搭建LNMP架構 ---- PHP配置+安裝論壇

搭建LNMP架構 ---- PHP配置

一:PHP 概述

​ PHP(超文本預處理器),是一種通用開源腳本語言。PHP是在服務器端執行的腳本語言是常用的網站編程語言。有利於學習,使用廣泛,主要適用於web開發領域。 具有成本低、速度快、可移植性好、 內置豐富的函數庫等優點 。

二:PHP有三個配置文件

核心配置文件 ------ php.ini

進程服務配置文件 ------ php-fpm.conf

擴展配置文件 ------ www.conf

三:安裝 PHP 過程

1、安裝依賴包
[root@localhost ~]# yum install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel durl curl-devel openssl openssl-devel -y
2、解壓php壓縮包
[root@localhost abc]# tar jxvf php-7.1.10.tar.bz2 -C /opt/     ‘解壓php壓縮包’
[root@localhost abc]# cd /opt/
[root@localhost opt]# ls
ab.conf  mysql-5.7.20  nginx-1.12.2  php-7.1.10  rh
3、configure 編譯
[root@localhost php-7.1.10]# ./configure \
--prefix=/usr/1ocal/php \
--with-mysq1-sock=/usr/local/mysq1/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

[root@localhost php-7.1.10]# make && make install
4、修改配置文件
[root@localhost php-7.1.10]# cp php.ini-development /usr/local/php/lib/php.ini    ‘先複製一份到lib路徑下’

[root@localhost php-7.1.10]# vim /usr/local/php/lib/php.ini
1170    mysqli.default_socket = /usr/local/mysql/mysql.sock    ‘指定路徑’
939     date.timezone = Asia/shanghai      ‘ 前面 ; 去掉 ’ ‘指定時區’
5、驗證安裝模塊
[root@localhost php-7.1.10]# /usr/local/php/bin/php -m      ‘驗證安裝模塊’
6、配置及優化FPM模塊
[root@localhost php-7.1.10]# cd /usr/local/php/
[root@localhost php]# ls
bin  etc  include  lib  php  sbin  var
[root@localhost php]# cd etc/
[root@localhost etc]# ls
pear.conf  php-fpm.conf.default  php-fpm.d
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf    ‘複製一份到 php-fpm.conf’

[root@localhost etc]# cd /usr/local/php/etc/php-fpm.d/
[root@localhost php-fpm.d]# ls
www.conf.default
[root@localhost php-fpm.d]# cp www.conf.default www.conf     ‘複製擴展包’
[root@localhost php-fpm.d]# cd /usr/local/php/etc/
[root@localhost etc]# vim php-fpm.con    ‘進入文件’
17     pid = run/php-fpm.pid    ‘前面 ; 去掉’ ‘開啓pid’
[root@localhost etc]# /usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini             ‘開啓PHP’
[root@localhost etc]# netstat -ntap | grep 9000       ‘檢測是否成功’
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      36269/php-fpm: mast 
[root@localhost etc]# ln -s /usr/local/php/bin/* /usr/local/bin/    ‘創建軟鏈接,便於系統識別’
7、讓nginx 支持PHP
[root@localhost etc]# ps aux | grep -c "php-fpm"      ‘查看fpm進程’
4
[root@localhost etc]# ln -s /usr/local/nginx/conf/nginx.conf /etc/
[root@localhost etc]# vim /etc/nginx.conf     ‘進入文件,修改路徑’

[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-2F0MA8cW-1577101349065)(C:\Users\xumin\AppData\Roaming\Typora\typora-user-images\1577099979652.png)]

8、創建PHP首頁
[root@localhost etc]# cd /usr/local/nginx/html/
[root@localhost html]# ls
50x.html  index.html
[root@localhost html]# mv index.html index.html.bak     ‘把index.html 移動到index.html.bak’
[root@localhost html]# ls
50x.html  index.html.bak
[root@localhost html]# vim index.php      ‘創建PHP首頁’
<?php
        phpinfo();
