LEMP 意思是 Linux + Nginx, + MySQL (MariaDB) + PHP。Nginx (發音能同 engine x) 是一款以性能取向的網頁伺服器, 較 Apache 及 Lighttpd 使用較少記憶體, 而配置 Nginx 及 PHP 的方法與 Apache 有點不同, 因為 Nginx 是透過 php-fpm (FastCGI Process Manager) 運作的, 以下會示範在 Fedora 22 用 DNF 安裝 Nginx, MariaDB 及 PHP.
安裝 Nginx
Fedora 安裝 Nginx 最簡單的方法是用 DNF 安裝, 輸入以下指令安裝:
安裝好 Nginx 網頁伺服器後, 便可以用 systemctl 啟動/停止/重新啟動 Nginx, 現在啟動 Nginx 及設定開機自動啟動:
# systemctl enable nginx
啟動後, 便可以用瀏覽器檢查 Nginx 是否可以連接, 例如:
http://server-ip/
如果沒有問題, 可以看到 “Welcome to nginx on Fedora!” 頁面。
nginx 的預設目錄在 /usr/share/nginx/html, 網頁放在這裡便可以。
安裝 MariaDB
執行以下指令安裝 MariaDB:
啟動及設定開機自動執行 MariaDB:
# systemctl enable mariadb
執行以下指令設定 MariaDB 的 root 密碼, 預設是空密碼, 所以建議盡快修改:
完成後可以用測試一下 MariaDB 是否已經啟動:
安裝 PHP
安裝好 PHP 後, 開啟 /etc/php-fpm.d/www.conf, 找到以下幾行:
|
1 2 3 4 |
; RPM: apache Choosed to be able to access some dir as httpd user = apache ; RPM: Keep a group allowed to write in log dir. group = apache |
改成:
|
1 2 3 4 |
; RPM: apache Choosed to be able to access some dir as httpd user = nginx ; RPM: Keep a group allowed to write in log dir. group = nginx |
儲存檔案後, 用以下指令啟動 php-fpm 及重新啟動 nginx:
# systemctl enable php-fpm
# systemctl restart nginx
設定完成後, 可以放一個簡單的 PHP 程式到 nginx 的根目錄 (/usr/share/nginx/html), 例如:
|
1 2 3 |
<?php phpinfo(); ?> |
如果用瀏覽器看到 PHP 的測試頁面, 那便表示安裝成功了。