1. 程式人生 > >【Linux】Debian 下安裝 Apache,MySQL,PHP

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

本文來自 DigitalOcean,我是翻譯過來的,親測安裝成功。

安裝環境:Debian7 64位

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

  1. $ sudo apt-get update  
第一步--安裝 Apache

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

安裝 Apache:

  1. $ sudo apt-get install apache2  

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

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

  1. $ sudo ifconfig eth0 | grep inet | awk '{ print $2 }'  

第二步--安裝 MySQL

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

安裝 MySQL:

  1. $ sudo apt-get mysql-server  
在安裝過程中,MySQL 要求你設定一個 root 密碼,不過你要是忘了設定,也可以在安裝之後通過 MySQL shell 設定。

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

  1. # mysql_secure_installation  
這步會要求你的 root 密碼。

輸入之後會是這樣的:

  1. Enter current password for root (enter for none):   
  2. OK, successfully used password, moving on...  
之後會提示你是否想修改 root 密碼,輸入 N 不修改,Enter 進入下一步。

之後的步驟全部 Yes ,最後 MySQL 會過載使得設定完成,如下:

  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. Remove anonymous users? [Y/n] y                                              
  7.  ... Success!  
  8. Normally, root should only be allowed to connect from 'localhost'.  This  
  9. ensures that someone cannot guess at the root password from the network.  
  10. Disallow root login remotely? [Y/n] y  
  11. ... Success!  
  12. By default, MySQL comes with a database named 'test' that anyone can  
  13. access.  This is also intended only for testing, and should be removed  
  14. before moving into a production environment.  
  15. Remove test database and access to it? [Y/n] y  
  16.  - Dropping test database...  
  17.  ... Success!  
  18.  - Removing privileges on test database...  
  19.  ... Success!  
  20. Reloading the privilege tables will ensure that all changes made so far  
  21. will take effect immediately.  
  22. Reload privilege tables now? [Y/n] y  
  23.  ... Success!  
  24. Cleaning up...  
完成以上步驟後你就可以開始安裝 PHP。

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

安裝 PHP (Debian 7 以下):

  1. # apt-get install php5 php-pear php5-suhosin php5-mysql  
安裝 PHP (Debian 7 ):
  1. # apt-get install php5 php-pear php5-mysql  
接下來將會有兩次詢問,全部 yes 即可。

完成 PHP 安裝後,過載 Apache:

  1. # service apache2 restart  
恭喜!你已經成功安裝 LAMP!
第四步--在你的伺服器上檢視 PHP 版本等資訊

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

首先建立一個檔案:

  1. # nano /var/www/info.php  
在新檔案寫下:
  1. <?php  
  2. phpinfo();  
  3. ?>  
之後儲存退出。

現在你可以在瀏覽器中輸入 http://localhost/info.php 檢視 PHP 版本等資訊,頁面如下面這樣: