電商平臺 lnmp 之 nginx mysql php 部署(1)
- 1. nginx 部署
- 2. mysql 的部署
- 3. php 部署
1. nginx 部署
在 nginx 官網下載 nginx 的原始碼包;此處我們選擇的是穩定版 nginx-1.18.0.tar.gz ;

- 解壓
[root@server1 ~]# ls
nginx-1.18.0.tar.gz
[root@server1 ~]# tar zxf nginx-1.18.0.tar.gz ##解壓
[root@server1 ~]# ls
nginx-1.18.0 nginx-1.18.0.tar.gz
[root@server1 ~]# cd nginx-1.18.0
[root@server1 nginx-1.18.0]# ls
##解壓之后,如果看到里面有 configure 腳本,
表示是 gmake,gmake:GNU組織的 make,是開源的;
cmake:商業化 ##
auto CHANGES.ru configure html man src
CHANGES conf contrib LICENSE README
- 編譯
在編譯前,可以在原始碼包中輸入./configure - - help來獲得編譯幫助;幫助里的 - -without代表默認有的選項,如果在腳本后加上這個引數,代表把它去掉,- -with代表沒有激活的功能,

輸入命令 ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with http_stub_status_module來開始編譯;
其中--prefix=/usr/local/nginx表示自定義安裝目錄, -- with-XXX_ module選項表示指明安裝對應的模塊,--without-XXX_ module選項表示指明不安裝對應的模塊;
注意:如果在配置的時候不設定安裝路徑,默認情況下會自動安裝到/usr/local/目錄下,將相關資訊分布在該目錄下的其他目錄中;為了方便查找與使用,我們可以在配置的時候自定義路徑/usr/local/nginx,
開始編譯之后會提示一些出現的問題,缺少依賴性軟體;只需根據提示依次安裝即可;
1)yum install -y gcc安裝 gcc ,解壓后的原始碼 nginx 是C語言,原始碼編譯就需要安裝 gcc;
安裝完成之后再次編譯: ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with http_stub_status_module
2)PCRE library不符合要求,這個庫用于網站的重寫,重定向;

比如:curl -I 163.com,在訪問域名時,重定向到www上;

根據錯誤,安裝 yum install -y pcre-develpcre-devel庫檔案,在Redhat 里,所有的開發庫檔案都是以-devel結尾;
安裝完成之后再次編譯: ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with http_stub_status_module
3) http狀態監控需要Openssl library的支持,在Linux上都是用openssl來做加密的;

根據錯誤, yum install openssl-devel -y安裝openssl-devel庫;
安裝完成之后再次編譯: ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with http_stub_status_module
沒有報錯完成之后,configure命令是為了在當前環境生成 Makefile檔案;

configure 配置的所有引數,最終都會寫入/nginx-1.18.0/Makefile檔案中;

4) make
接下的 make ,是按照 Makefile 檔案來進行編譯,編譯完成之后會在當前目錄生成符合當前系統的二進制程式;
注: make進行編譯,編譯后如果出現問題,可以使用make clean將編譯引數清空然后重新編譯,
5) make install
然后 make install,編譯好的程式會在/nginx-1.18.0/objs/nginx 中,同時會拷貝到剛才指定的位置 /usr/local/nginx/sbin 中 ;

6) 安裝完成后,進入/usr/local/nginx/目錄下的sbin里面存放的是nginx,在該目錄下輸入./nginx即可啟動:
/usr/local/nginx/ 目錄下各個檔案的含義:
conf:存放nginx的組態檔;
html:是默認提供的web服務的根目錄;
logs:是nginx日志的存放目錄;
sbin:存放nginx的二進制檔案,可以使用nginx二進制檔案啟動nginx.
- 優化二進制程式
這個二進制程式有點大,要進行優化,把bug去掉
此處可以洗掉之前的 nginx 的目錄,關閉 debug 然后再次 configure 、make 、 make install,也可以執行 make clean 命令,清理編譯的內容,
此處有原始碼包存在,直接洗掉之前的解壓后的包,再次編譯即可,
關閉debug
[root@server1 nginx-1.18.0]# cd
[root@server1 ~]# ls
nginx-1.18.0 nginx-1.18.0.tar.gz
[root@server1 nginx-1.18.0]# vim auto/cc/gcc
# debug
#CFLAGS="$CFLAGS -g"
如圖所示:

