Chinaunix首页 | 论坛 | 博客
  • 博客访问: 595150
  • 博文数量: 70
  • 博客积分: 3219
  • 博客等级: 中校
  • 技术积分: 1197
  • 用 户 组: 普通用户
  • 注册时间: 2006-02-13 12:20
个人简介

谢谢您的对我的博客的关心,同时希望这个站点真的能够对您有所帮助。 如果可以请告诉我你的联系方式(可能的话告诉我两个或更多,我不希望失去任何一个关注本主页人士的联系,不论你是我的老友,或是一位新朋友,对于我来说您十分重要)

文章分类
文章存档

2021年(1)

2020年(13)

2018年(1)

2013年(12)

2012年(2)

2009年(2)

2008年(6)

2007年(20)

2006年(13)

分类: PHP

2020-06-07 13:51:32

本文使用CentOS 7.5作为测试平台,最小化安装,禁用selinux

解析:
1、安装php-7.2.31
2、安装nginx-1.18.0
3、配置nginx支持php

1、安装php
安装依赖包:

yum install gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel readline readline-devel libxslt libxslt-devel

添加php用户:
groupadd www
useradd -M -g www -s /sbin/nologin www

下载、解压、安装:

wget -c
tar -jxf php-7.2.31.tar.bz2
cd php-7.2.31/
./configure --prefix=/usr/local/php --disable-fileinfo --enable-fpm --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-openssl --with-zlib --with-curl --enable-ftp --with-gd --with-xmlrpc --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-mbstring --enable-zip --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mysql-sock=/var/lib/mysql/mysql.sock --without-pear --enable-bcmath
make
make install

复制,编辑配置文件:
cp php.ini-development /etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/ /usr/local/php/etc/php-fpm.d/
sed -i '/^user/s/=.*/= www/' /usr/local/php/etc/php-fpm.d/
sed -i '/^group/s/=.*/= www/' /usr/local/php/etc/php-fpm.d/

配置服务:
echo '[Unit]
Description=php-fpm
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/php/sbin/php-fpm
PrivateTmp=True

[Install]
WantedBy=multi-user.target' > /etc/systemd/system/php-fpm.service

启用、并启动服务:
systemctl enable php-fpm.service
systemctl start php-fpm.service

测试php-fpm服务:
ps -aux | grep php-fpm
netstat -tnl | grep 9000

2、安装nginx
添加用户:

groupadd nginx
useradd -M -g nginx -s /sbin/nologin nginx

下载、解压、安装:
wget -c

tar -zxf nginx-1.18.0.tar.gz
cd nginx-1.18.0
./configure --prefix=/usr/local/nginx
make && make install

配置服务:
echo '[Unit]
Description=nginx - high performance web server
Documentation=
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
WorkingDirectory=/usr/local/nginx
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target' > /usr/lib/systemd/system/nginx.service

启用、并启动服务:
systemctl enable nginx.service
systemctl start nginx.service

打开防火墙端口:
firewall-cmd --add-port=80/tcp
firewall-cmd --add-port=80/tcp --permanent

测试nginx:
ps -aux | grep nginx
netstat -tnl | grep 80
curl

3、配置nginx支持php
vi /usr/local/nginx/conf/nginx.conf

点击(此处)折叠或打开

  1. location / {
  2.             root html;
  3. # index index.html index.htm;
  4.             index index.php index.html index.htm;
  5.         }

  6. ..............................................................

  7.         location ~ \.php$ {
  8.             root html;
  9.             fastcgi_pass 127.0.0.1:9000;
  10.             fastcgi_index index.php;
  11. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  12.             fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
  13.             include fastcgi_params;
  14.         }

测试:
echo "
phpinfo();
?>" > /usr/local/nginx/html/index.php

systemctl restart nginx.service
curl

4、X3 网络相册 nginx配置(本段可忽略):
Nginx does NOT support .htaccess. Therefore, you need to configure X3 rewrite rules in your Nginx server config. I am not sure what rules you have there now, but I created an official X3 Nginx config example in the link below.

vi /usr/local/nginx/conf/nginx.conf


点击(此处)折叠或打开

  1. location / {
  2.             root html;
  3. # index index.html index.htm;
  4.             index index.php index.html index.htm;


  5.             # X3 rewrite rules
  6.             if (!-e $request_filename){
  7.               # Rewrite any calls to html|json|xml|atom|rss if a folder matching * exists
  8.               rewrite (.+)\.(html|json|xml|atom|rss)$ $1/ last;
  9.               # Rewrite any calls to /render to the X3 image resizer
  10.               rewrite ^/render/. /app/parsers/slir/ last;
  11.               # Rewrite routes to X3 application index.php if they are non-existent files/dirs
  12.             rewrite ^(.*)$ /index.php?$1 last;
  13.             }
  14.         }

使配置生效:
systemctl restart nginx.service

阅读(1165) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~