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 "<?php phpinfo(); ?>" >> /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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章