nginx与php7.2安装配置
环境为centos7.9
一、安装nginx1.2
1)安装依赖项:
yum install -y pcre pcre-devel openssl openssl-devel zlib zlib-devel
正常可以安装成功。
2)安装工具:
yum install -y gcc gcc-c++
创建用户nginx,以该用户的身份执行nginx
useradd -s /bin/false -M nginx
3)开始编译:
tar -xzvf nginx-1.20.2.tar.gz
cd nginx-1.20.2
./configure --user=nginx \
--group=nginx \
--prefix=/usr/local/nginx-1.12.0 \
--conf-path=/usr/local/etc/nginx-1.12.0/nginx.conf \
--with-http_v2_module \
--with-http_ssl_module \
--with-http_sub_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre
make -j8
make install
4)配置:
编写启动脚本
vim /usr/lib/systemd/system/nginx.service
内容如下:
[Unit]
Description=nginx
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx-1.12.0/logs/nginx.pid
ExecStartPost=/bin/sleep 0.1
ExecStartPre=/usr/local/nginx-1.12.0/sbin/nginx -t -c /usr/local/etc/nginx-1.12.0/nginx.conf
ExecStart=/usr/local/nginx-1.12.0/sbin/nginx -c /usr/local/etc/nginx-1.12.0/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
加入到启动项目:
systemctl enable nginx.service
service nginx start
修改 vim /usr/local/etc/nginx-1.12.0/nginx.conf 中 user 为 nginx
vim /usr/local/etc/nginx-1.12.0/nginx.conf
在第1行:
user nginx;
worker_processes 1;
启动服务试试
service nginx start
本机浏览器能看到:
service nginx start
这样就是OK了。
最后防火墙关闭或者开启80端口访问。
service firewalld stop
备注:CentOS7:
systemctl status firewalld.service 查看防火墙状态
systemctl stop firewalld.service 本次访问关闭防火墙
systemctl disable firewalld.service 从下次开始关闭防火墙
systemctl enable firewalld.service 打开防火墙
关于网络的配置最后用:systemctl restart network
CentOS6:
service iptables status 查看防火墙状态
service iptables start 临时开启防火墙
service iptables stop 临时关闭防火墙
chkconfig iptables --list 查看防火墙开机启动状态
chkconfig iptables on 开启防火墙开机启动
chkconfig iptables off 关闭防火墙开机启动
二、php7.2.0
正常情况下安装以后就可以,( --force --nodeps )
rpm -ivh libxml2-2.9.9-1.fc28.x86_64.rpm
rpm -ivh libxml2-devel-2.9.9-1.fc28.x86_64.rpm
但是有时还缺少依赖,所以最好不要强制安装,否则后面还是会报错
yum install xz-devel -y
yum install libxml2 -y
yum install libxml2-devel -y
与ubuntu不一样,
apt-get install libxml2
apt-get install libxml2-dev
#php配置命令是
./configure --prefix=/usr/local/php/php720 --enable-fpm
make -j8
make install
安装完成后,会在目录
/usr/local/php/php720
配置一下,包括3个文件,ini默认应在lib目录下,可以使用php --ini 查看位置,
另两个配置文件,去掉默认的后缀即可;
cp php.ini-production /usr/local/php/php720/lib/php.ini
cd /usr/local/php/php720/etc/
cp php-fpm.conf.default php-fpm.conf
cp php-fpm.d/www.conf.default php-fpm.d/www.conf
将PHP放置于环境变量
添加环境变量
vim /etc/profile
添加
export PATH=/usr/local/php/php720/bin:$PATH
source /etc/profile
echo $PATH
设置软连接(可选步骤)
cp /usr/local/php/php720/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
ln -s /usr/local/php/php720/bin/* /usr/local/bin
ln -s /usr/local/php/php720/sbin/* /usr/local/sbin
三、 配置nginx与php
1、编辑nginx.conf
vi /usr/local/nginx/conf/nginx.conf
如果是没有加前缀的编译
vi /usr/local/etc/nginx-1.12.0/nginx.conf
在http{}中加入
include /usr/local/etc/nginx-1.12.0/conf.d/*.conf;
2、添加新的php.conf文件
mkdir /usr/local/etc/nginx-1.12.0/conf.d
vi php.conf
内容如下:
3、编辑php.ini
vim /usr/local/php/php720/lib/php.ini
打开选项,默认被注释并且值为1
cgi.fix_pathinfo
4、编辑php-fpm.com
vim /usr/local/php/php720/etc/php-fpm.conf
插入
include=/usr/local/php/etc/php-fpm.d/*.conf
我发现这个已经有了,不用动
需要打开一些选项:
pid = run/php-fpm.pid
error_log = log/php-fpm.log
log_level = notice
pm.start_servers
pm.min_spare_servers
pm.max_spare_servers
5、设置fpm服务
从源码目录
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm
ubuntu版本
update-rc.d php-fpm defaults
centos版本
chkconfig --add php-fpm
然后测试指令
service php-fpm start
lsof -i:9000
service nginx restart
http://10.128.6.119/hi.php?