首先,對你的源進行更新:
- $ sudo apt-get update
第一步--安裝 Apache
Apache 是一個開源軟件,它目前運行在全球超過 50% 的服務器上,是 LAMP(Linux,Apache,MySQL,PHP)組成部分之一。
安裝 Apache:
- $ sudo apt-get install apache2
安裝完成后可以在瀏覽器地址欄輸入 http://localhost/,安裝成功會有一個 It works 頁面。
可以通過以下命令找到你的服務器的 IP 地址:
- $ sudo ifconfig eth0 | grep inet | awk '{ print $2 }'
第二步--安裝 MySQL
(更好的參考:http://www.cnblogs.com/xusir/p/3334217.html)
MySQL是用於組織和檢索數據的廣泛部署的數據庫管理系統。
安裝 MySQL:
- $ sudo apt-get mysql-server
在安裝過程中,MySQL 要求你設置一個 root 密碼,不過你要是忘了設置,也可以在安裝之后通過 MySQL shell 設置。
安裝完成 MySQL 后你需要進行 MySQL 的初始設置,利用以下命令:
- # mysql_secure_installation
這步會要求你的 root 密碼。
輸入之后會是這樣的:
- Enter current password for root (enter for none):
- OK, successfully used password, moving on...
之后會提示你是否想修改 root 密碼,輸入 N 不修改,Enter 進入下一步。
之后的步驟全部 Yes ,最后 MySQL 會重載使得設置完成,如下:
- By default, a MySQL installation has an anonymous user, allowing anyone
- to log into MySQL without having to have a user account created for
- them. This is intended only for testing, and to make the installation
- go a bit smoother. You should remove them before moving into a
- production environment.
- Remove anonymous users? [Y/n] y
- ... Success!
- Normally, root should only be allowed to connect from 'localhost'. This
- ensures that someone cannot guess at the root password from the network.
- Disallow root login remotely? [Y/n] y
- ... Success!
- By default, MySQL comes with a database named 'test' that anyone can
- access. This is also intended only for testing, and should be removed
- before moving into a production environment.
- Remove test database and access to it? [Y/n] y
- - Dropping test database...
- ... Success!
- - Removing privileges on test database...
- ... Success!
- Reloading the privilege tables will ensure that all changes made so far
- will take effect immediately.
- Reload privilege tables now? [Y/n] y
- ... Success!
- Cleaning up...
完成以上步驟后你就可以開始安裝 PHP。
第三步--安裝 PHP
PHP 是種開源的 Web 腳本語言,並被廣泛應用來制作動態網頁。
安裝 PHP (Debian 7 以下):
- # apt-get install php5 php-pear php5-suhosin php5-mysql
安裝 PHP (Debian 7 ):
- # apt-get install php5 php-pear php5-mysql
接下來將會有兩次詢問,全部 yes 即可。
完成 PHP 安裝后,重載 Apache:
- # service apache2 restart
恭喜!你已經成功安裝 LAMP!
第四步--在你的服務器上查看 PHP 版本等信息
雖然我們已經安裝了 LAMP ,但我們還是需要更直觀一點查看安裝成功的 LAMP。
首先創建一個文件:
- # nano /var/www/info.php
在新文件寫下:
- <?php
- phpinfo();
- ?>
之后保存退出。
現在你可以在瀏覽器中輸入 http://localhost/info.php 查看 PHP 版本等信息,頁面如下面這樣: