【03】Cent OS 7 中部署Nginx + PHP 環境
一、Nginx環境部署
1、部署說明
1)確保系統安裝GCC編譯器及相關工具。上篇文章中已說明,使用 rpm包 安裝部署。
2)rewrite 模塊需要 pcre 庫。樓主使用的是 pcre-8.42.zip。
3)ssl 功能需要 openssl 庫。樓主使用的是 openssl-1.0.2o.tar.gz。
2、使用源包安裝 pcre,註意解壓後的源包不要刪除
參考文檔:https://www.cnblogs.com/LiuYanYGZ/p/5903954.html
3、使用源包安裝 openssl,註意解壓後的源包不要刪除
參考文檔:https://www.landui.com/help/show-1586.html
4、安裝Nginx
1)官網下載最新的軟件包
2)上傳至服務器
3)解壓,進入源包文件夾,執行步驟4~6進行安裝
4)./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_image_filter_module --with-http_gzip_static_module --with-pcre=/usr/local/src/pcre-8.42 --with-openssl=/usr/local/src/openssl-1.0.2o
註意:pcre 和 openssl 的路徑都是解壓後的源包路徑!!!
遇到問題:
解決方法:
在線:yum -y install gd-devel
離線:安裝以下的rpm
gd-2.0.35-26.el7.x86_64.rpm
gd-devel-2.0.35-26.el7.x86_64.rpm
5)編譯 make
6)安裝 make install
7)安裝nginx用戶
useradd -s /sbin/nologin -M nginx
id nginx
8)啟動 nginx,執行命令:/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
9)查看進程,ps aux | grep nginx
5、測試頁面
1)測試頁面前需要給防火墻添加80端口,否則無法打開測試頁面。
2)執行以下命令後,即可使用瀏覽器打開測試頁面了(http://X.X.X.X)
systemctl stop firewalld.service
firewall-cmd --zone=public --add-port=80/tcp --permanent
systemctl restart firewalld.service
6、開機自啟動設置
參考文檔:https://www.cnblogs.com/whatmiss/p/7091220.html
腳本內容:
二、PHP 環境部署
1、確保安裝之前有安裝gd,png,curl,xml等等lib開發庫。樓主使用 rpm包的方式安裝。
2、下載PHP。官網下載:http://www.php.net。樓主使用的是php-7.2.7.tar.gz
3、上傳至服務器,解壓,進入源包文件夾。執行4~6步驟。
4、Configure配置
./configure --prefix=/usr/local/php-7.2.7 --with-config-file-path=/usr/local/php-7.2.7/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath
問題1:
解決方法:重新安裝gcc、gcc-g++
問題2:
解決方法:
libcurl-7.29.0-46.el7.x86_64.rpm
libcurl-devel-7.29.0-46.el7.x86_64.rpm
問題3:
checking for jpeg_read_header in -ljpeg... no
configure: error: Problem with libjpeg.(a|so). Please check config.log for more information.
解決方法:
https://www.cnblogs.com/sybblogs/p/6085314.html
https://www.aliyun.com/jiaocheng/202425.html
5、make
6、make test
7、make install
8、配置PHP
cp php.ini-production /usr/local/php-7.2.7/etc/php.ini
cp /usr/local/php-7.2.7/etc/php-fpm.conf.default /usr/local/php-7.2.7/etc/php-fpm.conf
cd /usr/local/php-7.2.7/etc/php-fpm.d
cp www.conf.default www.conf
9、啟動 php-fpm
執行命令:/usr/local/php-7.2.7/sbin/php-fpm
關於如何啟動和關閉php-fpm,可參考:https://blog.csdn.net/u010716097/article/details/71908096/
10、測試頁面
1)進入nginx的html目錄,創建文件info.php,輸入內容如圖所示。
2)設置nginx的配置文件
cat nginx.conf,修改成如圖所示內容。
3)重啟nginx
4)瀏覽器打開http://X.X.X.X/info.php,顯示如下頁面即PHP與nginx安裝配置成功。
11、開機自啟動設置
參考文檔:https://www.cnblogs.com/tongl/p/7217283.html
腳本內容:
【03】Cent OS 7 中部署Nginx + PHP 環境