ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

PHP+Nginx服务部署

2021-09-27 21:29:53  阅读:334  来源: 互联网

标签:php nginx 部署 Nginx usr -- PHP local fastcgi


文章目录

一、PHP的安装和部署

tar jxf php-7.4.12.tar.bz2#这里是以4.12为例
tar zxf php-7.4.24.tar.gz#后续实验采用最新的版本
ls
cd php-7.4.12/

在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述
预编译

`./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-curl --with-iconv --with-zlib --with-openssl --enable-mysqlnd --with-mysqli --with-pdo-mysql --disable-debug --enable-sockets --enable-soap --enable-inline-optimization --enable-xml --enable-ftp --enable-gd --enable-exif --enable-mbstring --enable-bcmatch --with-fpm-systemd`

在这里插入图片描述每次预编译后安装所需软件,直至预编译完全为止。

yum install systemd-devel.x86_64 -y
yum install  libxml2-devel.x86_64 -y
yum install  sqlite-devel.x86_64 -y
yum install  libcurl-devel.x86_64 -y
yum install  libpng-devel.x86_64 -y
#以下两个安装包在系统自带的软件仓库中并没有,需要自行下载再安装
yum install  oniguruma-6.8.2-1.el7.x86_64.rpm -y
yum install  oniguruma-devel-6.8.2-1.el7.x86_64.rpm -y

预编译成功
在这里插入图片描述编译和安装
make&make install

在这里插入图片描述在这里插入图片描述

二、PHP的配置

1、PHP配置文件的生成和修改(php-fpm.conf)

在这里插入图片描述进入拷贝的配置文件,将图示位置注释掉
在这里插入图片描述

2、文件www.conf的生成

在这里插入图片描述

3、文件php.ini的生成

在这里插入图片描述

cp php.ini-production /usr/local/lnmp/php/etc/php.ini 
#将PHP生产文件复制到该路径下生成php.ini文件

在这里插入图片描述在这里插入图片描述

4、php-fpm.service服务的systemctl开启

在这里插入图片描述

cp php-fpm.service /usr/lib/systemd/system#将PHP服务文件复制到服务配置目录下并注释掉内容

在这里插入图片描述

systemctl daemon-reload
#重新加载某个服务的配置文件,如果新安装了一个服务,归属于 systemctl 管理,要是新服务的服务程序配置文件生效,需重新加载。此处为php-fpm服务
systemctl start php-fpm.service	#开启php服务

三、PHP+Nginx服务

1、修改nginx配置文件

进入nginx的目录下的配置文件中,打开php设置并添加php发布文件

http{

	.........
	
        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;
        }
...
}


server {
        listen 80;
        server_name www.westos.com;
        location / {
                root html;
        index =这里要修改=iindex.php index.html index.htm;
                }
        }

}#http的}
nginx -t
nginx -s reload

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

2、编写php发布文件

cd /usr/local/nginx/html
vim index.php
---
<?php
phpinfo()
?>
---
nginx -s reload

在真机浏览器访问172.25.76.1/index.php

在这里插入图片描述如出现以上问题可以选择:
1、重启php-fpm服务
2、ps ax | grep nginx查看进程后杀掉多余的nginx进程并重启nginx服务

在这里插入图片描述
php-fpm服务部署成功!

3、添加环境变量

cd /usr/local/lnmp/php/sbin
pwd #/usr/local/lnmp/php/sbin
cd
vim .bash_profile	#编辑文件添加环境变量
. bash_profile		#使修改生效

在这里插入图片描述
在这里插入图片描述测试php是否生效
在这里插入图片描述

四、PHP添加memcache模块

1、下载memcache

下载后解压安装包

tar zxf memcache-4.0.5.2.tgz

2、安装和部署memcache

cd memcache-4.0.5.2/
phpize

在这里插入图片描述

yum install autocon -y 
phpize

在这里插入图片描述可以进行安装和编译了

安装编译三部曲configure–>make–>make install

./configure --enable-debug
make
make install

在这里插入图片描述
在这里插入图片描述

cd /usr/local/lnmp/php/etc
ls
vim php.ini

在这里插入图片描述在这里插入图片描述

配置文件修改完成后注意要重启php-fpm服务
测试:
1、php -m | grep memcache查看是否有该模块
2、本机浏览器172.25.76.1/index.php查看是否有

在这里插入图片描述在这里插入图片描述

3、构建nginx高速缓存

安装并开启memcached服务

yum install -y memcached
systemctl start memcached.service
netstat -antpl | grep :11211
cat /etc/sysconfig/memcached 

在这里插入图片描述在这里插入图片描述在这里插入图片描述

vim memcache.php
systemctl restart memcached.service

在这里插入图片描述

访问本机浏览器172.25.76.1/memcache.php
需要输入memcache.php中设置的账号密码即可登陆

在这里插入图片描述在这里插入图片描述

在真机测试ab -c20 -n 1000 htpp://172.25.76.1/example.php

在这里插入图片描述

五、配置php加载模块openresty

1、下载安装

nginx -s stop
tar zxf openresty-1.19.3.1.tar.gz
cd openresty-1.19.3.1/
#安装三部曲
./configure --with-http_ssl_module --with-http_stub_status_module --with-threads --with-file-aio
make
make install

2、修改配置

cd /usr/local/openresty/nginx.conf
vim nginx.conf
///
user  nginx;
worker_processes  1;

events {
    worker_connections  65535;
}

        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.conf;
        }
///
cd ..
cd html/
cp /usr/local/nginx/html/example.php .		
cp /usr/local/nginx/html/index.php .
/usr/local/openresty/nginx/sbin/nginx
/usr/local/openresty/nginx/sbin/nginx -t
/usr/local/openresty/nginx/sbin/nginx -s reload

3、优化配置

vim nginx.conf
http {
        upstream memcache {
        server 127.0.0.1:11211;
        keepalive 512;					##保持512个不立即关闭的连接用于提升性能
        }

    include       mime.types;
    default_type  application/octet-stream;

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        location /memc {
        internal;						##表示只接受内部访问
        memc_connect_timeout 100ms;
        memc_send_timeout 100ms;
        memc_read_timeout 100ms;
        set $memc_key $query_string;	##使用内置的$query_string来作为key
        set $memc_exptime 300;			##表示缓存失效时间
        memc_pass memcache;
        }
        
        location ~ \.php$ {
            set $key $uri$args;
            srcache_fetch GET /memc $key;
            srcache_store PUT /memc $key;
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi_params;
        }
/usr/local/openresty/nginx/sbin/nginx -t
/usr/local/openresty/nginx/sbin/nginx -s reload

在真机测试

ab -c10 -n 5000 http://172.25.76.1/example.php

在这里插入图片描述

ab -c10 -n 5000 http://172.25.76.1/index.php

在这里插入图片描述

标签:php,nginx,部署,Nginx,usr,--,PHP,local,fastcgi
来源: https://blog.csdn.net/m0_49265034/article/details/120372735

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有