[root@localhost ~]# systemctl status firewalld
[root@localhost ~]# systemctl stop firewalld.service #中止firewall服務 [root@localhost ~]# systemctl disable firewalld.service #禁止開機自啓動
#安裝完nginx以後再修改 [root@localhost ~]# vim /etc/nginx/conf.d/default.conf > listen 81; #修改80端口爲81,按本身需求。 [root@localhost ~]# systemctl restart nginx #重啓nginx [root@localhost ~]# firewall-cmd --add-port=81/tcp #臨時開啓81端口 [root@localhost ~]# firewall-cmd --permanent --add-port=81/tcp #永久添加81端口 [root@localhost ~]# firewall-cmd --reload #重啓防火牆
[root@localhost ~]# vim /etc/yum.repos.d/nginx.repo
# /etc/yum.repos.d/nginx.repo # Date 2019_7_14 [nginx-stable] name=nginx stable repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://nginx.org/keys/nginx_signing.key [nginx-mainline] name=nginx mainline repo baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/ gpgcheck=1 enabled=0 gpgkey=https://nginx.org/keys/nginx_signing.key
[root@localhost ~]# yum update #更新源倉庫 [root@localhost ~]# yum install -y nginx #安裝nginx [root@localhost ~]# systemctl start nginx #開啓nginx服務 [root@localhost ~]# systemctl enable nginx #開機自啓 [root@localhost ~]# nginx -t #測試命令 [root@localhost ~]# nginx -s reload #當修改nginx.conf後的重載
php-cgi工做流程(單進程):
php
php-fpm轉發過程圖解
html
php-fpm模式(不在服務器中,可獨立成某一httpd模塊):使用php-fpm管理php-cgi,此時httpd再也不控制php-cgi進程的啓動。能夠將php-fpm獨立運行在非web服務器上,實現所謂的動靜分離。使用php-fpm管理php-cgi,此時httpd再也不控制php-cgi進程的啓動。能夠將php-fpm獨立運行在非web服務器上,實現所謂的動靜分離。java
[root@localhost ~] yum install -y php-fpm
[root@localhost ~]# find / -name html #找到nginx下的html目錄 [root@localhost ~]# vim /usr/share/nginx/html/index.php #編輯php訪問頁面 > # /usr/share/nginx/html/index.php # PHP頁面測試配置 <?php phpinfo(); ?>
[root@localhost ~]# vim /etc/nginx/conf.d/default.conf >找到如下位置,並啓用 # 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 /usr/share/nginx/html/$fastcgi_script_name;# 修改路徑 include fastcgi_params; } [root@localhost ~]# nginx -s reload # 重啓
[root@localhost ~]# ps -ef |grep 9000 #查看php-fpm服務是否開啓 [root@localhost ~]# systemctl restart php-fpm [root@localhost ~]# systemctl restart nginx
在瀏覽器中打開 192.168.110.128:81/index.phpmysql
[root@localhost ~]# vim /etc/nginx/conf.d/default.conf # 找到 pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # 修改相關配置 location ~ \.php$ { root /usr/share/nginx/html;#修改成絕對路徑 fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;#修改成$document或絕對路徑 include fastcgi_params; }
[root@localhost ~]# yum install -y mariadb mariadb-server [root@localhost ~]# systemctl start mariadb.service #啓動MariaDB [root@localhost ~]# systemctl stop mariadb.service #中止MariaDB [root@localhost ~]# systemctl restart mariadb.service #重啓MariaDB [root@localhost ~]# systemctl enable mariadb.service #設置開機啓動
[root@localhost ~]# /usr/bin/mysqladmin -u root password 'passwd' #'passwd'爲你設置的密碼 [root@localhost ~]# systemctl restart mariadb # 重啓
[root@localhost ~]# yum install -y php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash
[root@localhost ~]# vim /usr/share/nginx/html/db.php >#輸入如下測試文件 <?php $link=mysql_connect("localhost","root","passwd"); if(!$link) echo "Link Error!"; else echo "OK!Link Acces!"; mysql_close(); ?> # 重啓Php-fpm、nginx、mariadb-server
[root@localhost ~]# cat /var/log/nginx/error.log [root@localhost ~]# cat /var/log/php-fpm/error.log [root@localhost ~]# cat /var/log/php-fpm/www-error.log