LNMP專案部署
介紹
專案的生命周期
- 策劃:老板+產品+UI設計
- 實施:前端開發(客戶端頁面)+后端開發(ava php python等)+測驗
- 上線:運維
- 維護:運維
- 結束
運維作業內容
- 專案策劃,實施之初,進行準備作業,學習對應架構和方案
- 服務器上搭建代碼版本控制器
- 為測驗人員搭建測驗環境
- 部署專案上線
- 專案后期維護
分布式集群
-
集群:多臺服務器在一起作同樣的事
-
分布式 :多臺服務器在一起作不同的事
-
常用架構
- 負債均衡LB
- 高可用HA
- 資料庫主從復制M-S
- 讀寫分離R-W
- 快取中間件:memcached、Redis
- 非關系型資料庫:mongodb

專案背景
- 年份:2021
- 發布產品型別:互聯網動態站點 社區論壇 商城 社交類站點
- 用戶數量:100-500
- PV:頁面訪問數量,點擊量,1000-3000(24小時訪問次數總和)
- QPS:并發量,吞吐量,5-10(每秒訪問查詢次數)
- 計算:pv/時間 = qps
- 壓測:使用ab等并發測驗軟體,在規定時間發送一定的請求數量
- TPS:每秒事務次數,5-10
- RPS:每秒請求次數,5-10
- DAU:每榷訓躍用戶數,榷訓數,10-50
軟體架構
- C/S client/server
- B/S browser/server
不管是C還是B,都是屬于前端客戶端
運維人員主要負責和管理的是server端,也統稱為服務器端
- LAMP:Linux+Apache+MySQL+PHP
- LNMP:Linux+Nginx+MySQL+PHP
- LNMPA:Linux+Nginx+MySQL+PHP+Apache
- LNMT:Linux+Nginx+MySQL+Tomcat

環境準備
最小化安裝centOs6.9
安裝vim
[root@server02 ~]# yum install -y vim
已加載插件:fastestmirror
設定安裝行程
YumRepo Error: All mirror URLs are not using ftp, http[s] or file.
Eg. Invalid release/repo/arch combination/
removing mirrorlist with no valid mirrors: /var/cache/yum/x86_64/6/base/mirrorlist.txt
錯誤:Cannot retrieve repository metadata (repomd.xml) for repository: base. Please verify its path and try again
報錯:Cannot retrieve repository metadata (repomd.xml) for repository: base.
原因:CentOS6已經在2020年11月30日停止維護了,centos官方停止了對centos6的所有更新,并且下架了包括官方所有的centos6源,目前阿里、163、清華等centos6源已無法使用
解決:如下
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
vi /etc/yum.repos.d/CentOS-Base.repo
#撰寫
[centos-office]
name=centos-office
failovermethod=priority
baseurl=https://vault.centos.org/6.10/os/x86_64/
gpgcheck=1
gpgkey=https://vault.centos.org/6.10/os/x86_64/RPM-GPG-KEY-CentOS-6
yum list
yum install -y vim
配置vim
echo "set nu" >> /root/.vimrc
echo "set ts=4" >> /root/.vimrc
sed -i "8calias grep='grep --color'" /root/.bashrc
source /root/.bashrc
關閉防火墻
service iptables stop
chkconfig iptables off
setenforce 0
sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config
修改主機名
vim /etc/sysconfig/network
#修改為
HOSTNAME=server01
su
域名決議
vim /etc/hosts
#追加
192.168.139.128 server01.lnmp.com server01
時間同步
yum -y install ntp
service ntpd start
chkconfig ntpd on
ntpdate cn.ntp.org.cn
LNMP部署
MySQL安裝
編譯引數的說明
| 編譯引數 | 說明 |
|---|---|
| -DCMAKE_INSTALL_PREFIX | 安裝到的軟體目錄 |
| -DMYSQL_DATADIR | 資料檔案存盤的路徑 |
| -DSYSCONFDIR | 組態檔路徑 (my.cnf) |
| -DENABLED_LOCAL_INFILE=1 | 使用localmysql客戶端的配置 |
| -DWITH_PARTITION_STORAGE_ENGINE | 使mysql支持分表 |
| -DEXTRA_CHARSETS | 安裝支持的字符集 |
| -DDEFAULT_CHARSET | 默認字符集使用 這里配置為utf8mb4 |
| -DDEFAULT_COLLATION | 連接字符集 |
| -DWITH_SSL | 開啟mysql的ssl使用 |
初始化引數說明
| 初始化引數 | 說明 |
|---|---|
| –basedir | 安裝到的軟體目錄 |
| –datadir | 資料檔案存盤路徑 |
| –user | mysql使用的用戶 |
腳本安裝及其初始化
[root@server01 ~]# yum install -y lrzsz
[root@server01 ~]# mkdir /root/soft
[root@server01 ~]# cd /root/soft
[root@server01 soft]# rz
#傳入mysql-5.6.33.tar.gz軟體包
[root@server01 ~]# vim mysql_install.sh
#!/bin/bash
#原始碼編譯安裝MySQL
mysql_install() {
#1、創建用戶
`id mysql` &>/dev/null
[ $? -ne 0 ] && useradd -s /sbin/nologin -M mysql
#2、解決依賴
yum install -y cmake ncurses-devel
#3、編譯安裝
cd /root/soft
tar zxvf mysql-5.6.33.tar.gz
cd mysql-5.6.33
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_SSL=bundled
make && make install
#組態檔
rm -rf /etc/my.cnf
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
#授權并初始化資料庫
chown -R mysql:mysql /usr/local/mysql
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
#配置服務、自啟動和環境變數
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
service mysqld start
chkconfig --add mysqld
echo 'PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile
source /etc/profile
#洗掉匿名用戶
#設定root域名的密碼
rpm -qa|grep expect
if [ $? -ne 0 ];then
yum -y install expect
fi
#匯入環境變數PATH
export PATH=/usr/local/mysql/bin:$PATH
#初始化root密碼 洗掉匿名用戶
echo '#!/usr/bin/expect
set timeout 60
spawn mysql_secure_installation
expect {
"enter for none" { send "\r"; exp_continue}
"Y/n" { send "Y\r" ; exp_continue}
"password" { send "123456\r"; exp_continue}
"Cleaning up" { send "\r"}
}
interact ' > mysql_secure_installation.exp
chmod +x mysql_secure_installation.exp
./mysql_secure_installation.exp
}
#腳本開始時間
start_time=`date +%s`
#執行的腳本代碼
mysql_install
#腳本結束時間
end_time=`date +%s`
#腳本執行花費時間
const_time=$((end_time-start_time))
echo 'Take time is: '$const_time's'
[root@server01 ~]# sh mysql_install.sh
Nginx安裝
介紹
官網
http://nginx.org/

