nginx和php调用原理
1)用户通过HTTP协议发送请求,到达LNMP架构中的nginx;
2)nginx会根据用户的请求进行判断,这个判断是由location完成(静态走本地,动态交给后端)
3)判断用户请求的是静态页面,nginx会直接进行处理
4)判断用户请求的是动态页面,nginx会将该请求交给fastcgi协议下发给php-fpm
5)php-fpm管理进程接收到请求后会生成具体的工作线程warrap
6)由warrap线程操作php进行解析
7)如果有操作数据库的操作,则由php去连接数据库,然后发起查询操作搭建lnmp
下载php
1、下载php yum源
yum localinstall -y http://mirror.webtatic.com/yum/el7/webtatic-release.rpm
2、下载php
yum install php71w php71w-cli php71w-common php71w-devel php71w-embedded php71w-gd php71w-mbstring php71w-pdo php71w-xml php71w-fpm php71w-mysqlnd php71w-opcache php71w-mcrypt php71w-pecl-memcached php71w-pecl-mongodb php71w-pecl-redis php71w-pecl-zip php71w-bcmath
3、修改php-fpm进程用户和用户组
sed -i '/^user/c user = www' /etc/php-fpm.d/www.conf
sed -i '/^group/c group = www' /etc/php-fpm.d/www.conf
4、启动php-fpm服务,并加入开机自启
systemctl start php-fpm
systemctl enable php-fpm
下载mysql5.7
1、下载mysql官方拓展源
rpm -ivh http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql57-community-release-el7-10.noarch.rpm
2、下载mysql
yum install -y mysql-community-server
3、启动mysql并加入开机自启
systemctl start mysqld
systemctl enable mysqld
3、登录mysql
mysql -uroot -p$(awk '/temporary password/{print $NF}' /var/log/mysqld.log)
4、修改mysql密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Hax123.com';
配置站点目录并安装wordpress
mkdir /code
cd /code
wget https://wordpress.org/latest.tar.gz
tar xf lastest.tar.gz
mv lastest.tar.gz wordpress
chown -R www.www /code
配置nginx
1、修改nginx进程用户
sed -i '/^user/c user wwww;' /etc/nginx/nginx.conf
2、配置nginx站点配置文件
vim /etc/nginx/conf.d/blog.test.conf
1 server {
2 listen 80;
3 server_name blog.test.com;
4
5 location / {
6 root /code/wordpress;
7 index index.php index.html;
8 }
9 location ~ \.php$ {
10 root /code/wordpress;
将php请求交给本地9000端口处理,9000是php-fpm的默认端口
11 fastcgi_pass 127.0.0.1:9000;
告诉php-fpm解析本地的哪个路径下的哪个文件
12 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
包含一些其他的相关信息的变量
13 include fastcgi_params;
14 }
15 }
3、启动nginx服务并加入开机自启
systemctl start nginx
systemctl enable nginx