序:
一般情况下,php-fpm端口为9000,然有些情况不想使用端口,就可使用sock的方式连接,做此随笔。
一、源码安装nginx1.17
使用下面脚本即可
#!/bin/bash
#Centos7源码安装nginx-1.17.0
#2020年5月28日 20:04:24
#author Toyix
############################
repobase="/etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo"
repoepel="/etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo"
soft1="vim wget lrzsz"
soft2="pcre-devel pcre gcc gcc-c++ openssl openssl-devel zlib-devel"
nginxversion="nginx-1.17.0"
nginxsoft="http://nginx.org/download/${nginxversion}.tar.gz"
nginxdir="/usr/local/docker/nginx"
mkdir -p /usr/local/docker/nginx
configuremoudule="--user=otoyix \
--group=otoyix \
--prefix=${nginxdir} \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_mp4_module \
--with-http_realip_module \
--with-pcre \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-stream"
netstat_nginx="netstat -tnlp |grep nginx"
selinuxconfigfile="/etc/selinux/config"
selinux_enforcing="SELINUX=enforcing"
selinux_disabled="SELINUX=disabled"
firewalld_open80="--zone=public --add-port=80/tcp --permanent"
firewalld_ports="--zone=public --list-ports"
yum install $soft1 -y
echo "安装国内base及epel源"
seleep 5
curl -o $repobase
wget -O $repoepel
yum clean all
yum makecache
echo "创建nginx用户nginx"
#useradd -s /sbin/nologin -r nginx
echo "安装环境支持"
yum install $soft2 -y
echo "下载nginx"
cd /usr/src/
wget $nginxsoft
tar -xf ${nginxversion}.tar.gz
cd ${nginxversion}
echo "预编译"
./configure ${configuremoudule}
echo "编译"
make
echo "安装"
make install
${nginxdir}/sbin/nginx
sed -i "s/${selinux_enforcing}/${selinux_disabled}/g" ${selinuxconfigfile}
setenforce 0
firewall-cmd ${firewalld_open80}
firewall-cmd --reload
firewall-cmd $firewalld_ports
ps -ef|grep nginx
echo "------------------end"
执行结果见下:
test -d '/usr/local/docker/nginx/html' \
|| cp -R html '/usr/local/docker/nginx'
test -d '/usr/local/docker/nginx/logs' \
|| mkdir -p '/usr/local/docker/nginx/logs'
make[1]: Leaving directory `/usr/src/nginx-1.17.0'
setenforce: SELinux is disabled
success
success
8080/tcp 82/tcp 80/tcp
root 1972 1879 0 16:23 pts/0 00:00:00 sh installnginx.sh
root 4941 1 0 16:27 ? 00:00:00 nginx: master process /usr/local/docker/nginx/sbin/nginx
otoyix 4942 4941 0 16:27 ? 00:00:00 nginx: worker process
root 4973 1972 0 16:27 pts/0 00:00:00 grep nginx
二、源码安装php7
使用脚本,见下:
#!/bin/bash
#auto Source Code install PHP
#by author toyix
#2021年1月2日 14:08:02
echo "安装vim wget lrzsz"
yum install -y wget lrzsz vim
echo "安装阿里base及epel源"
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
echo "清缓存"
yum clean all
yum makecache
echo "安装软件环境支持"
yum install wget make gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel kernel keyutils patch perl -y
yum install -y libjpeg libpng-devel freetype freetype-devel libxslt libxslt-devel libXpm-devel sqlite-devel bzip2 bzip2-devel libjpeg libjpeg-devel libpng libpng-devel oniguruma oniguruma-devel libcurl libcurl-devel postgresql-devel openssl openssl-devel libzip libxml2 libxml2-devel pcre2 pcre-devel pcre gcc gcc-c++
echo "软件下载"
cd /usr/src
wget -c https://www.php.net/distributions/php-7.1.27.tar.gz
echo "创建nginx用户"
useradd -s /sbin/nologin -r nginx -M
echo "解压、编译、安装"
tar -zxvf php-7.1.27.tar.gz
cd php-7.1.27
./configure \
--prefix=/usr/local/php7 \
--enable-fpm \
--with-fpm-user=otoyix \
--with-fpm-group=otoyix \
--enable-debug \
--with-gd \
--enable-ldap \
--with-jpeg-dir=/usr/lib64 \
--with-pgsql \
--enable-inline-optimization \
--with-bz2 \
--with-zlib-dir \
--with-freetype-dir=/usr/include/freetype2/freetype \
--enable-mbstring \
--enable-soap \
--with-openssl \
--enable-calendar \
--with-curl \
--enable-ftp \
--with-gettext \
--with-xmlrpc \
--with-xsl \
--enable-opcache \
--with-iconv \
--with-pdo-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-kerberos \
--with-pdo-sqlite \
--with-pear \
--enable-shmop \
--enable-xml \
--with-zlib \
--enable-sockets \
--enable-sysvsem \
--enable-pcntl \
--enable-mbregex \
--enable-exif \
--enable-bcmath \
--with-mhash \
--with-zlib-dir \
--with-pcre-jit \
--with-config-file-path=/usr/local/php7/etc
make -j4 && make install -j4
echo "主配置文件"
cp php.ini-development /usr/local/php7/etc/php.ini
echo "次配置文件"
cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
echo "修改Php-fpm配置文件中的include默认文件名"
cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/default.conf
echo "配置启动文件php-fpm及软链接"
cp /usr/src/php-7.1.27/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
ln -s /etc/init.d/php-fpm /usr/sbin/php-fpm
echo "启动php-fpm"
php-fpm start
ps -ef|grep php-fpm
netstat -tnlp
echo "添加phpredis"
cd /usr/src
wget -c https://github.com/phpredis/phpredis/archive/4.3.0.tar.gz
tar zxf 4.3.0.tar.gz
cd phpredis-4.3.0/
/usr/local/php7/bin/phpize
./configure --with-php-config=/usr/local/php7/bin/php-config
make
make install
cd /usr/local/php7/
REDISPHP_DIR=`find . -name debug-non-zts*|awk -F'/' '{print $NF}'`
sed -i '$a extension_dir = /usr/local/php7/lib/php/extensions/'${REDISPHP_DIR}'' /usr/local/php7/etc/php.ini
sed -i '$a extension="redis.so"' /usr/local/php7/etc/php.ini
ps -ef|grep php-fpm
php-fpm stop
php-fpm start
ps -ef|grep php-fpm
/usr/local/php7/bin/php -m|grep redis
sh -x 执行结果:
+ cd /usr/local/php7/
++ find . -name 'debug-non-zts*'
++ awk -F/ '{print $NF}'
+ REDISPHP_DIR=debug-non-zts-20160303
+ sed -i '$a extension_dir = /usr/local/php7/lib/php/extensions/debug-non-zts-20160303' /usr/local/php7/etc/php.ini
+ sed -i '$a extension="redis.so"' /usr/local/php7/etc/php.ini
+ grep php-fpm
+ ps -ef
root 14948 1 0 18:28 ? 00:00:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
otoyix 14949 14948 0 18:28 ? 00:00:00 php-fpm: pool www
otoyix 14950 14948 0 18:28 ? 00:00:00 php-fpm: pool www
root 17566 9770 0 18:28 pts/1 00:00:00 grep php-fpm
+ php-fpm stop
Gracefully shutting down php-fpm . done
+ php-fpm start
Starting php-fpm done
+ grep php-fpm
+ ps -ef
root 17573 1 0 18:28 ? 00:00:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
otoyix 17574 17573 0 18:28 ? 00:00:00 php-fpm: pool www
otoyix 17575 17573 0 18:28 ? 00:00:00 php-fpm: pool www
root 17577 9770 0 18:28 pts/1 00:00:00 grep php-fpm
+ /usr/local/php7/bin/php -m
+ grep redis
redis
查看模块是否加载
vim /usr/local/php7/etc/php.ini
extension_dir = /usr/local/php7/lib/php/extensions/debug-non-zts-20160303
extension="redis.so"
三、配置
1、创建sock文件
touch /dev/shm/php7120-fpm0.socket
2、更改php-fpm配置文件, 将listen指令的值改为socket文件路径,,并改启动权限
vim /usr/local/php7/etc/php-fpm.d/default.conf
listen = /dev/shm/php7120-fpm0.socket
改权限
listen.owner = otoyix
listen.group = otoyix
listen.mode = 0660
3、改nginx配置
vim /usr/local/docker/nginx/conf/nginx.conf
location ~ \.php$ {
#ifastcgi_pass 192.168.1.24:9000;
fastcgi_pass unix:/dev/shm/php7120-fpm0.socket;
root /usr/local/docker/nginx/html;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
vim /usr/local/docker/nginx/html/index.php
<?php
phpinfo();
?>
重启动nginx,php-fpm,浏览器测试即可
/usr/local/docker/nginx/sbin/nginx -s reload
php-fpm restart
----------------------------end