然后重新make make install;
再次編譯完成之后,查看大小:

- nginx 的啟動腳本
nginx 二進制程式編譯完成之后默認在 /usr/local/nginx/sbin下,如果要啟動 nginx ,就要甬道絕對路徑的方式來啟動或者進入到該目錄中執行該腳本,就顯得很麻煩;可以將其寫在系統的PATH環境里面;

添加完環境變數之后,輸入命令 source .bash_profile來讓其生效;
然后就可以直接執行 nginx 來啟動 nginx;啟動之后,可以來查看 nginx 的行程狀態,

輸入命令netstat -antlp來查看埠資訊,nginx 的80 埠是我們所需要的;

注:此處要安裝yum install net-tools -y埠查詢工具,
測驗
輸入命令curl localhost本地測驗;

也可以網頁訪問 172.25.25.1該 IP 為安裝 nginx 的主機 ip ,

- 目錄介紹
nginx 的默認發布目錄在/usr/local/nginx/html下;
可以通過人為方式來更改默認發布的內容,編輯檔案,更改發布內容;

查看測驗效果,訪問測驗檔案172.25.25.1/tes/html,效果如下所示:

- nginx 的常用命令
[root@server1 ~]# nginx ##開啟
[root@server1 ~]# nginx -s reload ##多載
[root@server1 ~]# nginx -s stop ##關閉
注: 一旦開啟就不要再次重復開啟,否則會報如下的錯誤,

2. mysql 的部署
在mysql 官網 https://www.mysql.com/downloads/ 下載官方社區版本原始碼包的,要帶有 boost ,此處安裝 mysql-5.7.31 的版本;


- 解壓
[root@server1 ~]# ls
mysql-5.7.31 nginx-1.18.0
mysql-boost-5.7.31.tar.gz nginx-1.18.0.tar.gz
[root@server1 ~]# cd mysql-5.7.31/
[root@server1 mysql-5.7.31]# ls
boost configure.cmake libbinlogevents mysql-test regex support-files
BUILD dbug libbinlogstandalone mysys scripts testclients
client Docs libmysql mysys_ssl source_downloads unittest
cmake Doxyfile-perfschema libmysqld packaging sql VERSION
CMakeLists.txt extra libservices plugin sql-common vio
cmd-line-utils include LICENSE rapid storage win
config.h.cmake INSTALL man README strings zlib
- 原始碼編譯
在解壓之后生成的目錄中可以看到,mysql 與 nginx 不同,沒有configure;因為MySQL屬于Oracle公司的產品,使用的是cmake;
編譯時,一定要在原始碼目錄的頂級路徑里面,
[root@server1 mysql-5.7.31]# cd boost/
[root@server1 boost]# ls
boost_1_59_0
[root@server1 boost]# cd boost_1_59_0/
[root@server1 boost_1_59_0]# ls
boost
[root@server1 boost_1_59_0]# pwd
/root/mysql-5.7.31/boost/boost_1_59_0 ##boost 路徑
[root@server1 mysql-5.7.31]# yum install cmake -y
## 由于mysql 安裝需要用到 cmake 所以要先下載
[root@server1 mysql-5.7.31]# cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ ##安裝目錄
-DMYSQL_DATADIR=/usr/local/mysql/data \ ##資料庫存放目錄
-DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysql.sock \##Unix socket 檔案路徑
-DWITH_INNOBASE_STORAGE_ENGINE=1 \ ##安裝 innodb 存盤引擎
-DDEFAULT_CHARSET=utf8 \ ##使用 utf8 字符
-DDEFAULT_COLLATION=utf8_general_ci \ ##校驗字符
-DEXTRA_CHARSETS=all \ ##安裝所有擴展字符集
-DWITH_BOOST=/root/mysql-5.7.31/boost/boost_1_59_0 ##制定 boost 路徑
開始編譯

輸入命令 cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysql.sock -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_BOOST=/root/mysql-5.7.31/boost/boost_1_59_0開始編譯,在編譯的程序中會出現一些依賴性需要解決,依次安裝需要的包即可;
第一次出現的問題:

根據錯誤, yum install ncurses-devel -y安裝ncurses-devel庫;
然后再次編譯: cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysql.sock -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_BOOST=/root/mysql-5.7.31/boost/boost_1_59_0

根據提示洗掉快取:rm -fr CMakeCache.txt;
然后再次編譯: cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysql.sock -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_BOOST=/root/mysql-5.7.31/boost/boost_1_59_0
第二次出現問題:

根據錯誤, yum install gcc-c++ -y;
安裝完成之后根據提示洗掉快取:rm -fr CMakeCache.txt;
然后再次編譯: cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysql.sock -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_BOOST=/root/mysql-5.7.31/boost/boost_1_59_0
第三次出現問題:

根據錯誤, yum install bison -y;
安裝完成之后根據提示洗掉快取:rm -fr CMakeCache.txt;
然后再次編譯: cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysql.sock -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_BOOST=/root/mysql-5.7.31/boost/boost_1_59_0
直至編輯不再報錯:

make :此程序時間的長短會根據 cpu 的能力,往往都需要較長的時間

當出現如圖所示的提示時,說明 make 成功;

然后執行 make install 向向/usr/local/mysql中連續寫入資料即可編譯完成,當編譯完成之后便會生成/usr/local/mysql這個目錄,
cmake在編譯的程序中有顏色,有進度,
- mysql 啟動腳本和環境變數設定
生成啟動腳本
[root@server1 mysql-5.7.31]# cd /usr/local/mysql/
[root@server1 mysql]# du -sh
1.9G .
[root@server1 mysql]# ls
bin docs include lib LICENSE man mysql-test README README-test share support-files
[root@server1 mysql]# cd support-files/
[root@server1 support-files]# ls
magic mysqld_multi.server mysql-log-rotate mysql.server
[root@server1 support-files]# cp mysql.server /etc/init.d/mysql ##復制腳本到啟動目錄
[root@server1 support-files]# ll /etc/init.d/mysqld ##腳本一定要有可執行的權限
-rwxr-xr-x 1 root root 10576 Apr 17 23:14 /etc/init.d/mysqld
[root@server1 mysql-5.7.31]# cd mysql-test/
[root@server1 mysql-test]# ls
asan.supp CTestTestfile.cmake Makefile mysql-test-run.pl std_data
CMakeFiles extra mtr r suite
cmake_install.cmake include mtr.out-of-source README t
CMakeLists.txt lib mysql-stress-test.pl README.gcov valgrind.supp
collections lsan.supp mysql-test-run README.stress
[root@server1 mysql-test]# vim /etc/my.cnf
[root@server1 mysql-test]# cat /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/data ##資料目錄
socket=/usr/local/mysql/data/mysql.sock ##編譯的路經
symbolic-links=0
添加環境變數
[root@server1 bin]# pwd
/usr/local/mysql/bin ##MySQL的指令都在/usr/local/mysql/bin目錄里
[root@server1 bin]# ls
innochecksum mysqlcheck mysql_embedded mysqltest_embedded
lz4_decompress mysql_client_test mysqlimport mysql_tzinfo_to_sql
myisamchk mysql_client_test_embedded mysql_install_db mysql_upgrade
myisam_ftdump mysql_config mysql_plugin mysqlxtest
myisamlog mysql_config_editor mysqlpump perror
myisampack mysqld mysql_secure_installation replace
my_print_defaults mysqld_multi mysqlshow resolveip
mysql mysqld_safe mysqlslap resolve_stack_dump
mysqladmin mysqldump mysql_ssl_rsa_setup zlib_decompress
mysqlbinlog mysqldumpslow mysqltest
配置環境變數如圖所示:

- mysql 初始化
在/usr/local/mysql下沒有資料目錄,需要做一個初始化;

