搭建 LNMP 架構 之 PHP 配置和論壇平臺(下篇)

[TOC]php

文章目錄

1、PHP解析環境

2、PHP配置安裝

3、配置及優化FPM模塊

4、nginx支持PHP功能配置

5、新建數據庫bbs

6、Discuz!社區論壇的部署

上接上篇博客繼續搭建LNMP架構,上一篇博客連接:搭建 LNMP 架構 之 nginx配置、MySQL安裝(上篇)

1、PHP解析環境

配置網頁動靜分離,解析PHP,有兩種方法能夠選擇

使用PHP的FPM模塊

將訪問PHP頁面的Web請求轉交給Apache服務器去處理

較新版本的PHP已經自帶FPM模塊,用來對PHP解析實例進行管理、優化解析效率

FastCGI將Http Server和動態腳本語言分離開

Nginx專[ ]處理靜態請求,轉發動態請求

PHP_ FPM專[門解析PHP動態請求

單服務器的LNMP架構一般使用FPM的方式來解析PHP

PHP-FPM(FastCGI Process Manager: FastCGI進程管理器)

是一個PHPFastCGI 管理器,因爲Nginx服務器不能處理動態頁面

2、PHP配置安裝

一、安裝環境依賴包

yum -y install \
libjpeg \ 
libjpeg-devel \
libpng libpng-devel \
libxml2 \
libxml2-devel \
freetype freetype-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel
----------------------------------------------
//參數解釋
libjpeg libjpeg-devel //識別jpg圖片
libpng lbpng-devel   //識別png圖片  
freetype freetype-devel   //字體識別
libxml2  libxml2-devel   //用於xml文件的識別
zlib zlib-devel    //壓縮功能
curl curl-devel   //curl支持網頁上傳、下載
openssl openssl-devel  //身份驗證登陸

二、掛載共享文件,解壓php安裝包

cd /abc/LNMP
tar jxvf php-7.1.10.tar.bz2 -C /opt/

三、編譯配置

cd /opt/php-7.1.10/
./configure \
--prefix=/usr/local/php \
--with-mysql-sock=/usr/local/mysql/mysql.sock \
--with-mysqli \
--with-zlib \
--with-curl \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-openssl \
--enable-fpm \
--enable-mbstring \
--enable-xml \
--enable-session \
--enable-ftp \
--enable-pdo \
--enable-tokenizer \
--enable-zip

四、make && make install

make && make install

五、配置優化 php 有三個配置文件。

php. ini (核心配置文件) php-fpm.conf (進程服務配置文件) www.conf (擴展配置文件)

//主配置文件
cp php.ini-development /usr/local/php/lib/php.ini
vim /usr/local/php/lib/php.ini

//輸入 /default_sock 查找
mysqli.default_socket = /usr/local/mysql/mysql.sock
// 輸入 /data.time 查找,把前面的‘ ;’註釋符去掉。
date.timezone = Asia/Shanghai

搭建 LNMP 架構 之 PHP 配置和論壇平臺(下篇)

搭建 LNMP 架構 之 PHP 配置和論壇平臺(下篇)
搭建 LNMP 架構 之 PHP 配置和論壇平臺(下篇)

六、驗證安裝的模塊

/usr/local/php/bin/php -m

3、配置及優化FPM模塊

一、複製一份默認模板做爲php-fpm的配置文件,再加以修改。

#配置及優化FPM模塊
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
vim php-fpm.conf

//把註釋符號‘;’去掉
pid = run/php-fpm.pid
一樣這個php-fpm.d也要複製一份默認模板
cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.conf

搭建 LNMP 架構 之 PHP 配置和論壇平臺(下篇)
搭建 LNMP 架構 之 PHP 配置和論壇平臺(下篇)
搭建 LNMP 架構 之 PHP 配置和論壇平臺(下篇)

二、啓動配置

/usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
netstat -anpt | grep 9000

搭建 LNMP 架構 之 PHP 配置和論壇平臺(下篇)

三、優化路徑。檢查進程

ln -s /usr/local/php/bin/* /usr/local/bin
ps aux | grep -c "php-fpm"

搭建 LNMP 架構 之 PHP 配置和論壇平臺(下篇)

4、讓 nginx 支持 PHP 功能配置

一、修改nginx的配置文件

vim /usr/local/nginx/conf/nginx.conf
//輸入  location ~ \.php$ 查找
location ~ \.php$ {
        root        html;
            fastcgi_pass    127.0.0.1:9000;
            fastcgi_index   index.php;
            fastcgi_param   SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
        inclide     fastcgi_params;     
}

搭建 LNMP 架構 之 PHP 配置和論壇平臺(下篇)

二、設置檢驗網頁index.php

vim /usr/local/nginx/html/index.php

//輸入:
<?php
phpinfo();
?>

搭建 LNMP 架構 之 PHP 配置和論壇平臺(下篇)

三、開啓 nginx 服務

systemctl restart nginx

//測試網頁
http://192.168.111.141/index.php

搭建 LNMP 架構 之 PHP 配置和論壇平臺(下篇)

5、新建數據庫bbs

下面測試數據庫工做是否正常

mysql -u -root -p   //輸入密碼 「abc123」登陸
/建立一個數據庫//
CREATE DATABASE bbs;                  
GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY 'admin123';
GRANT all ON bbs.* TO 'bbsuser'@'localhost' IDENTIFIED BY 'admin123';
//刷新數據庫//
mysql>flush privileges;   

//原來的測試頁內容更改:
vim /usr/local/nginx/html/index.php            

<?php
$link=mysqli_connect('192.168.111.141','bbsuser','admin123');
if($link) echo "<h1>Success!!</h1>";
else echo "Faill!!";
?>

systemctl restart nginx

在網頁測試「http://192.168.111.141/index.php」

搭建 LNMP 架構 之 PHP 配置和論壇平臺(下篇)

6、Discuz!社區論壇的部署

一、解壓安裝

cd /abc/LNMP
unzip Discuz_x3.4_SC_UTF8.zip -d /opt

二、受權安裝論壇

cd /opt/dir_SC_UTF8/
cp -r upload/ /usr/local/nginx/html/bbs/

cd /usr/local/nginx/html/bbs/

chown -R root:nginx ./config/
chown -R root:nginx ./data/
chown -R root:nginx ./uc_client/
chown -R root:nginx ./uc_server/

chmod -R 777 ./config/
chmod -R 777 ./data/
chmod -R 777 ./uc_client/
chmod -R 777 ./uc_server/

三、在瀏覽器輸入 http://192.168.111.141/bbs/install/index.php 安裝

搭建 LNMP 架構 之 PHP 配置和論壇平臺(下篇)

搭建 LNMP 架構 之 PHP 配置和論壇平臺(下篇)

搭建 LNMP 架構 之 PHP 配置和論壇平臺(下篇)

搭建 LNMP 架構 之 PHP 配置和論壇平臺(下篇)

搭建 LNMP 架構 之 PHP 配置和論壇平臺(下篇)

搭建 LNMP 架構 之 PHP 配置和論壇平臺(下篇)

到這裏咱們的LNMP架構已經搭建成功了。

相關文章
相關標籤/搜索