Nginx+PHP+MySQL安裝參考

Nginx+PHP+MySQL安裝參考


CentOS7環境
配置CentOS7網絡:

CentOS(最小安裝)默認是不打開網絡的

啟動網絡
vi打開:/etc/sysconfig/network-scripts/ifcfg-ens33 文件
將 “ONBOOT:no”屬性修改為:“ONBOOT:yes”

重啟網絡服務
# sudo service network restart?

查看IP
# ip addr


Nginx服務:
安裝依賴包

? ? 安裝:
? ? # yum -y install build-essential
? ??
? ? 安裝:更多依賴包
? ? # yum -y install gcc automake autoconf libtool make

? ? 安裝:g++
? ? # yum -y install gcc gcc-c++

安裝PCRE庫
選定源碼目錄 ==> ftp下載PCRE庫 ==> 安裝PCRE庫
# cd /usr/local/src
# wget ftp://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz
# tar -zxvf pcre-8.42.tar.gz
# cd ./pcre-8.42
# ./configure
# make && make install

安裝zlib源碼包
下載zlib源碼包 ==> 安裝zlib包
# cd /usr/local/src
# wget http://zlib.net/zlib-1.2.11.tar.gz
# tar -zxvf zlib-1.2.11.tar.gz
# cd zlib-1.2.11
# ./configure
# make && make install

安裝openssl源碼包
# cd /usr/local/src
# wget https://www.openssl.org/source/openssl-1.1.0k.tar.gz
# tar -zxvf openssl-1.1.0k.tar.gz
# cd ./openssl-1.1.0k
# mkdir /usr/local/openssl
# ./configure --prefix=/usr/local/openssl
# make && make install

安裝Nginx
# cd /usr/local/src
# wget http://nginx.org/download/nginx-1.16.1.tar.gz
# tar -zxvf nginx-1.16.1.tar.gz
# cd nginx-1.16.1
# groupadd -r nginx
# useradd -s /bin/false -M nginx -g nginx

# ./configure \
--prefix=/usr/local/nginx \
--sbin-path=/usr/local/nginx/sbin/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--pid-path=/usr/local/nginx/logs/nginx.pid \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_mp4_module? \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/tmp/nginx/client/ \
--http-proxy-temp-path=/var/tmp/nginx/proxy/ \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--http-scgi-temp-path=/var/tmp/nginx/scgi \
--with-pcre=/usr/local/src/pcre-8.42 \
--with-zlib=/usr/local/src/zlib-1.2.11 \
--with-openssl=/usr/local/src/openssl-1.1.0k \
# make
執行make 進行編譯,如果編譯成功的話會在objs中出現一個nginx文件
特別注意:
在已安裝的nginx上進行添加模塊的話執行到這里就行了,把objs中的nginx替換掉之前的安裝的nginx/sbin/中的nginx文件,
然后重啟nginx就行了,如果執行下一步的install,會導致之前安裝的nginx被覆蓋,比如之前配置好的nginx.conf文件

# make install

參數說明:
--prefix 用于指定nginx編譯后的安裝目錄
--add-module 為添加的第三方模塊,如添加fdfs的nginx模塊,則--add-module=/home/fastdfs-nginx-module/src
--with..._module 表示啟用的nginx模塊,如此處啟用了http_ssl_module模塊

可能出現的錯誤:
出現:./configure:? error: the HTTP rewrite module requires the PCRE library.
解決方法:yum -y install pcre-devel

出現:SSL modules require the OpenSSL library
解決方法:yum install openssl-devel?

或是下載源碼,指定對應路徑,如:
--with-pcre=/usr/local/src/pcre-8.41 指的是pcre-8.42 的源碼路徑
--with-zlib=/usr/local/src/zlib-1.2.11 指的是zlib-1.2.11 的源碼路徑
--with-openssl=/usr/local/src/openssl-1.1.0g 指的是openssl-1.1.0k 的源碼路徑

