在OpenSUSE中安裝LAMP——Apache、PHP、MariaDB和PhpMyAdmin
介紹
LAMP架構,代表Linux、Apache、MySQL/MariaDB和PHP,是一個強大的開源軟體組合,廣泛用於Web開發和託管。本教程將指導您在流行的Linux發行版openSUSE上安裝和配置LAMP架構。我們將介紹Apache、PHP、MariaDB和PhpMyAdmin的安裝過程,提供詳細的示例和命令輸出,以確保安裝過程順利進行。
步驟1:更新系統軟體包
在開始之前,務必更新系統軟體包,以確保我們擁有最新的軟體版本和安全補丁。開啟終端並執行以下命令:
sudo zypper refresh sudo zypper update
步驟2:安裝Apache
Apache是一個廣泛使用的Web伺服器,是LAMP架構的基石。要安裝Apache,請執行以下命令:
示例
sudo zypper install apache2
輸出
Loading repository data... Reading installed packages... Resolving package dependencies... The following NEW package is going to be installed: apache2 1 new package to install. Overall download size: XXX MiB. Already cached: 0 B. After the operation, additional XXX MiB will be used. Continue? [y/n/...? shows all options] (y): Retrieving package apache2-2.x.x-x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x
安裝完成後,使用以下命令啟動並啟用Apache服務:
sudo systemctl start apache2 sudo systemctl enable apache2
輸出
$ sudo systemctl start apache2 [sudo] password for user: Starting apache2.service... $ sudo systemctl enable apache2 Created symlink /etc/systemd/system/multi-user.target.wants/apache2.service → /usr/lib/systemd/system/apache2.service.
步驟3:安裝PHP
PHP是一種流行的用於Web開發的指令碼語言。要安裝PHP及其必要的依賴項,請執行以下命令:
示例
sudo zypper install php7 php7-mysql apache2-mod_php7
輸出
$ sudo zypper install php7 php7-mysql apache2-mod_php7 Loading repository data... Reading installed packages... Resolving package dependencies... The following 3 NEW packages are going to be installed: apache2-mod_php7 php7 php7-mysql 3 new packages to install. Overall download size: XXX MiB. Already cached: XXX MiB. After the operation, additional XXX MiB will be used. Continue? [y/n/...? shows all options] (y): Retrieving package apache2-mod_php7-XXX... Retrieving package php7-XXX... Retrieving package php7-mysql-XXX... Installing package apache2-mod_php7-XXX... Installing package php7-XXX... Installing package php7-mysql-XXX... Checking for file conflicts: [done] (1/3) Installing: apache2-mod_php7-XXX..................................................................[done] (2/3) Installing: php7-XXX....................................................................................[done] (3/3) Installing: php7-mysql-XXX..............................................................................[done] Additional rpm output: ... ... ... Installation of packages was successful.
步驟4:安裝MariaDB
MariaDB是MySQL的替代品,提供了一個強大而健壯的關係資料庫管理系統。使用以下命令安裝MariaDB:
示例
sudo zypper install mariadb mariadb-client
輸出
Loading repository data... Reading installed packages... Resolving package dependencies... The following 2 NEW packages are going to be installed: mariadb mariadb-client 2 new packages to install. Overall download size: 150.1 MiB. Already cached: 0 B. After the operation, additional 672.9 MiB will be used. Continue? [y/n/v/...? shows all options] (y): y ... Retrieving package mariadb-10.6.5-2.1.x86_64 (1/2), 140.6 MiB (373.7 MiB unpacked) Retrieving: mariadb-10.6.5-2.1.x86_64.rpm ..........................................................................................................................[done] Retrieving package mariadb-client-10.6.5-2.1.x86_64 (2/2), 9.5 MiB (299.3 MiB unpacked) Retrieving: mariadb-client-10.6.5-2.1.x86_64.rpm ...................................................................................................................[done] ... Checking for file conflicts: .................................................................................................................................[done] (1/2) Installing: mariadb-10.6.5-2.1.x86_64 ..............................................................................................................................[done] (2/2) Installing: mariadb-client-10.6.5-2.1.x86_64 ...................................................................................................................[done] ... Executing post-install scripts.....................................................................................................................................[done] Additional rpm output: Installing MySQL system tables... OK Filling help tables... OK ...
執行以下命令啟動並啟用MariaDB服務:
示例
sudo systemctl start mariadb sudo systemctl enable mariadb
輸出
$ sudo systemctl start mariadb [sudo] password for user: $ sudo systemctl enable mariadb Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
要保護您的MariaDB安裝,請執行安全指令碼並按照提示操作:
示例
sudo mysql_secure_installation
輸出
$ sudo mysql_secure_installation Securing the MySQL server deployment. Connecting to MySQL using a Unix socket. MySQL server found running with a Unix socket at /var/run/mysqld/mysqld.sock. Continue with the MySQL secure installation? [Y/n] Y Please enter the MySQL root password: Validating password... The existing password for the user account root has expired. Please set a new password. New password: Re-enter new password: Estimated strength of the password: 100 Do you wish to continue with the password provided? [Y/n] Y Remove anonymous users? [Y/n] Y Disallow root login remotely? [Y/n] Y Remove test database and access to it? [Y/n] Y Reload privilege tables now? [Y/n] Y All done! MySQL should now be secured.
步驟5:安裝PhpMyAdmin
PhpMyAdmin是一個基於Web的介面,用於管理MySQL/MariaDB資料庫。執行以下命令安裝PhpMyAdmin:
sudo zypper install phpMyAdmin
在安裝過程中,系統會提示您選擇Web伺服器。選擇“apache2”並按Enter鍵。然後,選擇“yes”為phpMyAdmin配置資料庫。
步驟6:為PhpMyAdmin配置Apache
要配置Apache以識別PhpMyAdmin,請在文字編輯器中開啟配置檔案:
sudo nano /etc/apache2/conf.d/phpMyAdmin.conf
將`Require ip 127.0.0.1`一行替換為`Require all granted`。儲存並關閉檔案。
步驟7:重啟Apache
重啟Apache服務以使更改生效:
sudo systemctl restart apache2
步驟8:訪問PhpMyAdmin
開啟Web瀏覽器並輸入以下URL:https:///phpMyAdmin。您應該看到PhpMyAdmin登入頁面。使用您的MariaDB root使用者名稱和密碼登入。
恭喜!您已成功在openSUSE上安裝LAMP——Apache、PHP、MariaDB和PhpMyAdmin。您現在可以開始開發和託管Web應用程式了。
結論
在openSUSE上設定LAMP架構是一個簡單的過程,可以讓您利用開源軟體的強大功能進行Web開發。透過遵循本文中概述的步驟,您已經獲得了構建和部署Web應用程式的堅實基礎。享受LAMP架構提供的無限可能性!