功能
- web服務器 httpd http協議
同類的web服務器軟體:apache,nginx(俄羅斯),IIS(微軟 fastcgi),lighttpd(德國)
- 代理服務器 反向代理
- 郵箱代理服務器 IMAP POP3 SMTP
- 負載均衡功能 LB loadblance
特點(優點)
- 高可靠:穩定性高,一個master多個worker,master行程用于管理調度請求分發到哪一個worker行程,worker行程用于回應請求,當其中一個worker行程出現問題,master會調度其他worker行程
- 熱部署 :(1)平滑升級 ;(2)可以快速多載配置
- 高并發:可以同時回應更多的請求 ,達到幾萬的并發量,基于事件epoll模型
- 回應快:尤其在處理靜態檔案上,回應速度很快 ,內核基于sendfile機制
- 低消耗:cpu和記憶體占用低,建立開銷1w個請求 ,記憶體只消耗2-3MB
- 分布式支持 :反向代理,七層負載均衡
安裝
- 編譯引數說明
| 引數 | 作用 |
|---|---|
| –prefix | 編譯安裝到的軟體目錄 |
| –user | worker行程運行用戶 |
| –group | worker行程運行用戶組 |
| –with-http_ssl_module | 支持https,需要pcel-devel依賴 |
| –with-http_stub_status_module | 基本狀態資訊顯示,查看請求數、連接數等 |
| –with-http_realip_module | 定義客戶端地址和埠為header頭資訊 用于反向代理后的真實IP獲取 |
[root@server01 ~]# cd /root/soft/
[root@server01 soft]# rz
#傳入下載好的 nginx-1.14.2軟體包
[root@server01 soft]# tar -xzf nginx-1.14.2.tar.gz
[root@server01 soft]# ls
mysql-5.6.33 mysql_secure_installation.exp nginx-1.14.2.tar.gz
mysql-5.6.33.tar.gz nginx-1.14.2
[root@server01 nginx-1.14.2]# useradd -s /sbin/nologin -M www
[root@server01 nginx-1.14.2]# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module
報錯:./configure: error: the HTTP rewrite module requires the PCRE library.
原因:缺少pcre-devel依賴庫
解決:yum install -y pcre-devel
[root@server01 nginx-1.14.2]# yum install -y pcre-devel
[root@server01 nginx-1.14.2]# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module
報錯:./configure: error: SSL modules require the OpenSSL library.
原因:缺少openssl-devel依賴庫
解決:yum install -y openssl-devel
[root@server01 nginx-1.14.2]# yum install -y openssl-devel
[root@server01 nginx-1.14.2]# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ using system zlib library
[root@server01 nginx-1.14.2]# make && make install
[root@server01 nginx-1.14.2]# cd /usr/local/nginx/
[root@server01 nginx]# pwd
/usr/local/nginx
腳本安裝(提前將軟體包下載到/root/soft):
#!/bin/bash #編譯安裝Nginx nginx_install(){ #創建軟體運行用戶 `id www` &>>/dev/null if [ $? -ne 0 ];then useradd -s/sbin/nologin -M www fi #安裝依賴 yum -y install pcre-devel zlib-devel openssl-devel #編譯安裝 cd /root/soft tar xvf nginx-1.14.2.tar.gz cd nginx-1.14.2 ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module && make && make install } #腳本開始時間 start_time=`date +%s` #執行的腳本代碼 nginx_install #腳本結束時間 end_time=`date +%s` #腳本執行花費時間 const_time=$((end_time-start_time)) echo 'Take time is: '$const_time's'
初始化
[root@server01 nginx-1.14.2]# cd /usr/local/nginx/
[root@server01 nginx]# ls
conf html logs sbin
[root@server01 nginx]# cd sbin/
[root@server01 sbin]# ls
nginx
| 目錄 | 作用 |
|---|---|
| conf | 組態檔 |
| html | 網站根目錄 |
| logs | 日志 |
| sbin | 可執行檔案 [軟體的啟動,停止,重啟等] |
啟動nginx
[root@server01 sbin]# ./nginx
[root@server01 sbin]# ss -tnalp|grep nginx
LISTEN 0 128 *:80 *:* users:(("nginx",34295,6),("nginx",34296,6))
[root@server01 sbin]# ps -ef |grep nginx
root 34295 1 0 17:57 ? 00:00:00 nginx: master process ./nginx
www 34296 34295 0 17:57 ? 00:00:00 nginx: worker process
root 34304 3419 0 17:57 pts/0 00:00:00 grep --color nginx
[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-pvRlavDz-1633274276799)(…/%E5%9B%BE%E7%89%87%E6%94%BE%E7%BD%AE%E7%82%B9/image-20211002180101979.png)]
引數介紹(#后面的了解即可,不常用)
[root@server01 sbin]# ./nginx -h
nginx version: nginx/1.14.2
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]
Options:
-?,-h : this help 幫助
-v : show version and exit #版本查看
-V : show version and configure options then exit查看版本和配置選項
-t : test configuration and exit 檢測組態檔語法
-T : test configuration, dump it and exit
-q : suppress non-error messages during configuration testing #在配置測驗期間禁止顯示非錯誤資訊
-s signal : send signal to a master process: stop, quit, reopen, reload stop強制退出 quit優雅的退出 reopen重開日志 reload多載配置
-p prefix : set prefix path (default: /usr/local/nginx/) #設定nginx目錄
-c filename : set configuration file (default: conf/nginx.conf) #指定啟動使用的組態檔
-g directives : set global directives out of configuration file
- nginx編譯包里默認沒有服務啟動腳本模板,可以通過官方社區獲得https://www.nginx.com/resources/wiki/start/topics/examples/redhatnginxinit/
服務配置
[root@server01 ~]# cd /etc/init.d/
[root@server01 init.d]# rz
#傳入已經下載的nginx腳本
[root@server01 init.d]# chmod +x nginx
開啟
[root@server01 init.d]# service nginx start
[root@server01 init.d]# chkconfig --add nginx
[root@server01 init.d]# chkconfig nginx on
PHP安裝
介紹
-
PHP: Hypertext Preprocessor,超文本前處理器
- HTML:超文本標記語言
- HTTP:超文本傳輸協議
-
頁面分類:
-
靜態頁面 一般普通訪問到的頁面
-
動態頁面 用戶可以和服務器進行互動頁面
-
執行動態頁面,需要和服務器進行互動,使用后端語言進行開發,php可實作該功能
-