nginx編譯選項
make是用來編譯的,它從Makefile中讀取指令,然后編譯。
make install是用來安裝的,它也從Makefile中讀取指令,安裝到指定的位置。
configure命令是用來檢測你的安裝平臺的目標特征的。它定義了系統的各個方面,包括nginx的被允許使用的連接處理的方法,比如它會檢測你是不是有CC或GCC,
并不是需要CC或GCC,它是個shell腳本,執行結束時,它會創建一個Makefile文件。nginx的configure命令支持以下參數:
? ? --prefix=*path* 定義一個目錄,存放服務器上的文件 ,也就是nginx的安裝目錄。默認使用 /usr/local/nginx。
? ? --sbin-path=*path* 設置nginx的可執行文件的路徑,默認為 *prefix*/sbin/nginx.
? ? --conf-path=*path* 設置在nginx.conf配置文件的路徑。nginx允許使用不同的配置文件啟動,通過命令行中的-c選項。默認為*prefix*/conf/nginx.conf.
? ? --pid-path=*path* 設置nginx.pid文件,將存儲的主進程的進程號。安裝完成后,可以隨時改變的文件名 , 在nginx.conf配置文件中使用 PID指令。默認情況下,文件名 為``*prefix*/logs/nginx.pid.
? ? --error-log-path=*path* 設置主錯誤,警告,和診斷文件的名稱。安裝完成后,可以隨時改變的文件名 ,在nginx.conf配置文件中 使用 的error_log指令。默認情況下,文件名 為*prefix*/logs/error.log.
? ? --http-log-path=*path* 設置主請求的HTTP服務器的日志文件的名稱。安裝完成后,可以隨時改變的文件名 ,在nginx.conf配置文件中 使用 的access_log指令。默認情況下,文件名 為*prefix*/logs/access.log.
? ? --user=*name* 設置nginx工作進程的用戶。安裝完成后,可以隨時更改的名稱在nginx.conf配置文件中 使用的 user指令。默認的用戶名是nobody。
? ? --group=*name* 設置nginx工作進程的用戶組。安裝完成后,可以隨時更改的名稱在nginx.conf配置文件中 使用的 user指令。默認的為非特權用戶。
? ? --with-select_module --without-select_module 啟用或禁用構建一個模塊來允許服務器使用select()方法。該模塊將自動建立,如果平臺不支持的kqueue,epoll,rtsig或/dev/poll。
? ? --with-poll_module --without-poll_module 啟用或禁用構建一個模塊來允許服務器使用poll()方法。該模塊將自動建立,如果平臺不支持的kqueue,epoll,rtsig或/dev/poll。
? ? --without-http_gzip_module — 不編譯壓縮的HTTP服務器的響應模塊。編譯并運行此模塊需要zlib庫。
? ? --without-http_rewrite_module 不編譯重寫模塊。編譯并運行此模塊需要PCRE庫支持。
? ? --without-http_proxy_module — 不編譯http_proxy模塊。
? ? --with-http_ssl_module — 使用https協議模塊。默認情況下,該模塊沒有被構建。建立并運行此模塊的OpenSSL庫是必需的。
? ? --with-pcre=*path* — 設置PCRE庫的源碼路徑。PCRE庫的源碼(版本4.4 - 8.30)需要從PCRE網站下載并解壓。其余的工作是Nginx的./ configure和make來完成。正則表達式使用在location指令和 ngx_http_rewrite_module 模塊中。
? ? --with-pcre-jit —編譯PCRE包含“just-in-time compilation”(1.1.12中, pcre_jit指令)。
? ? --with-zlib=*path* —設置的zlib庫的源碼路徑。要下載從 zlib(版本1.1.3 - 1.2.5)的并解壓。其余的工作是Nginx的./ configure和make完成。ngx_http_gzip_module模塊需要使用zlib 。
? ? --with-cc-opt=*parameters* — 設置額外的參數將被添加到CFLAGS變量。例如,當你在FreeBSD上使用PCRE庫時需要使用:--with-cc-opt="-I /usr/local/include。.如需要需要增加 select()支持的文件數量:--with-cc-opt="-D FD_SETSIZE=2048".
? ? --with-ld-opt=*parameters* —設置附加的參數,將用于在鏈接期間。例如,當在FreeBSD下使用該系統的PCRE庫,應指定:--with-ld-opt="-L /usr/local/lib".

安裝完成后,按照安裝的參數,安裝的啟動目錄在/usr/local/nginx

[root@localhost nginx]# ls -l
總用量 76
drwxr-xr-x. 2 root root 4096 9月? ?8 09:46 conf
-rw-r--r--. 1 root root 1077 9月? ?8 10:34 fastcgi.conf
-rw-r--r--. 1 root root 1077 9月? ?8 10:34 fastcgi.conf.default
-rw-r--r--. 1 root root 1007 9月? ?8 10:34 fastcgi_params
-rw-r--r--. 1 root root 1007 9月? ?8 10:34 fastcgi_params.default
drwxr-xr-x. 2 root root? ?40 9月? ?8 09:46 html
-rw-r--r--. 1 root root 2837 9月? ?8 10:34 koi-utf
-rw-r--r--. 1 root root 2223 9月? ?8 10:34 koi-win
drwxr-xr-x. 2 root root? ?41 9月? ?8 10:37 logs
-rw-r--r--. 1 root root 5231 9月? ?8 10:34 mime.types
-rw-r--r--. 1 root root 5231 9月? ?8 10:34 mime.types.default
-rw-r--r--. 1 root root 2656 9月? ?8 10:34 nginx.conf
-rw-r--r--. 1 root root 2656 9月? ?8 10:34 nginx.conf.default
-rw-r--r--. 1 root root? ? 6 9月? ?8 10:37 nginx.pid
drwxr-xr-x. 2 root root? ?36 9月? ?8 10:34 sbin
-rw-r--r--. 1 root root? 636 9月? ?8 10:34 scgi_params
-rw-r--r--. 1 root root? 636 9月? ?8 10:34 scgi_params.default
-rw-r--r--. 1 root root? 664 9月? ?8 10:34 uwsgi_params
-rw-r--r--. 1 root root? 664 9月? ?8 10:34 uwsgi_params.default
-rw-r--r--. 1 root root 3610 9月? ?8 10:34 win-utf
[root@localhost nginx]# pwd
/usr/local/nginx


啟動Nginx服務:

由于CentOS-7防火墻不開發端口,所以在本地測試中,可以選擇關閉防火墻或者允許開發80端口
CentOS防火墻

# systemctl status firewalld? ? ?==> 防火墻狀態
# systemctl start firewalld? ? ? ?==> 開啟防火墻
# systemctl stop firewalld? ? ? ? ==> 關閉防火墻
# systemctl restart firewalld? ? ?==> 重啟防火墻
# firewall-cmd --reload? ? ? ? ? ==> 防火墻重載
# firewall-cmd --permanent --zone=public --add-port=80/tcp
? ? permanent: 永久有效
? ? zone:作用域
? ? --add-port=80/tcp:添加-端口=端口/通信協議