[root@server1 ~]# mysqld --verbose --help |less ##查看幫助
[root@server1 ~]# useradd -u 1000 -M -d /usr/local/mysql/data -s /sbin/nologin mysql
##創建用戶,原始碼不會像rpm包會自動創建相應的用戶,需要我們自己創建
##不創建家目錄,制定資料目錄為 /usr/local/mysql/data
[root@server1 mysql]# mysqld --verbose --help |less
[root@server1 mysql]# mysqld --initialize --user=mysql ##生成資料庫密碼,自動讀取/etc/my.cnf,生成臨時密碼,初始化密碼只允許登陸,
初始化

更改資料庫密碼
[root@server1 mysql]# /etc/init.d/mysqld start ##開啟資料庫,資料庫在開啟之后就不要重復開啟,以免 socket 沖突
Starting MySQL.Logging to '/usr/local/mysql/data/server1.err'.
SUCCESS!
[root@server1 mysql]# netstat -antlp | grep :3306 ##查看資料庫開啟之后的埠3306
tcp6 0 0 :::3306 :::* LISTEN 11280/mysqld
輸入 mysql_secure_installatin修改資料庫密碼;


注:改密碼,不要檢查密碼的強壯度,否則校驗過不去,
在修改密碼之后,用更改的密碼成功登陸資料庫,至此資料庫編譯結束,

3. php 部署
在 php 官網 https://www.php.net 下載所需要的原始碼包,此處我們下載的為 php-7.4.12.tar.bz2版本;

- 解壓
[root@server1 ~]# yum search bzip ##由于 php 包為 bz2 的壓縮格式,需要下載 bzip 的解壓工具
[root@server1 ~]# ls
mysql-5.7.31 nginx-1.18.0.tar.gz
mysql-boost-5.7.31.tar.gz php-7.4.12.tar.bz2
nginx-1.18.0
[root@server1 ~]# tar jxf php-7.4.12.tar.bz2 ##解壓
[root@server1 ~]# ls
mysql-5.7.31 nginx-1.18.0.tar.gz
mysql-boost-5.7.31.tar.gz php-7.4.12
nginx-1.18.0 php-7.4.12.tar.bz2
- 原始碼編譯
1)創建用戶
此處安裝的 php 是為了和前面安裝的 nginx 構成 lnmp 架構,所以應該和 nginx 的用戶保持一致;
由于前面沒有為 nginx 創建用戶,需要在此處創建用戶;

創建一個名為 nginx 的用戶,PHP和nginx都使用這個用戶;
修改mysql的用戶和用戶組
[root@server1 php-7.4.12]# nginx ##開啟 nginx
[root@server1 php-7.4.12]# useradd -M -d /usr/local/nginx/ -s /sbin/nologin nginx ##不指定用戶的家目錄,資料目錄為/usr/local/nginx/
[root@server1 php-7.4.12]# id nginx
uid=1001(nginx) gid=1001(nginx) groups=1001(nginx)
[root@server1 nginx]# cd /usr/local/nginx/conf/
[root@server1 conf]# ls
fastcgi.conf koi-utf nginx.conf uwsgi_params
fastcgi.conf.default koi-win nginx.conf.default uwsgi_params.default
fastcgi_params mime.types scgi_params win-utf
fastcgi_params.default mime.types.default scgi_params.default
[root@server1 conf]# vim nginx.conf
[root@server1 conf]# head -n 5 nginx.conf
user nginx nginx; ##編輯檔案內容,將用戶和組都更改為 nginx;
worker_processes 1;
#error_log logs/error.log;
[root@server1 conf]# nginx -s reload ##重新加載 nginx
[root@server1 conf]# ps aux
nginx 3833 0.0 0.0 46420 2024 ? S 21:14 0:00 nginx: worker process
root 3842 0.0 0.0 155360 1880 pts/1 R+ 21:15 0:00 ps aux
- 編譯
在 /php-7.4.12 里存在configure,屬于gmake;可以用 ./configure - -help 查看其引數幫助;
[root@server1 php-7.4.12]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc
--enable-mysqlnd ##驅動
--with-pdo-mysql --with-mysqli
--with-openssl-dir ##加密
--enable-gd ##開啟圖形
--with-zlib-dir ##壓縮
--with-curl ##支持curl 命令
--with-pear ##php 重要擴展
--enable-inline-optimization ##優化選項
--enable-soap ##動態編譯支持
--enable-sockets ##socket 支持
--enable-mbstring
--enable-fpm ##fpm 觀念器
--with-fpm-user=nginx ##用戶身份,用什么身份運行,盡量和nginx 一致
--with-fpm-group=nginx ##用戶組身份
--with-fpm-systemd
開始編譯
在 /php-7.4.12目錄中執行 ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-mysqlnd --with-pdo-mysql --with-mysqli --with-openssl-dir --enable-gd --with-zlib-dir --with-curl --with-pear --enable-inline-optimization --enable-soap --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-fpm-systemd,會遇到一些依賴性需要解決;

