【Linux】Debian 下安裝 Apache,MySQL,PHP
阿新 • • 發佈:2019-02-14
本文來自 DigitalOcean,我是翻譯過來的,親測安裝成功。
安裝環境:Debian7 64位
首先,對你的源進行更新:
- $ sudo apt-get update
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
MySQL是用於組織和檢索資料的廣泛部署的資料庫管理系統。安裝 MySQL:
- $ sudo apt-get mysql-server
安裝完成 MySQL 後你需要進行 MySQL 的初始設定,利用以下命令:
- # mysql_secure_installation
輸入之後會是這樣的:
- Enter current password for root (enter for none):
- OK, successfully used password, moving on...
之後的步驟全部 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 是種開源的 Web 指令碼語言,並被廣泛應用來製作動態網頁。
安裝 PHP (Debian 7 以下):
- # apt-get install php5 php-pear php5-suhosin php5-mysql
- # apt-get install php5 php-pear php5-mysql
完成 PHP 安裝後,過載 Apache:
- # service apache2 restart
第四步--在你的伺服器上檢視 PHP 版本等資訊
雖然我們已經安裝了 LAMP ,但我們還是需要更直觀一點檢視安裝成功的 LAMP。
首先建立一個檔案:
- # nano /var/www/info.php
- <?php
- phpinfo();
- ?>
現在你可以在瀏覽器中輸入 http://localhost/info.php 檢視 PHP 版本等資訊,頁面如下面這樣: