在本教程中,我們將向您展示如何在 Manjaro 20 上安裝 LAMP。對於那些不知道的人,燈指 Linux、Apache、MySQL/MariaDB 和 PHP 或 Perl 或 Python。 所有組件都是免費和開源軟件,組合適用於創建動態網頁。 LAMP 堆棧是世界上最流行的服務器設置之一。
本文假設您至少對 Linux 有基本的了解,您知道如何使用 shell,最重要的是,您在自己的 VPS 上託管您的站點。 安裝非常簡單,它假定您在 root 帳戶下運行,如果不是,您可能需要添加 'sudo
' 獲取 root 權限的命令。 我將向您展示在 Manjaro 20 上逐步安裝 LAMP Stack(尼比亞).
以前的要求
- 運行以下操作系統之一的服務器或台式機:Manjaro 或 Arch Linux。
- 建議您使用全新的操作系統安裝以避免潛在問題。
- 和
non-root sudo user
或訪問root user
. 我們建議充當non-root sudo user
但是,如果您在以 root 身份運行時不小心,可能會損壞您的系統。
在 Manjaro 20 Nibia 上安裝 LAMP
步驟 1. 在運行下面的教程之前,請確保我們的系統是最新的:
sudo pacman -Syu
步驟 2. 安裝 Apache。
我們使用以下命令安裝 Apache Web 服務器:
sudo pacman -S apache
安裝完成後,打開Apache中存在的配置文件/etc/httpd/conf/httpd.conf
找到並評論以下行:
# LoadModule unique_id_module módulos/mod_unique_id.so
現在我們可以使用以下命令啟用並啟動 apache 服務器:
sudo systemctl enable httpd sudo systemctl restart httpd
步驟 3. 安裝 MySQL。
運行以下命令在 Manjaro 上安裝 MySQL 服務器:
sudo pacman -S mysql
完成後,首先使用以下命令初始化 MySQL 數據目錄:
sudo mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
然後使用以下命令啟用並啟動它:
sudo systemctl enable mysqld sudo systemctl restart mysqld
默認情況下,MySQL 未加固。 您可以使用以下方法保護 MySQLmysql_secure_installation
文本。 您應該仔細閱讀下面的每個步驟,這將設置 root 密碼、刪除匿名用戶、禁止遠程 root 登錄以及刪除測試數據庫和訪問安全 MySQL:
$ sudo mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and haven't set the root password yet, you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password or using the unix_socket ensures that nobody can log into the MariaDB root user without the proper authorisation. You already have your root account protected, so you can safely answer 'n'. Switch to unix_socket authentication [Y/n] Y Enabled successfully! Reloading privilege tables.. ... Success! You already have your root account protected, so you can safely answer 'n'. Change the root password? [Y/n] n ... skipping. By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB 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, MariaDB 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... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
步驟 4. PHP 安裝。
要在 Manjaro 中安裝 PHP 和 PHP Apache 模塊,只需使用pacman
命令:
sudo pacman -S php php-apache
安裝完成後,我們需要配置PHP。 編輯文件:/etc/httpd/conf/httpd.conf:
sudo nano /etc/httpd/conf/httpd.conf
找到以下行並將其註釋掉:
#LoadModule mpm_event_module modules/mod_mpm_event.so
另外,取消註釋或添加行:
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
然後將以下行添加到配置文件的末尾:
LoadModule php7_module modules/libphp7.so AddHandler php7-script php Include conf/extra/php7_module.conf
現在保存文件並退出。 重新啟動 apache 服務器以確保正確加載所有配置:
sudo systemctl restart httpd
要測試 PHP 安裝,請在/srv/http/phpinfo.php
並編寫以下 PHP 代碼:
<?php phpinfo(); ?>
現在通過訪問在瀏覽器中打開這個文件localhost/phptest.php
並檢查您的 Manjaro Linux 上是否安裝了帶有最新版本 PHP 的 Apache 服務器。
恭喜! 您已成功安裝 LAMP 服務器。 感謝您使用本教程安裝 LAMP(Apache,MariaDB是PHP) on Manjaro 20 systems. 如需更多幫助或有用信息,我們建議您參考官方 ApacheMariaDB 網站和 PHP 網站。