第一個問題:需要libsystemd的版本高于209;
根據錯誤,yum install systemd-devel.x86_64 -y安裝 systemd-devel 安裝包;
安裝完成之后再次執行 ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-mysqlnd --with-pdo-mysql --with-mysqli --with-openssl-dir --enable-gd --with-zlib-dir --with-curl --with-pear --enable-inline-optimization --enable-soap --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-fpm-systemd繼續編譯;
第二個問題:

根據錯誤,yum install libxml2-devel -y
安裝 systemd-devel 安裝包;
安裝完成之后再次執行 ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-mysqlnd --with-pdo-mysql --with-mysqli --with-openssl-dir --enable-gd --with-zlib-dir --with-curl --with-pear --enable-inline-optimization --enable-soap --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-fpm-systemd繼續編譯;
第三個問題:

根據錯誤,yum install sqlite-devel.x86_64 -y
安裝 systemd-devel 安裝包;
安裝完成之后再次執行 ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-mysqlnd --with-pdo-mysql --with-mysqli --with-openssl-dir --enable-gd --with-zlib-dir --with-curl --with-pear --enable-inline-optimization --enable-soap --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-fpm-systemd繼續編譯;
第四個問題:

根據錯誤,yum install libcurl-devel.x86_64 -y
安裝 systemd-devel 安裝包;
安裝完成之后再次執行 ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-mysqlnd --with-pdo-mysql --with-mysqli --with-openssl-dir --enable-gd --with-zlib-dir --with-curl --with-pear --enable-inline-optimization --enable-soap --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-fpm-systemd繼續編譯;
第五個問題:

根據錯誤,yum install libpng-devel.x86_64 -y
安裝 systemd-devel 安裝包;
安裝完成之后再次執行 ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-mysqlnd --with-pdo-mysql --with-mysqli --with-openssl-dir --enable-gd --with-zlib-dir --with-curl --with-pear --enable-inline-optimization --enable-soap --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-fpm-systemd繼續編譯;
第六個問題:此處的依賴性的解決 Redhat 本身沒有可以支持的安裝包,需要去網上下載下來然后再安裝;
根據錯誤,yum install oniguruma-6.8.2-1.el7.x86_64.rpm oniguruma-devel-6.8.2-1.el7.x86_64.rpm -y
安裝 systemd-devel 安裝包;
安裝完成之后再次執行 ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-mysqlnd --with-pdo-mysql --with-mysqli --with-openssl-dir --enable-gd --with-zlib-dir --with-curl --with-pear --enable-inline-optimization --enable-soap --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-fpm-systemd繼續編譯;
當沒有錯誤時,編譯完成之后的效果如圖所示:

make
make 完成之后的效果如圖所示:

make install