開放端口或關閉防火墻后就可以啟動nginx服務
服務啟動

[root@localhost nginx]# netstat -ano | grep 80
tcp? ? ? ? 0? ? ? 0 0.0.0.0:80? ? ? ? ? ? ? 0.0.0.0:*? ? ? ? ? ? ? ?LISTEN? ? ? off (0.00/0/0)
unix? 3? ? ? [ ]? ? ? ? ?STREAM? ? ?CONNECTED? ? ?80900? ??
unix? 3? ? ? [ ]? ? ? ? ?STREAM? ? ?CONNECTED? ? ?80899? ??
[root@localhost nginx]# /usr/local/nginx/sbin/nginx
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()

通過netstat查看端口網絡狀態,是否有服務占用80端口;通過調用nginx的啟動目錄實現nginx服務啟動

Nginx服務維護
為了避免每次開機手動啟動,可以使用命令腳本,注冊服務,開機自啟動等

創建nginx啟動命令腳本
#vi /etc/init.d/nginx
插入以下內容, 注意修改PATH和NAME字段, 匹配自己的安裝路徑 (這段是從網上copy的)
#! /bin/sh
# chkconfig: 2345 55 25
# Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and
# run 'update-rc.d -f nginx defaults', or use the appropriate command on your
# distro. For CentOS/Redhat run: 'chkconfig --add nginx'

### BEGIN INIT INFO
# Provides:? ? ? ? ? nginx
# Required-Start:? ? $all
# Required-Stop:? ? ?$all
# Default-Start:? ? ?2 3 4 5
# Default-Stop:? ? ? 0 1 6
# Short-Description: starts the nginx web server
# Description:? ? ? ?starts nginx using start-stop-daemon
### END INIT INFO

# Author:? ?licess
# website:? http://lnmp.org

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=nginx
NGINX_BIN=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/$NAME.conf
PIDFILE=/usr/local/nginx/logs/$NAME.pid

case "$1" in
? ? start)
? ? ? ? echo -n "Starting $NAME... "

? ? ? ? if netstat -tnpl | grep -q nginx;then
? ? ? ? ? ? echo "$NAME (pid `pidof $NAME`) already running."
? ? ? ? ? ? exit 1
? ? ? ? fi

? ? ? ? $NGINX_BIN -c $CONFIGFILE

? ? ? ? if [ "$?" != 0 ] ; then
? ? ? ? ? ? echo " failed"
? ? ? ? ? ? exit 1
? ? ? ? else
? ? ? ? ? ? echo " done"
? ? ? ? fi
? ? ? ? ;;

? ? stop)
? ? ? ? echo -n "Stoping $NAME... "

? ? ? ? if ! netstat -tnpl | grep -q nginx; then
? ? ? ? ? ? echo "$NAME is not running."
? ? ? ? ? ? exit 1
? ? ? ? fi

? ? ? ? $NGINX_BIN -s stop

? ? ? ? if [ "$?" != 0 ] ; then
? ? ? ? ? ? echo " failed. Use force-quit"
? ? ? ? ? ? exit 1
? ? ? ? else
? ? ? ? ? ? echo " done"
? ? ? ? fi
? ? ? ? ;;

? ? status)
? ? ? ? if netstat -tnpl | grep -q nginx; then
? ? ? ? ? ? PID=`pidof nginx`
? ? ? ? ? ? echo "$NAME (pid $PID) is running..."
? ? ? ? else
? ? ? ? ? ? echo "$NAME is stopped"
? ? ? ? ? ? exit 0
? ? ? ? fi
? ? ? ? ;;

? ? force-quit)
? ? ? ? echo -n "Terminating $NAME... "

? ? ? ? if ! netstat -tnpl | grep -q nginx; then
? ? ? ? ? ? echo "$NAME is not running."
? ? ? ? ? ? exit 1
? ? ? ? fi

? ? ? ? kill `pidof $NAME`

? ? ? ? if [ "$?" != 0 ] ; then
? ? ? ? ? ? echo " failed"
? ? ? ? ? ? exit 1
? ? ? ? else
? ? ? ? ? ? echo " done"
? ? ? ? fi
? ? ? ? ;;

? ? restart)
? ? ? ? $0 stop
? ? ? ? sleep 1
? ? ? ? $0 start
? ? ? ? ;;

? ? reload)
? ? ? ? echo -n "Reload service $NAME... "

? ? ? ? if netstat -tnpl | grep -q nginx; then
? ? ? ? ? ? $NGINX_BIN -s reload
? ? ? ? ? ? echo " done"
? ? ? ? else
? ? ? ? ? ? echo "$NAME is not running, can't reload."
? ? ? ? ? ? exit 1
? ? ? ? fi
? ? ? ? ;;

? ? configtest)
? ? ? ? echo -n "Test $NAME configure files... "

? ? ? ? $NGINX_BIN -t
? ? ? ? ;;

? ? *)
? ? ? ? echo "Usage: $0 {start|stop|force-quit|restart|reload|status|configtest}"
? ? ? ? exit 1
? ? ? ? ;;

esac

設置執行權限
chmod a+x /etc/init.d/nginx
注冊成服務
chkconfig --add nginx
設置開機啟動
chkconfig nginx on

重啟
shutdown -h 0 -r

查看nginx服務是否自動啟動
ss -apn|grep nginx

