Contents
  1. 1. 安装软件包
  2. 2. 配置php-fpm
  3. 3. 配置nginx
    1. 3.1. 创建配置目录
    2. 3.2. 修改nginx.conf
  4. 4. 设置开机自动启动服务

安装软件包

1
pacman -S nginx mariadb php php-fpm php-pear

配置php-fpm

编辑 /etc/php/php-fpm.conf

  • 启用error_log:把 ;error_log = log/php-fpm.log改成error_log = log/php-fpm.log
  • 把user, group 参数改成与nginx的一致,以避免权限问题,例如:
    user = joelhy
    group = joelhy
  • 改成在9000端口监听:
    listen = 127.0.0.1:9000
    ;listen = /run/php-fpm/php-fpm.sock

配置nginx

创建配置目录

1
2
cd /etc/nginx
mkdir conf.d sites-available sites-enabled

修改nginx.conf

假定nginx以普通帐号joelhy运行
#user html;改成user joelhy joelhy;
#error_log logs/error.log info;改成error_log /var/log/nginx/error.log info;
在 http{…}块最后添加:

1
2
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;

在sites-available目录创建虚拟主机配置文件,如需启用虚拟主机,则把sites-available中的链接到sites-enabled。
例如在sites-available目录里创建文件demo.conf,内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
server {
listen 8001;
root /home/joelhy/workspace/demo;
index index.html index.html;
server_name demo.dev;
#location / {
#try_files $uri $uri/ /index.php;
#}
location ~\.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

配置修改好后,使用nginx -t测试配置是否正常

设置开机自动启动服务

1
2
3
4
5
6
systemctl enable nginx
systemctl enable mysqld
systemctl enable php-fpm
systemctl start nginx
systemctl start mysqld
systemctl start php-fpm
Contents
  1. 1. 安装软件包
  2. 2. 配置php-fpm
  3. 3. 配置nginx
    1. 3.1. 创建配置目录
    2. 3.2. 修改nginx.conf
  4. 4. 设置开机自动启动服务