【Linux】Debian 下安裝 Apache,MySQL,PHP


首先,對你的源進行更新:

 

[plain]  view plain  copy
 
 
 
  在CODE上查看代碼片派生到我的代碼片
  1. $ sudo apt-get update  

第一步--安裝 Apache

 

Apache 是一個開源軟件,它目前運行在全球超過 50% 的服務器上,是 LAMP(Linux,Apache,MySQL,PHP)組成部分之一。

安裝 Apache:

 

[plain]  view plain  copy
 
 
 
  在CODE上查看代碼片派生到我的代碼片
  1. $ sudo apt-get install apache2  

 

安裝完成后可以在瀏覽器地址欄輸入 http://localhost/,安裝成功會有一個 It works 頁面。

可以通過以下命令找到你的服務器的 IP 地址:

 

[plain]  view plain  copy
 
 
 
  在CODE上查看代碼片派生到我的代碼片
  1. $ sudo ifconfig eth0 | grep inet | awk '{ print $2 }'  

第二步--安裝 MySQL

(更好的參考:http://www.cnblogs.com/xusir/p/3334217.html

MySQL是用於組織和檢索數據的廣泛部署的數據庫管理系統。

 

安裝 MySQL:

 

[plain]  view plain  copy
 
 
 
  在CODE上查看代碼片派生到我的代碼片
  1. $ sudo apt-get mysql-server  

在安裝過程中,MySQL 要求你設置一個 root 密碼,不過你要是忘了設置,也可以在安裝之后通過 MySQL shell 設置。

 

安裝完成 MySQL 后你需要進行 MySQL 的初始設置,利用以下命令:

 

[plain]  view plain  copy
 
 
 
  在CODE上查看代碼片派生到我的代碼片
  1. # mysql_secure_installation  

這步會要求你的 root 密碼。

 

輸入之后會是這樣的:

 

[plain]  view plain  copy
 
 
 
  在CODE上查看代碼片派生到我的代碼片
  1. Enter current password for root (enter for none):   
  2. OK, successfully used password, moving on...  

之后會提示你是否想修改 root 密碼,輸入 N 不修改,Enter 進入下一步。

 

之后的步驟全部 Yes ,最后 MySQL 會重載使得設置完成,如下:

 

[plain]  view plain  copy
 
 
 
  在CODE上查看代碼片派生到我的代碼片
  1. By default, a MySQL installation has an anonymous user, allowing anyone  
  2. to log into MySQL without having to have a user account created for  
  3. them.  This is intended only for testing, and to make the installation  
  4. go a bit smoother.  You should remove them before moving into a  
  5. production environment.  
  6.   
  7. Remove anonymous users? [Y/n] y                                              
  8.  ... Success!  
  9.   
  10. Normally, root should only be allowed to connect from 'localhost'.  This  
  11. ensures that someone cannot guess at the root password from the network.  
  12.   
  13. Disallow root login remotely? [Y/n] y  
  14. ... Success!  
  15.   
  16. By default, MySQL comes with a database named 'test' that anyone can  
  17. access.  This is also intended only for testing, and should be removed  
  18. before moving into a production environment.  
  19.   
  20. Remove test database and access to it? [Y/n] y  
  21.  - Dropping test database...  
  22.  ... Success!  
  23.  - Removing privileges on test database...  
  24.  ... Success!  
  25.   
  26. Reloading the privilege tables will ensure that all changes made so far  
  27. will take effect immediately.  
  28.   
  29. Reload privilege tables now? [Y/n] y  
  30.  ... Success!  
  31.   
  32. Cleaning up...  

完成以上步驟后你就可以開始安裝 PHP。

 

第三步--安裝 PHP
PHP 是種開源的 Web 腳本語言,並被廣泛應用來制作動態網頁。

安裝 PHP (Debian 7 以下):

[plain]  view plain  copy
 
 
 
  在CODE上查看代碼片派生到我的代碼片
  1. # apt-get install php5 php-pear php5-suhosin php5-mysql  

安裝 PHP (Debian 7 ):

 

 

[plain]  view plain  copy
 
 
 
  在CODE上查看代碼片派生到我的代碼片
  1. # apt-get install php5 php-pear php5-mysql  

接下來將會有兩次詢問,全部 yes 即可。

 

完成 PHP 安裝后,重載 Apache:

 

[plain]  view plain  copy
 
 
 
  在CODE上查看代碼片派生到我的代碼片
  1. # service apache2 restart  

恭喜!你已經成功安裝 LAMP!
第四步--在你的服務器上查看 PHP 版本等信息

 

雖然我們已經安裝了 LAMP ,但我們還是需要更直觀一點查看安裝成功的 LAMP。

首先創建一個文件:

 

[plain]  view plain  copy
 
 
 
  在CODE上查看代碼片派生到我的代碼片
  1. # nano /var/www/info.php  

在新文件寫下:

[plain]  view plain  copy
 
 
 
  在CODE上查看代碼片派生到我的代碼片
  1. <?php  
  2. phpinfo();  
  3. ?>  

之后保存退出。

 

現在你可以在瀏覽器中輸入 http://localhost/info.php 查看 PHP 版本等信息,頁面如下面這樣:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM