[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