對nginx服務執行停止/啟動/重新讀取配置文件操作
#啟動nginx服務
systemctl start nginx.service
#停止nginx服務
systemctl stop nginx.service
#重啟nginx服務
systemctl restart nginx.service
#重新讀取nginx配置(這個最常用, 不用停止nginx服務就能使修改的配置生效)
systemctl reload nginx.service

如出現:nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid"
則需通過nginx –c ../conf/nginx.conf? ? 命令指定nginx的配置

關于nginx.conf配置文件
在安裝完nginx后會在conf目錄中產生一個nginx.conf的配置文件
里面有些默認配置,可根據自己的需求進行更改
示例:
#user? nobody;
worker_processes? 1;
events {
? ? ?use epoll;
? ? ? ? worker_connections? 51200;
}

http {
? ? include? ? ? ?mime.types;
? ? default_type? application/octet-stream;
? ? sendfile? ? ? ? on;
? ? keepalive_timeout? 65;
? ? proxy_connect_timeout 600s;
? ? proxy_read_timeout 600s;
? ? proxy_send_timeout 600s;
? ? proxy_buffer_size 64k;
? ? proxy_buffers 4 32k;
? ? proxy_busy_buffers_size 64k;
? ? proxy_temp_file_write_size 64k;
? ? proxy_ignore_client_abort on;
? ? client_max_body_size 200m;? #此參數在使用fdfs上傳可控制上傳文件的大小
#日志的輸出格式,如需打印請求的body參數信息,可在$body_bytes_sent后添加 $request_body?
log_format? main? '$remote_addr - $remote_user [$time_local] "$request" '
? ? ? ? ? ? ? ? ?'$status $body_bytes_sent "$http_referer" '
? ? ? ? ? ? ? ? '"$http_user_agent" "$http_x_forwarded_for"';
?
access_log? logs/access.log? main; #設置日志輸出的位置
access_log on;? #是否開啟日志,開啟on,關閉off
#負載均衡配置
upstream test.com {
ip_hash;
server 192.168.68.9:8080;
server 192.168.68.72:8080;
}
? ? server {
? ? ? ? listen? ? ? ?80; #監聽的端口,http默認監聽端口為80
? ? ? ? server_name? localhost; #監聽的主機名
? ? ? ? location / {
#設置請求的頭部中主機名為請求的主機名,而不是代理的nginx的主機名
? ? ? proxy_set_header Host $host:$server_port;
#代理的目標地址,如果要進行負載均衡,目標地址可添test.com
? ? ? ? ?proxy_pass http://192.168.68.9:8080;
? ? ? ? }
? ? ? ? error_page? ?500 502 503 504? /50x.html;
? ? ? ? location = /50x.html {
? ? ? ? ? ? root? ?html;
? ? ? ? }
? ? }
#https配置,https默認監聽端口為443
? ? server {
? ? ? ? listen? 443;
? ? ? ? server_name system.test.com;
? ? ? ? ssl on;
? ? ? ? ssl_certificate_key cert/system.key; #ssl key文件的位置,此處使用配置文件的相對路徑
? ? ? ? ssl_certificate cert/system.pem; #證書文件,此處為阿里云云盾證書生成的.pem也可修改擴展名為熟悉的.crt
? ? ? ? ssl_session_timeout 5m;
? ? ? ? ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
? ? ? ? ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
? ? ? ? ssl_prefer_server_ciphers on;
? ? ? ? location / {
? ? ? ? ? ? ?proxy_pass http://192.168.68.9:8080;
? ? ? ? }
? ? }
? ? #以下為我的fdfs文件配置,沒有使用fdfs可以不用配置
? ? server {
? ? ? ? listen? ? ? ?9300;? ? ? ??
? ? ? ? server_name? localhost;? ?
? ? #location /group1/M01 {
? ? ? ? ?#? ?root? ?/home/fdfs/storage2/data;
? ? ? ? ? #? ngx_fastdfs_module;? ? ? ? ?
? ? ? ? #}
? ? ? ??
? ? ? ? location /group1/M00 {
? ? ? ? ? ?root? ?/home/fdfs/storage1/data;
? ? ? ? ? ?ngx_fastdfs_module;
? ? ? ? }
? ? ? ? error_page? ?500 502 503 504? /50x.html;
? ? ? ? location = /50x.html {
? ? ? ? ? ? root? ?html;
? ? ? ? }
? ? }
#include vhost/*.conf;
}

關于https配置ssl
如果在安裝nginx的時候沒有安裝 --with-http_ssl_module模塊要先安裝該模塊
nginx –V 可查看已經安裝的模塊
添加一個https的server大概如下面這個樣子
server {
? ? ? ? ?listen 443;? ?##默認的監聽端口為443
? ? ? ? ?server_name? localhost;
? ? ? ? ?ssl on;
? ? ? ? ?ssl_certificate_key? xxx.key; ##私鑰
? ? ? ? ?ssl_certificate? xxx.crt; ##證書,證書中包含公鑰和私鑰加密后的簽名信息
?
? ? ? ? location / {
? ? ? ? ? ? root? ?html;
? ? ? ? ? ? index? index.html index.htm;
? ? ? ? ? ? ?proxy_pass http://xxx.xxx.xxx.xxx:xxx;
? ? ? ? }
? ? ? ? ?
? ? }

--------------------------------MySQL安裝---------------------------

--------------------------------PHP環境安裝------------------------------
編譯安裝php-fpm
PHP-FPM是一個PHP FastCGI管理器,是只用于PHP的

