阿里云CentOS8安装nginx+php-fpm

附加知识

CentOS8已经开始使用dnf作为系统包的安装工具了,yum虽然可以用,但是已经不推荐了

安装nginx

阿里CentOS8安装的是nginx 1.14.1,感觉上还是想升级一下,参考CentOS 8升级nginx至最新版本(yum方式)

安装php-fpm

阿里CentOS8安装的是php7.2,可以用dnf升级一下,参考How To Install PHP 7.3 on CentOS 8

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
dnf module install php:remi-7.3

配置php-fpm服务

# vim /etc/php-fpm.d/www.conf
user = nginx		# 这个值原来是apache
group = nginx		# 这个值原来是apache

记得在编辑的时候记录一下listen的值,一会配置nginx的时候要用到

listen = /run/php-fpm/www.sock

启动php-fpm服务

# systemctl enable php-fpm
# systemctl start php-fpm

配置nginx

# vim /etc/nginx/conf.d/default.conf
server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /var/www/html;
        index  index.html index.htm;
        if (!-e $request_filename) {
            rewrite  ^(.*)$  /index.php?s=/$1  last;
            break;
        }
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    location ~ \.php$ {
        root           /var/www/html;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php-fpm/www.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

启动服务

systemctl enable nginx
systemctl start nginx

做个测试程序试一下

# vim /var/www/html/Info.php
curl http://localhost/info.php

如果你本机成功看到内容,可以远程看一下了

你可能感兴趣的:(Linux)