1. 获取软件包
wget http://nginx.org/download/nginx-1.14.2.tar.gzwget https://www.php.net/distributions/php-7.3.4.tar.gz
2. 安装nginx
添加用户
useradd -s /sbin/nologin -M nginx
yum安装nginx所需的扩展
yum install openssl openssl-devel pcre pcre-devel
tar -zxvf nginx-1.14.2.tar.gz
cd nginx-1.14.2
./configure --user=nginx \
--group=nginx \
--prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-ipv6
make
make install
3. 安装PHP7
添加用户组和用户
groupadd www
useradd -s /sbin/nologin -g www www
安装所需依赖
yum -y install gcc gcc-c++ make automake autoconf
yum -y install libxml2-devel openssl-devel pcre-devel sqlite-devel libzip libzip-devel bzip2-devel libcurl-devel freetype-devel gd-devel readline-devel libmcrypt-devel libicu-devel
选择自己需要的PHP扩展,编译PHP。如果此时扩展少选了,后续还可以使用phpize安装扩展。
tar -zxvf cd php-7.3.4.tar.gz
cd cd php-7.3.4/
./configure --prefix=/usr/local/php7 --disable-fileinfo --with-pdo-mysql --with-mcrypt --with-bz2 --with-gd --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-libxml-dir --with-readline --with-curl --with-pear --with-openssl --with-fpm-user=www --with-fpm-group=www --enable-fpm --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-gd-native-ttf --enable-pcntl --enable-sockets --enable-soap --enable-session --enable-zip
编译时可能会提示某个依赖包版本较低比如下面的提示,都需要根据提示重新安装
a: configure: error: Please reinstall the libzip distribution
b: checking for libzip... configure: error: system libzip must be upgraded to version >= 0.11安装高版本libzip
yum remove libzip*
wget https://nih.at/libzip/libzip-1.2.0.tar.gz
tar -zxvf libzip-1.2.0.tar.gz
cd libzip-1.2.0
./configuremake
make install
cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
解决完问题后重新编译PHP,并执行。如果在make过程中遇到问题并解决后执行make clean再make。
make
make install
4. 配置
设置软连接
ln -s /usr/local/php7/bin/php /usr/bin/php
ln -s /usr/local/php7/bin/phpize /usr/bin/phpize
ln -s /usr/local/php7/bin/pecl /usr/bin/pecl
ln -s /usr/local/php7/bin/php-config /usr/bin/php-config
ln -s /usr/local/php7/sbin/php-fpm /usr/bin/php-fpm
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
配置nginx,是请求转发至phpfpm
vim /usr/local/nginx/conf/nginx.conf
配置php
cd /usr/local/php7/etc/
mv php-fpm.conf.default php-fpm.conf
cd /usr/local/php7/etc/php-fpm.d/
mv www.conf.default www.conf
5. 启动
php-fpm -D
nginx
如无报错则启动成功,可用ps查看服务状态
ps aux|grep nginx
ps aux|grep php-fpm