?>

[root@localhost html]# systemctl restart nginx     ‘開啓nginx’
9、到win10客戶機驗證,網頁訪問PHP 首頁

[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-SH4CICYs-1577101349066)(C:\Users\xumin\AppData\Roaming\Typora\typora-user-images\1577100262186.png)]
這時 LNMP 架構搭建成功了。

四:測試數據庫工作是否正常

[root@localhost html]# mysql -uroot -p
Enter password:                   ‘輸入密碼,安裝mysql時設置的密碼’

mysql> CREATE DATABASE bbs;       ‘在mysql創建bbs庫’
 Query OK, 1 row affected (0.01 sec)
mysql> GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY 'admin123';   ‘給用戶授權’
 Query OK, 0 rows affected, 1 warning (0.05 sec)
mysql> GRANT all ON bbs.* TO 'bbsuser'@'localhost' IDENTIFIED BY 'admin123';    ‘給用戶授權’
 Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;         ‘刷新Musql的系統權限相關表’
 Query OK, 0 rows affected (0.01 sec)
[root@localhost html]# vim index.php         ‘把原來的測試頁內容更改’
<?php
$link=mysqli_connect('192.168.34.149','bbsuser','admin123');
if($link) echo "<h1>Success!!</h1>";          ‘會在網頁上顯示’
else echo "Fail!!";
?>

[root@localhost html]# systemctl restart nginx     ‘開啓nginx’

在win10客戶機上驗證,可以看到在配置文件編寫的內容
[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-zgcITWLD-1577101349067)(C:\Users\xumin\AppData\Roaming\Typora\typora-user-images\1577100720654.png)]

五:安裝論壇

可接着上面的步驟繼續

1、解壓Discuz 論壇文件
[root@localhost html]# cd /abc
[root@localhost abc]# unzip Discuz_X3.4_SC_UTF8.zip -d /opt/       ‘解壓’
[root@localhost abc]# cd /opt/      ‘查看/opt/目錄下被解壓的文件’
[root@localhost opt]# ls
ab.conf  dir_SC_UTF8  mysql-5.7.20  nginx-1.12.2  php-7.1.10  rh  說明.htm
2、授權
[root@localhost opt]# cd dir_SC_UTF8/
[root@localhost dir_SC_UTF8]# ls
readme  upload  utility  
[root@localhost dir_SC_UTF8]# cp -r upload/ /usr/local/nginx/html/bbs
[root@localhost dir_SC_UTF8]# cd /usr/local/nginx/html/
[root@localhost html]# ls
50x.html  bbs  index.html.bak  index.php
‘授權’
[root@localhost html]# cd /usr/local/nginx/html/bbs/
[root@localhost bbs]# chown -R root:nginx ./config/
[root@localhost bbs]# chown -R root:nginx ./data/
[root@localhost bbs]# chown -R root:nginx ./uc_client/
[root@localhost bbs]# chown -R root:nginx ./uc_server/
[root@localhost bbs]# chmod -R 777 ./config/
[root@localhost bbs]# chmod -R 777 ./data/
[root@localhost bbs]# chmod -R 777 ./uc_client/
[root@localhost bbs]# chmod -R 777 ./uc_server/

3、在win10客戶機驗證,在網頁中安裝論壇

[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-uNH1HIx2-1577101349068)(C:\Users\xumin\AppData\Roaming\Typora\typora-user-images\1577101191214.png)]
點擊下一步:
[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-YDU8wSoj-1577101349068)(C:\Users\xumin\AppData\Roaming\Typora\typora-user-images\1577101211659.png)]
這邊注意修改數據庫用戶名、密碼等信息。
[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-tCBdDBEt-1577101349069)(C:\Users\xumin\AppData\Roaming\Typora\typora-user-images\1577101251815.png)]
[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-pOJZFpxV-1577101349069)(C:\Users\xumin\AppData\Roaming\Typora\typora-user-images\1577101276245.png)]

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