安裝依賴包
# yum -y install libmcrypt-devel mhash-devel libxslt-devel \
libjpeg libjpeg-devel libpng libpng-dvevl freetype freetype-devel libxml2 libxml2-devel \
zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel \
ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel \
krb5 krb5-devel libidn libidn-devel openssl openssl-devel

源碼安裝PHP:
# cd /usr/local/src
# wget http://php.net/get/php-5.6.27.tar.gz/from/a/mirror
# tar -zxvf php-5.6.27.tar.gz?
# ./configure \
--prefix=/usr/local/php56 \
--with-config-file-path=/usr/local/php56/etc \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-opcache \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-gettext \
--enable-mbstring \
--with-iconv \
--with-mcrypt \
--with-mhash \
--with-openssl \
--enable-bcmath \
--enable-soap \
--with-libxml-dir \
--enable-pcntl \
--enable-shmop \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-sockets \
--with-curl \
--with-zlib \
--enable-zip \
--with-bz2 \
--with-readline \
--enable-gd-native-ttf \
--with-gd
#make
#make install
安裝的參數說明:
""" 安裝路徑 """
--prefix=/usr/local/php56 \

""" php.ini 配置文件路徑 """
--with-config-file-path=/usr/local/php56/etc \

""" 優化選項 """
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \

""" 啟用 opcache,默認為 ZendOptimizer+(ZendOpcache) """
--enable-opcache \

""" FPM """
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \

""" MySQL """
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \

""" 國際化與字符編碼支持 """
--with-gettext \
--enable-mbstring \
--with-iconv \

""" 加密擴展 """
--with-mcrypt \
--with-mhash \
--with-openssl \

""" 數學擴展 """
--enable-bcmath \

""" Web 服務,soap 依賴 libxml """
--enable-soap \
--with-libxml-dir \

""" 進程,信號及內存 """
--enable-pcntl \
--enable-shmop \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \

""" socket & curl """
--enable-sockets \
--with-curl \

""" 壓縮與歸檔 """
--with-zlib \
--enable-zip \
--with-bz2 \

""" GNU Readline 命令行快捷鍵綁定 """
--with-readline

""gd庫支持""
--enable-gd-native-ttf \
--with-gd

注:依賴包要同時安裝依賴包的本身,以及該依賴包的開發版,例如:zlib和zlib-devel。配置過程中可能會出現一些問題,
主要是依賴包沒有安裝開發板,或者安裝的依賴包版本過低導致的,更多編譯參數請使用 ./configure --help 查看。

執行configure時,發生報錯:
1. Please reinstall the libzip distribution?
刪除了舊版的libzip(“yum remove libzip”),之后下載libzip源碼包進行本地執行configure+make&&make install
libzip的安裝:
# cd /usr/local/src
# wget https://libzip.org/download/libzip-1.5.2.tar.gz
# tar -zxf libzip-1.2.0.tar.gz
# cd libzip-1.2.0
# ./configure
# make && make install

2. configure: error: mcrypt.h not found. Please reinstall libmcrypt
libmcrypt的安裝:
# cd /usr/local/src
# wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/attic/libmcrypt/libmcrypt-2.5.7.tar.gz
# tar -zxvf libmcrypt-2.5.7.tar.gz
# cd libmcrypt-2.5.7
# ./configure --prefix=/usr/local
# make && make install

3. Don't know how to define struct flock on this system, set --enable-opcache=no
查看--enble-opchahe的作用
#./configure --help|grep opcache--enable-opcache
Enable Zend OPcache support
可知這個是與 php 的加速模塊 zend相關的,不能省略

vim /etc/ld.so.conf.d/local.conf? ? ?# 編輯庫文件
/usr/local/lib
/usr/local/lib64
:wq? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # 保存退出
ldconfig -v? ? ? ? ? ? ? ? ? ? ? ? ? # 使之生效

4. Please reinstall readline - I cannot find readline.h
yum -y install readline-devel


至此!PHP-fpm安裝的基本流程結束了,下一步就需要配置文件
用戶配置文件

? ? 為php提供配置文件:php.ini

# cp php.ini-production /usr/local/php/lib/php.ini

? ? 為php-fpm提供配置文件

# cd /usr/local/php
# cp etc/php.fpm.conf.default etc/php-fpm.conf
# vi etc/php-fpm.conf

vi打開php-fpm.conf文件:

將文件的尾部的索引;修改成實際的目錄

