linux企业部分:php配置、nginx与php合用、memcache模块、openresty模块

Php源码编译

1、软件下载

网络资源下载:http:php.com
我们这里直接从分享资源处获得:
lftp 172.25.254.250 get php-7.4.12.tar.bz2 获取资源后 因为php-7.4.12.tar.bz2是bz2类型的压缩包,需要用到bzip2的压缩工具 yum install bzip2 -y tar jxf php-7.4.12.tar.bz2
到这里软件的获取下载就已经完成了。

2、编译安装

cd php-7.4.12
进行编译:
/configure --prefix=/usr/local/php --with-config-file--path=/usr/local/etc --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-curl --with-iconv --with-zlib --with-mhash --with-openssl --enable-mysqlnd --with-mysqli --with-pdo-mysql --disable-debug --enable-socket
很多部分是我们根据自己的需求添加的模块。
所以在编译过程中会报错,提示某些模块不存在。
我们增加的模块中需要下载的有:
yum install libxml2-devel yum install sqlite-devel yum install libcurl-devel
完成模块添加后,再编译。
make make install
这样我们就完成安装了。但为了正常使用我们还需要完成以下操作。

3、拷贝php-fpm配置文件

cd /usr/local/php/etc cp php-fpm.conf.default php-fpm.conf vim php-fpm.conf
在这里插入图片描述cd php-7.4.12/ cp php.ini-production /usr/local/php/etc/php.ini cd /usr/local/php/etc/ vim php/ini
在这里插入图片描述cd /php-7.4.12/sapi/fpm cp php-fpm.dervice /usr/lib/systemd/system vim php-fom.service
在这里插入图片描述systemctl daemon-reload ##刷新服务列表
systemctl enable --now php-fpm.service ##启动服务

4、nginx结合php使用

1)修改nginx配置文件
vim /usr/local/nginx/conf/nginx.conf
在这里插入图片描述nginx -s reload ##更改配置文件后,重启服务

cd /usr/lcoal/nginx/html/ vim index.php
在这里插入图片描述nginx -s reload ##更改配置文件后,重启服务
测试:
网页搜索:172.25.37.1/index.php
在这里插入图片描述 2)添加环境变量
cd ~ vim .bash_profile
在这里插入图片描述which php echo $PATH
在这里插入图片描述

5、php添加memcache功能模块

1)软件下载
网络资源:http//pecl.php.net/package/memcache
本地资源:
lftp 172.25.254.250 cd /pub/docs/lamp get memcache-4.0.5.2.tar
退出lftp后,解压压缩包:
tar zxfmemcache-4.0.5.2.tgz
在这里插入图片描述
2)软件安装
cd memcache-4.0.5.2 phpize ##phpize是用来扩展php扩展模块的,通过phpize可以建立php的外挂模块,提醒缺少以外autoconf
通过提示,安装缺少的部分:
yum install autoconf yum install automake.noarcch phpize
在这里插入图片描述做完这些后,开始编译、检测、安装。
./configure make make install systemctl daemon-reload systemctl reload php-fpm.service php -m |grep memcache
在这里插入图片描述
在这里插入图片描述
3)构建nginx高速缓存,添加memcache模块。
yum install memcached systemctl start memcache.service netstat -antlp
在这里插入图片描述cat /etc/sysconfig/memcached
在这里插入图片描述cd memcache-4.0.5.2/ cp example.php /usr/local/nginx/html/ cp memcache.php /usr/local/nginx/html/ vim /usr/local/nginx/html/memcache.php

在这里插入图片描述nginx -s relaod systemctl start php-fpm.service systemctlstart memcached
测试:
浏览器搜索:172.25.37.1/memcache.php
User Name : memcache
password: westos

在这里插入图片描述在这里插入图片描述优化:
在真机中执行压力测试命令对其进行优化:
ab -c20 -n1000 http://172.25.37.1/example.php
刷新页面
在这里插入图片描述此时信息处理率达到百分之百。

6、配置php加载模块openresty

1)资源下载
以openresty(构建高效透明的缓存机制)访问,能将缓存放在nginx中,速度更快。
网络资源:http://openresty.org/cn/
本地资源: lftp 172.25.254.250
cd pub/docs/lamp get openresty-1.19.3.1.tar.gz exit tar zxf open-1.19.3.1.tar.gz cd openresty-1.19.3.1
2)安装软件
./configure --with-http_ssl_module --with-http_stub_status_module --with-threads --with-file-aio make make install
3)软件配置

cd /usr/local/openresty/nginx/conf vim /usr/local/opensetry/nginx/conf/nginx.conf
在这里插入图片描述cp /usr/local/nginx/html/example.php . cp /usr/local/nginx/html/index.php . /usr/local/openresty/nginx/sbin/nginx -t /usr/local/openresty/nginx/sbin/nginx -s reload
!!!注意注意!!!
在这里插入图片描述出现图片中的报错时,通过nginx -c指定nginx.conf的文件位置
/usr/local/openresty/nginx/sbin/nginx -c /usr/local/openresty/nginx/conf/nginx.conf /usr/local/openresty/nginx/sbin/nginx -s reload

vim /usr/local/opensetry/nginx/conf/nginx.conf
在这里插入图片描述测试:
在真机进行
ab -c10 -n5000 http://172.25.37.1/example.php
在这里插入图片描述速度快,无报错。

ab -c10 -n5000 http://172.25.37.1/index.php
在这里插入图片描述速度也很快,但传输量大幅提升。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值