- 通過腳本多載 php
在編譯時,configure 后加了systemd,默認會生成 systemctl 的啟動后臺,但是默認的位置并不是想要的需要更改;
在 php 的原始碼中將啟動 systemd 的腳本/php-7.4.12/sapi/fpm/init.d.php-fpm 拷貝到 /etc/init.d /下,給定執行權限;
這種啟動方式是在 systemd 以前,最常用的;
[root@server1 fpm]# pwd
/root/php-7.4.12/sapi/fpm
[root@server1 fpm]# ls
config.m4 init.d.php-fpm Makefile.frag php-fpm.8.in php-fpm.service status.html.in www.conf.in
CREDITS init.d.php-fpm.in php-fpm php-fpm.conf php-fpm.service.in tests
fpm LICENSE php-fpm.8 php-fpm.conf.in status.html www.conf
[root@server1 fpm]# cp init.d.php-fpm /etc/init.d/php-fpm ##復制啟動腳本到對應的位置
[root@server1 fpm]# chmod +x /etc/init.d/php-fpm ##給腳本執行的權限
[root@server1 fpm]# /etc/init.d/php-fpm ##直接呼叫該腳本,系統會列印相應的幫助
Usage: /etc/init.d/php-fpm {start|stop|force-quit|restart|reload|status|configtest}
補充:
cgi 和 fcgi 區別:
php 無法平滑加載
cgi 的更改修改每次重啟 apache 才可以生效,沒有后臺;
fcgi 可以平滑加載有后臺;呼叫腳本 reload 就可以了,
- 組態檔
在安裝路徑中的 php-fpm.conf.default 是 php 控制器的組態檔模板;
復制成組態檔;
組態檔中全部都是注釋的內容,注釋后面是否有默認值,該有的不能為空,
[root@server1 etc]# pwd
/usr/local/php/etc
[root@server1 etc]# ls
pear.conf php-fpm.conf.default php-fpm.d
[root@server1 etc]# cp php-fpm.conf.default php-fpm.conf ##生成組態檔
[root@server1 etc]# vim php-fpm.conf
13 [global]
14 ; Pid file
15 ; Note: the default prefix is /usr/local/php/var
16 ; Default Value: none ##默認值為空就需要更改
17 pid = run/php-fpm.pid #修改組態檔中PID的位置

在 /root/php-7.4.12/etc/php-fpm.d/ 目錄下有 www.conf.default ;將其復制成 www.conf 組態檔;
[root@server1 php-fpm.d]# ls
www.conf.default
[root@server1 php-fpm.d]# cp www.conf.default www.conf
23 user = nginx ##用戶身份正常,說明編譯成功
24 group = nginx
---
36 listen = 127.0.0.1:9000 ##默認監聽的是本機127.0.0.1:9000埠;需要遠程連接就需要打開該埠
---
---
114 pm.max_children = 5 ##默認開啟的服務數量最大是 5
115
116 ; The number of child processes created on startup.
117 ; Note: Used only when pm is set to 'dynamic'
118 ; Default Value: (min_spare_servers + max_spare_servers) / 2
119 pm.start_servers = 2 ##默認開啟2個,;此值的修改根據自己的生產環境設定,此處的實驗不做更改
120
121 ; The desired minimum number of idle server processes.
122 ; Note: Used only when pm is set to 'dynamic'
123 ; Note: Mandatory when pm is set to 'dynamic'
124 pm.min_spare_servers = 1 ##默認最小空閑1個
如下圖所示;
- 啟動 php
php.ini-productionPHP的生產檔案
PHP組態檔的命名方式一定是php.ini
[root@server1 ~]# cd php-7.4.12
[root@server1 php-7.4.12]# ls
appveyor config.log ext Makefile php.ini-production travis
azure config.nice EXTENSIONS Makefile.fragments README.md TSRM
azure-pipelines.yml config.status include Makefile.objects README.REDIST.BINS UPGRADING
build configure libs modules run-tests.php UPGRADING.INTERNALS
buildconf configure.ac libtool NEWS sapi win32
buildconf.bat CONTRIBUTING.md LICENSE pear scripts Zend
CODING_STANDARDS.md docs main php.ini-development tests
[root@server1 php-7.4.12]# cp php.ini-production /usr/local/php/etc/php.ini ##生成php組態檔,組態檔一定是 php.ini 命名方式
[root@server1 php-7.4.12]# /etc/init.d/php-fpm start ##開啟 php
Starting php-fpm done
開啟之后過濾,查看埠資訊:

可以用 ps aux查看行程狀態資訊,php 的用戶為 nginx,

轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/278058.html
標籤:其他
