使NGINX支持PHP

首先配置PHP

安装PHP之后,执行以下操作:

cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf
cd php-fpm.d
cp www.conf.default www.conf
cp /root/php-7.4.6/php.ini-production /usr/local/php/lib/php.ini

开启OPcache vi /usr/local/php/lib/php.ini 添加 zend_extension=opcache.so

vi /usr/local/php/etc/php-fpm.d/www.conflisten = 127.0.0.1:9000 更改为 listen = /usr/local/php/php-fpm.sock 再把下面三行前面的分号 ; 去掉

;listen.owner = nobody
;listen.group = nobody
;listen.mode = 0660

启动PHP-FPM /usr/local/php/sbin/php-fpm

然后配置NGINX

安装NGINX之后,执行以下操作:

vi /usr/local/nginx/conf/nginx.conf 在server段内添加以下内容:

location ~ \.php$ {
            root           html;
            fastcgi_pass   unix:/usr/local/php/php-fpm.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  HTTPS            $https;
            include        fastcgi_params;
        }

启动NGINX /usr/local/nginx/sbin/nginx

设置PHP-FPM和NGINX开机自动启动 vi /etc/rc.d/rc.local 添加 /usr/local/php/sbin/php-fpm/usr/local/nginx/sbin/nginx 然后授权 chmod +x /etc/rc.d/rc.local

发表评论

电子邮件地址不会被公开。 必填项已用*标注