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 的测试页面, 那便表示安装成功了。