-
PHP是一種通用開源腳本語言,混合了C、Java、Perl以及PHP自創的語法,主要適用于Web開發
-
PHP是將程式嵌入到HTML(標準通用標記語言下的一個應用)檔案中去執行,執行效率比完全生成HTML標記的CGI要高許多
-
PHP還可以執行編譯后代碼,編譯可以達到加密和優化代碼運行,使代碼運行更快
-
PHP-FPM(FastCGI Process Manager:FastCGI行程管理器),PHP-FPM提供了更好的PHP行程管理方式,可以有效控制記憶體和行程、可以平滑多載PHP配置,在./configure的時候帶 –enable-fpm引數即可開啟PHP-FPM
安裝
[root@server01 init.d]# cd /root/soft/
[root@server01 soft]# rz
[root@server01 soft]# ls
mysql-5.6.33 mysql-5.6.33.tar.gz mysql_secure_installation.exp nginx-1.14.2 nginx-1.14.2.tar.gz php-7.2.12.tar.gz
[root@server01 soft]# tar -xzf php-7.2.12.tar.gz
[root@server01 soft]# cd php-7.2.12
解決依賴(可忽略下文因依賴報錯的部分)
[root@server01 php-7.2.12]# yum -y install libxml2-devel libjpeg-devel libpng-devel freetype-devel curl-devel openssl-devel
配置
[root@server01 php-7.2.12]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --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-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-libzip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts
報錯:configure: error: libxml2 not found. Please check your libxml2 installation.
原因:缺少依賴庫libxml2
解決:yum install -y libxml2-devel
[root@server01 php-7.2.12]# yum install -y libxml2-devel
[root@server01 php-7.2.12]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --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-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-libzip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts
報錯:configure: error: cURL version 7.10.5 or later is required to compile php with cURL support
原因:缺少curl依賴庫
解決:yum install -y curl-devel
[root@server01 php-7.2.12]# yum install -y curl-devel
[root@server01 php-7.2.12]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --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-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-libzip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts
報錯:configure: error: jpeglib.h not found.
原因:缺少libjpeg依賴庫
解決:yum install -y libjpeg-devel
[root@server01 php-7.2.12]# yum install -y libjpeg-devel
[root@server01 php-7.2.12]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --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-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-libzip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts
報錯:configure: error: png.h not found.
原因:缺少libpng依賴庫
解決:yum install -y libpng-devel
[root@server01 php-7.2.12]# yum install -y libpng-devel
[root@server01 php-7.2.12]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --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-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-libzip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts
報錯:configure: error: freetype-config not found.
原因:缺少freetype依賴庫
解決:yum install -y freetype-devel
[root@server01 php-7.2.12]# yum install -y freetype-devel
[root@server01 php-7.2.12]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --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-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-libzip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts
編譯安裝
[root@server01 php-7.2.12]# make && make install
[root@server01 php-7.2.12]# cd /usr/local/php/
[root@server01 php]# ls
bin etc include lib php sbin var
| 目錄名稱 | 作用 |
|---|---|
| bin | php相關命令目錄,php 、phpize、php-config在原始碼編譯擴展時用 |
| etc | 組態檔 |
| include | php默認類別庫 |
| lib | php第三方擴展類別庫 |
| php | man檔案檔案 |
| sbin | php-fpm執行檔案 |
| var | log日志目錄 ;run運行目錄 ;保存pid檔案 |
初始化
使組態檔生效
[root@server01 php]# cd etc
[root@server01 etc]# ls
php-fpm.conf.default php-fpm.d
[root@server01 etc]# cp php-fpm.conf.default php-fpm.conf
[root@server01 etc]# cp php-fpm.d/www.conf.default php-fpm.d/www.conf
[root@server01 etc]# ls
php-fpm.conf php-fpm.conf.default php-fpm.d
[root@server01 etc]# cp /root/soft/php-7.2.12/php.ini-development /usr/local/php/etc/php.ini
#組態檔說明
php.ini 默認php組態檔
php-fpm.conf php-fpm相關的配置
啟動php
[root@server01 etc]# cd ../sbin/
[root@server01 sbin]# ./php-fpm
選項說明
[root@server01 sbin]# ./php-fpm -h
Usage: php-fpm [-n] [-e] [-h] [-i] [-m] [-v] [-t] [-p <prefix>] [-g <pid>] [-c <file>] [-d foo[=bar]] [-y <file>] [-D] [-F [-O]]
-c <path>|<file> Look for php.ini file in this directory
-n No php.ini file will be used
-d foo[=bar] Define INI entry foo with value 'bar'
-e Generate extended information for debugger/profiler
-h This help
-i PHP information
-m Show compiled in modules
-v Version number
-p, --prefix <dir>
Specify alternative prefix path to FastCGI process manager (default: /usr/local/php).
-g, --pid <file>
Specify the PID file location.
-y, --fpm-config <file>
Specify alternative path to FastCGI process manager config file.
-t, --test Test FPM configuration and exit
-D, --daemonize force to run in background, and ignore daemonize option from config file
-F, --nodaemonize
force to stay in foreground, and ignore daemonize option from config file
-O, --force-stderr
force output to stderr in nodaemonize even if stderr is not a TTY
-R, --allow-to-run-as-root
Allow pool to run as root (disabled by default)
添加到啟動服務中
[root@server01 php-7.2.12]# cp /root/soft/php-7.2.12/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@server01 php-7.2.12]# chmod +x /etc/init.d/php-fpm
[root@server01 php-7.2.12]# chkconfig --add php-fpm
[root@server01 php-7.2.12]# chkconfig --list
添加環境變數
[root@server01 php-7.2.12]# echo 'PATH=/usr/local/php/bin:$PATH' >> /etc/profile
[root@server01 php-7.2.12]# source /etc/profile
上述步驟均可使用腳本代替
#!/bin/bash php_install(){ #php編譯安裝 #和nginx使用相同的用戶,如果沒有就創建 `id www` &> /dev/null [ $? -ne 0 ] && useradd -s /sbin/nologin -M www #解決依賴 yum -y install libxml2-devel libjpeg-devel libpng-devel freetype-devel curl-devel openssl-devel #解壓 tar xvf php-7.2.12.tar.gz cd php-7.2.12 #編譯安裝php ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --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-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-libzip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts && make && make install #組態檔初始化 cp php.ini-development /usr/local/php/etc/php.ini #php-fpm服務組態檔 cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf #php-fpm服務子組態檔 cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf #配置服務及其環境變數 cp /root/soft/php-7.2.12/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm chmod +x /etc/init.d/php-fpm service php-fpm start chkconfig --add php-fpm echo 'PATH=/usr/local/php/bin:$PATH' >> /etc/profile } #腳本開始時間 start_time=`date +%s` #執行的腳本代碼 php_install #腳本結束時間 end_time=`date +%s` #腳本執行花費時間 const_time=$((end_time-start_time)) echo 'Take time is: '$const_time's'
Nginx+php-fpm配置
撰寫測驗檔案
[root@server01 php-7.2.12]# vim /usr/local/nginx/html/index.php
<?php
phpinfo();
修改組態檔
[root@server01 php-7.2.12]# vim /usr/local/nginx/conf/nginx.conf
41 #access_log logs/host.access.log main;
42 root html; 第一步:把root變數提升上層
43 location / {
44 #root html; 這里的root需要被注釋掉
45 index index.html index.htm;
46 }
47
48 #error_page 404 /404.html;
49
50 # redirect server error pages to the static page /50x.html
51 #
52 error_page 500 502 503 504 /50x.html;
53 location = /50x.html {
54 root html;
55 }
56
57 # proxy the PHP scripts to Apache listening on 127.0.0.1:80
58 #
59 #location ~ \.php$ {
60 # proxy_pass http://127.0.0.1;
61 #}
62
63 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
64 #
65 location ~ \.php$ { 第二步:該段解注釋
66 # root html; 默認使用上層的root變數,這里也要注釋掉
67 fastcgi_pass 127.0.0.1:9000;
68 fastcgi_index index.php;
69 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 第三步:把script修改為$document_root
70 include fastcgi_params;
71 } 注意,不要忘記最后這個括號
72
root@server01 php-7.2.12]# service nginx configtest
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@server01 php-7.2.12]# service nginx reload
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
重新載入 nginx: [確定]
測驗

轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/305407.html
標籤:其他
上一篇:計算機網路概述(1)基本概念、因特網組成與三種交換方式、計算機網路的分類
下一篇:Linux之無人值守安裝系統