include=/usr/local/php/etc/php-fpm.d/*.conf

根據參數--with-fpm-user=www,添加用戶和組:

useradd www
groupadd -g www www

默認情況下,etc/php-fpm.d/目錄下有一個“www .conf.defalut”用戶配置文件

# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
# vi /usr/local/php/etc/php-fpm.d/www.conf

修改“www.conf"文件中的user和group的value;添加用戶和組

user = www
group = www

? ? 啟動php-fpm服務

# /usr/local/php/sbin/php-fpm
# ps aux | grep php-fpm [驗證服務啟動]
# netstat -tln | grep 9000 [驗證網絡端口是否使用]

[root@localhost /]# ps aux | grep php-fpm
root? ? ? 41831? 0.0? 0.3 221264? 6220 ?? ? ? ? Ss? ?08:54? ?0:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
mirror? ? 41832? 0.0? 0.2 221264? 5748 ?? ? ? ? S? ? 08:54? ?0:00 php-fpm: pool www
mirror? ? 41833? 0.0? 0.2 221264? 5748 ?? ? ? ? S? ? 08:54? ?0:00 php-fpm: pool www
root? ? ? 41835? 0.0? 0.0 110292? ?916 pts/0? ? R+? ?08:54? ?0:00 grep --color=auto php-fpm
[root@localhost /]# netstat -tln | grep 9000
tcp? ? ? ? 0? ? ? 0 127.0.0.1:9000? ? ? ? ? 0.0.0.0:*? ? ? ? ? ? ? ?LISTEN? ?

至此!php-fpm服務啟動成功!
Nginx+PHP環境配置

? ? 打開nginx.conf(nginx配置文件)

[root@localhost nginx]# vi ./nginx.conf


#user? nobody;
worker_processes? 1;

#error_log? logs/error.log;
#error_log? logs/error.log? notice;
#error_log? logs/error.log? info;

#pid? ? ? ? logs/nginx.pid;


events {
? ? worker_connections? 1024;
}


http {
? ? include? ? ? ?mime.types;
? ? default_type? application/octet-stream;

? ? #log_format? main? '$remote_addr - $remote_user [$time_local] "$request" '
? ? #? ? ? ? ? ? ? ? ? '$status $body_bytes_sent "$http_referer" '
? ? #? ? ? ? ? ? ? ? ? '"$http_user_agent" "$http_x_forwarded_for"';

? ? #access_log? logs/access.log? main;

? ? sendfile? ? ? ? on;
? ? #tcp_nopush? ? ?on;

? ? #keepalive_timeout? 0;
? ? keepalive_timeout? 65;

? ? #gzip? on;

? ? server {
? ? ? ? listen? ? ? ?80;
? ? ? ? server_name? localhost;

? ? ? ? #charset koi8-r;

? ? ? ? #access_log? logs/host.access.log? main;

? ? ? ? location / {
? ? ? ? ? ? root? ?html;
? ? ? ? ? ? index? index.html index.htm;
? ? ? ? }

? ? ? ? #error_page? 404? ? ? ? ? ? ? /404.html;

? ? ? ? # redirect server error pages to the static page /50x.html
? ? ? ? #
? ? ? ? error_page? ?500 502 503 504? /50x.html;
? ? ? ? location = /50x.html {
? ? ? ? ? ? root? ?html;
? ? ? ? }

? ? ? ? # proxy the PHP scripts to Apache listening on 127.0.0.1:80
? ? ? ? #
? ? ? ? #location ~ \.php$ {
? ? ? ? #? ? proxy_pass? ?http://127.0.0.1;
? ? ? ? #}

? ? ? ? # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
? ? ? ? #
? ? ? ? #location ~ \.php$ {
? ? ? ? #? ? root? ? ? ? ? ?html;
? ? ? ? #? ? fastcgi_pass? ?127.0.0.1:9000;
? ? ? ? #? ? fastcgi_index? index.php;
? ? ? ? #? ? fastcgi_param? SCRIPT_FILENAME? /scripts$fastcgi_script_name;
? ? ? ? #? ? include? ? ? ? fastcgi_params;
? ? ? ? #}

? ? ? ? # deny access to .htaccess files, if Apache's document root
? ? ? ? # concurs with nginx's one
? ? ? ? #
? ? ? ? #location ~ /\.ht {
? ? ? ? #? ? deny? all;
? ? ? ? #}
? ? }


? ? # another virtual host using mix of IP-, name-, and port-based configuration
? ? #
? ? #server {
? ? #? ? listen? ? ? ?8000;
? ? #? ? listen? ? ? ?somename:8080;
? ? #? ? server_name? somename? alias? another.alias;

? ? #? ? location / {
? ? #? ? ? ? root? ?html;
? ? #? ? ? ? index? index.html index.htm;
? ? #? ? }
? ? #}


? ? # HTTPS server
? ? #
? ? #server {
? ? #? ? listen? ? ? ?443 ssl;
? ? #? ? server_name? localhost;

? ? #? ? ssl_certificate? ? ? cert.pem;
? ? #? ? ssl_certificate_key? cert.key;

? ? #? ? ssl_session_cache? ? shared:SSL:1m;
? ? #? ? ssl_session_timeout? 5m;

? ? #? ? ssl_ciphers? HIGH:!aNULL:!MD5;
? ? #? ? ssl_prefer_server_ciphers? on;

? ? #? ? location / {
? ? #? ? ? ? root? ?html;
? ? #? ? ? ? index? index.html index.htm;
? ? #? ? }
? ? #}
}

修改server配置塊中的location和php后端請求配置塊

? server {
? ? ? ? listen? ? ? ?80;
? ? ? ? server_name? localhost;

? ? ? ? #charset koi8-r;

? ? ? ? #access_log? logs/host.access.log? main;

? ? ? ? location / {
? ? ? ? ? ? root? ?html;
? ? ? ? ? ? index? index.html index.htm index.php
? ? ? ? }

? ? ? ? #error_page? 404? ? ? ? ? ? ? /404.html;

? ? ? ? # redirect server error pages to the static page /50x.html
? ? ? ? #
? ? ? ? error_page? ?500 502 503 504? /50x.html;
? ? ? ? location = /50x.html {
? ? ? ? ? ? root? ?html;
? ? ? ? }

? ? ? ? # proxy the PHP scripts to Apache listening on 127.0.0.1:80
? ? ? ? #
? ? ? ? #location ~ \.php$ {
? ? ? ? #? ? proxy_pass? ?http://127.0.0.1;
? ? ? ? #}

? ? ? ? # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
? ? ? ? #
? ? ? ? location ~ \.php$ {
? ? ? ? ? ? root? ? ? ? ? ?html;
? ? ? ? ? ? fastcgi_pass? ?127.0.0.1:9000;
? ? ? ? ? ? fastcgi_index? index.php;
? ? ? ? ? ? fastcgi_param? SCRIPT_FILENAME? /scripts$fastcgi_script_name;
? ? ? ? ? ? include? ? ? ? fastcgi_params;
? ? ? ? }

? ? ? ? # deny access to .htaccess files, if Apache's document root
? ? ? ? # concurs with nginx's one
? ? ? ? #
? ? ? ? #location ~ /\.ht {
? ? ? ? #? ? deny? all;
? ? ? ? #}
? ? }

在location配置塊中添加index.php首頁

php請求和后端php-fpm模塊進行通信,需要配置location ~\ .php$配置塊

? root:配置php程序文件的根目錄

*** 修改配置文件的第一行:”user“屬性為我們之前配置的用戶**,表示nginx的權限

至此!我們的Nginx和php的環境完成簡單的配置!
大功告成
啟動步驟:

? ? 啟動Nginx服務

? ? # /usr/local/nginx/sbin/nginx

? ? 啟動php-fpm服務

? ? # /usr/local/php/sbin/php-fpm 或 systemctl restart php-fpm

? ? 啟動mysql服務

? ? # systemctl start mysqld

phpinfo():

在Nginx的目錄html中添加一個php文件:”index.php“

<?php
? ? phpinfo();
?>

測試數據庫連接:

編寫一個連接數據庫行為的php文件:”mysql.php“

php和mysql之間的連接操作依靠的是”mysqli“

<?php
? ? $conn = mysqli_connect("127.0.0.1","root","926498");
? ? if(! $conn ) {
? ? ? ? echo "連接失敗".mysqli_connect_error();
? ? } else {
? ? ? ? ?echo "連接成功";
? ? }
?>

至此!PHP+Nginx+MySQL環境完成了基本的搭建!

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/84943.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/84943.shtml
英文地址,請注明出處:http://en.pswp.cn/web/84943.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

JavaScript中的反射魔法:揭秘Reflect對象的核心方法(下)

JavaScript中的Reflect對象&#xff1a;高級方法解析&#xff08;下&#xff09; 在JavaScript中&#xff0c;Reflect對象不僅提供了基礎的對象操作方法&#xff08;如get、set等&#xff09;&#xff0c;還包含了許多高級API&#xff0c;用于更精細地控制對象行為。本文將繼續…

【數字人開發】Unity+百度智能云平臺實現長短文本個性化語音生成功能

一、創建自己的應用 百度智能云控制臺網址&#xff1a;https://console.bce.baidu.com/ 1、創建應用 2、獲取APIKey和SecretKey 3、Api調試 調試網址&#xff1a;https://console.bce.baidu.com/support/?timestamp1750317430400#/api?productAI&project%E8%AF%AD%E9%…

銀河麒麟 | ubuntu 搭建屬于自己的郵件服務器

目錄 遇權不絕就轉root 更新系統 安裝 Postfix 配置 Postfix 重啟 Postfix 安裝 Dovecot 配置 Dovecot 編輯 Dovecot 的 IMAP 配置文件 編輯 Dovecot 的用戶認證配置文件 編輯 Dovecot 的服務配置文件 重啟 Dovecot 安裝發送郵箱功能 發送郵件 測試 遇權不絕就轉…

嵌入式通信協議框架的四層架構設計與實現

文章目錄 一、硬件抽象層&#xff1a;數據收發的基石1.1 設計要點1.2 代碼示例 二、協議管理層&#xff1a;智能路由中樞2.1 設計要點2.2 代碼示例 三、協議處理層&#xff1a;協議具體實現3.1 設計要求3.2代碼示例3.2.1 協議公共定義3.2.2 協議一設計3.2.3 協議二設計 四、應用…

RA信號處理

ra_snr_gui.m 作用&#xff1a;統計不同信噪比下&#xff0c;五種信號的峰值旁瓣比RA和低高頻均值比RM&#xff0c;繪制結果&#xff0c;參考圖3.11和3.12 DFCW_RA_SNR.m 作用&#xff1a;產生正交離散頻率編碼信號&#xff0c;并計算峰值旁瓣比RA和低高頻均值比 RM LFM_RA_S…

【go的測試】單測之gomock包與gomonkey包

目錄 使用gomock包 1. 安裝mockgen 2. 定義接口 3. 生成mock文件 4. 在單測中使用mock的函數 5. gomock 包的使用問題 使用gomonkey包 1. mock 一個包函數 2. mock 一個公有成員函數 3. mock 一個私有成員函數 使用gomock包 1. 安裝mockgen go get -u github.com/go…

html實現登錄與注冊功能案例(不寫死且只使用js)

目錄 案例需求 實現思路 代碼參考 login.html register.html 運行效果 升級思路 案例需求 需要一個登錄界面和注冊頁面實現一個較為完整的登錄注冊功能 1.登錄界面沒有登錄限制需求&#xff08;降低難度&#xff09;&#xff0c;實現基本的登錄判斷需求&#xff0c;彈窗…

PHP is the best language.

PHP很好寫。 眾所周知Python很好寫&#xff0c;Python 也能開發 Web 應用&#xff0c;但和 PHP 相比&#xff0c;在“直接處理網頁”這件事上&#xff0c;PHP 更加貼近底層和原生。 想快速搭建原型或者 B 端后臺工具&#xff0c;不妨用 PHP Laravel 來搞&#xff0c;真的很香…

Mybatis-Plus 在 getOne() 的時候要加上 .last(“limit 1“)

1.先寫結論: 1.為了確保 SQL 查詢只返回一條記錄&#xff08;當查詢返回多條時會報錯->多為代碼本身問題&#xff09;。 2.防止數據庫執行全表掃描 3.參考網址&#xff1a;問題記錄&#xff1a;MyBatis-Plus 中 ServiceImpl 類的 getOne_mybatis_無他&唯手熟爾-2048…

C語言:二分搜索函數

一、二分搜索基本概念 二分搜索&#xff08;Binary Search&#xff09;是一種在有序數組中查找特定元素的高效算法&#xff0c;時間復雜度為O(log n)。 基本特點&#xff1a; 僅適用于有序數組&#xff08;升序或降序&#xff09; 每次比較將搜索范圍減半 比線性搜索(O(n))…

[前端AI]LangChain.js 和 Next.js LLM構建——協助博客撰寫和總結助手

LangChain.js 和 Next.js LLM 后端應用于協助博客撰寫和總結領域是一個非常實用的方向&#xff01;這涉及到理解和處理文本內容&#xff0c;并生成新的、有結構的信息。 根據您之前提供的代碼和需求&#xff0c;我們可以在此基礎上進行更具針對性的功能規劃和技術實現。 博客…

用 GitHub Issues 做任務管理和任務 List,簡單好用!

說實話&#xff0c;我平時也是一個人寫代碼&#xff0c;每次開完會整理任務最麻煩&#xff1a; 一堆事項堆在聊天里、文檔里&#xff0c;或者散落在郵件里…… 為了理清這些&#xff0c;我通常會做一份 List&#xff0c;標好優先級&#xff0c;再安排到每日的工作里 雖然這個…

每日算法刷題Day35 6.22:leetcode枚舉技巧枚舉中間2道題,用時1h

枚舉中間 對于三個或者四個變量的問題&#xff0c;枚舉中間的變量往往更好算。 為什么&#xff1f;比如問題有三個下標&#xff0c;需要滿足 0≤i<j<k<n&#xff0c;對比一下&#xff1a; 枚舉 i&#xff0c;后續計算中還需保證 j<k。 枚舉 j&#xff0c;那么 i 和…

【教學類-18-06】20250623蒙德里安黑白七款合并WORD(500張、無學號)

背景需要 客戶買了蒙德里安黑白格子7種尺寸,但是不需要學號方塊,并指定要WORD 設計思路 【教學類-18-05】20241118正方形手工紙(蒙德里安-風格派-紅黃藍黑白)-CSDN博客文章瀏覽閱讀1.3k次,點贊29次,收藏18次。【教學類-18-05】20241118正方形手工紙(蒙德里安-風格派-紅…

langchain--(4)

7 Embedding文本向量化 Embedding文本向量化是一種將非結構化文本轉化為低維、連續數值向量的技術,旨在通過數學方式捕捉文本的語義、語法或特征信息,從而讓機器更高效地處理語言任務。其核心思想源于流形假設(Manifold Hypothesis),即認為高維原始數據(如文本)實際隱含…

DMDRS部署實施手冊(ORACLE=》DM)

DMDRS部署實施手冊&#xff08;ORACLE》DM&#xff09; 1 同步說明2 DMDRS安裝3 數據庫準備3.1 源端準備3.1.1 開啟歸檔日志和附加日志3.1.2 關閉回收站3.1.3 創建同步用戶 3.2 目標準備3.2.1 創建同步用戶 4 DMDRS配置4.1 源端配置4.2 目標配置 5 DMDRS啟動5.1 啟動源端服務5.…

十(1)作業:sqli-labs重點關卡

參考文章&#xff1a;詳細sqli-labs&#xff08;1-65&#xff09;通關講解-CSDN博客 第1關&#xff1a; 輸入 &#xff1a; ?id3 輸入 &#xff1a; ?id2 當輸入的數字不同&#xff0c;頁面的響應也不同&#xff0c;說明&#xff0c;輸入的內容被帶入到數據庫里查詢了 輸…

Python 爬蟲入門 Day 7 - 復盤 + 實戰挑戰日

Python 第二階段 - 爬蟲入門 &#x1f3af; 本周知識回顧 網絡請求與網頁結構基礎 HTML解析入門&#xff08;使用 BeautifulSoup&#xff09; 實現爬蟲多頁抓取與翻頁邏輯 模擬登錄爬蟲與 Session 維持 使用 XPath 進行網頁解析&#xff08;lxml XPath&#xff09; 反爬蟲應對…

WebRTC(七):媒體能力協商

目的 在 WebRTC 中&#xff0c;每個瀏覽器或終端支持的音視頻編解碼器、分辨率、碼率、幀率等可能不同。媒體能力協商的目的就是&#xff1a; 確保雙方能“聽得懂”對方發的媒體流&#xff1b;明確誰發送、誰接收、怎么發送&#xff1b;保障連接的互操作性和兼容性。 P2P的基…

可信啟動方案設計

安全之安全(security)博客目錄導讀 目錄 一、引言 二、關鍵數據(Critical Data) 三、度量槽(Measurement Slot) 四、可信啟動后端 1、事件日志(Event Log) 2、離散型 TPM(Discrete TPM) 3、RSE(運行時安全引擎) 五、平臺接口 平臺接口的職責: 1、函數:b…