Ubuntu编译安装nginx PHP7.2

编译Nginx

准备工作, 下载包,创建安装目录

wget https://nginx.org/download/nginx-1.16.1.tar.gz
mkdir -p /data/exec

安装依赖

apt install -y libpcre3 libpcre3-dev openssl libssl-dev build-essential zlib1g-dev

创建用户www

useradd www -s '/sbin/nologin'

开始编译nginx

./configure --user=www --group=www \
--prefix=/data/exec/nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_gzip_static_module \
--with-http_sub_module \
--with-stream \
--with-stream_ssl_module \
--with-openssl-opt='enable-weak-ssl-ciphers'

make && make install

编译PHP

准备工作

wget https://www.php.net/distributions/php-7.2.28.tar.bz2
mkdir -p /data/exec

创建用户www(已创建则忽略)

useradd www -s '/sbin/nologin'

编译php7依赖

apt install -y libxml2 libxml2-dev libcurl4-openssl-dev libfreetype6-dev libjpeg-dev libicu-dev libxslt1-dev openssl

如果需要ldap扩展需要安装libldap-dev这个包

编译PHP7.2

./configure --prefix=/data/exec/php \
--with-config-file-path=/data/exec/php/etc \
--with-config-file-scan-dir=/data/exec/php/conf.d \
--enable-fpm --with-fpm-user=www --with-fpm-group=www \
--enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd \
--with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir \
--with-zlib --with-libxml-dir --enable-xml --disable-rpath \
--enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization \
--with-curl --enable-mbregex --enable-mbstring --enable-intl --enable-ftp --with-gd \
--with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip \
--enable-soap --with-gettext --enable-opcache --with-xsl

如果提示configure: error: Cannot find OpenSSL's libraries
我们需要执行find / -name libssl.so 假设输出: /usr/lib/x86_64-linux-gnu/libssl.so
重新做一个软连接
ln -s /usr/lib/x86_64-linux-gnu/libssl.so /usr/lib

make && make install

测试PHP能不能正常工作

mkdir -p /data/exec/nginx/html/
echo "" >> /data/exec/nginx/html/index.php

开启opcache扩展
php.ini 添加一行

zend_extension=opcache.so

查看编译参数

php -i |grep configure
nginx -V
cat /user/local/mysql/bin/mysqlbug |grep configure

查看php当前用的是什么配置文件
php --ini

查看php安装的扩展
php -m

你可能感兴趣的:(运维)