您现在的位置是:技术博客 > 服务器服务器 yum配置多个PHP版本 Lucas2021-07-22 22:15【代码】1057人已围观 简介yum配置多个PHP版本。 1、依次执行以下命令,更新 yum 中 PHP 的软件源 ``` rpm -Uvh https://mirrors.cloud.tencent.com/epel/epel-release-latest-7.noarch.rpm rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm ``` *rpm 是Redhat用来安装rpm包的命令* 2、安装 PHP 7.2 所需要的包 ``` yum -y install mod_php72w.x86_64 php72w-cli.x86_64 php72w-common.x86_64 php72w-mysqlnd php72w-fpm.x86_64 ``` 3、启动 PHP-FPM 服务 ``` systemctl start php-fpm ``` 4、执行以下命令,设置 PHP-FPM 服务为开机自启动。 ``` systemctl enable php-fpm ``` 再次配置nginx的默认配置 ``` # 编辑配置 vi /etc/nginx/conf.d/default.conf ``` 配置如下 ``` server { listen 80; server_name localhost; root /usr/share/nginx/html; location / { index index.html index.htm; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; } } ``` 注意配置fastcgi_param,否则无法解析php文件,fastcgi_param详解如下 ``` # 1、脚本文件请求的路径 SCRIPT_FILENAME $document_root$fastcgi_script_name; ``` *当访问127.0.0.1/index.php的时候,需要读取网站根目录下面的index.php文件,如果没有配置这一配置项时,nginx不会去网站根目录下访问.php文件,所以返回空白。* ``` # 2、请求的参数;如?app=123 fastcgi_param QUERY_STRING $query_string # 3、请求的动作(GET,POST) fastcgi_param REQUEST_METHOD $request_method # 4、请求头中的Content-Type字段 fastcgi_param CONTENT_TYPE $content_type # 5、请求头中的Content-length字段 fastcgi_param CONTENT_LENGTH $content_length # 6、脚本名称 fastcgi_param SCRIPT_NAME $fastcgi_script_name # 7、请求的地址不带参数 fastcgi_param REQUEST_URI $request_uri # 8、与document_uri; #与uri相同。 fastcgi_param DOCUMENT_URI document_uri # 9、网站的根目录。在server配置中root指令中指定的值 fastcgi_param DOCUMENT_ROOT $document_root # 10、nginx_version;#nginx 版本号,可修改、隐藏 fastcgi_param SERVER_PROTOCOL KaTeX parse error: Expected 'EOF', got '#' at position 18: …rver_protocol # 11、客户端IP fastcgi_param REMOTE_ADDR $remote_addr # 12、客户端端口 fastcgi_param REMOTE_PORT $remote_port # 13、服务器IP地址 fastcgi_param SERVER_ADDR $server_addr # 14、服务器端口 fastcgi_param SERVER_PORT $server_port # 15、服务器名,域名在server配置中指定的server_name fastcgi_param SERVER_NAME $server_name # 16、可自定义变量 #fastcgi_param PATH_INFO $path_info ``` #### 验证环境配置 执行以下命令,创建测试文件 ``` echo "<?php phpinfo(); ?>" >> /usr/share/nginx/html/index.php ``` 重启nginx ``` xxxxxxxxxx systemctl restart nginx ``` 在本地浏览器中访问如下地址,查看环境配置是否成功。 ``` http://云服务器实例的公网 IP ``` 显示结果如下, 则说明环境配置成功。 #### linux配置php环境变量 ``` vim /etc/profile # 加入以下代码,$PATH:后面是需要设置对应php版本的bin目录路径 export PATH=$PATH:/www/wwwserver/php/72/bin ``` 保存退出后,重载*/etc/profile* ``` source /etc/profile ``` 查看php已安装的模块 ``` # php -m ``` 查看yum源php72的相关扩展,下载对应的扩展 ``` yum search php72 # 安装redis扩展 yum -y install php72w-pecl-redis.x86_64 # 重载php-fpm服务 systemctl restart php-fpm ``` ``` # 安装rpm源 rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-7.rpm ``` 更新完后,查看可以安装的PHP版本 ``` yum repolist all | grep php ``` 以下版本可以同时安装 ``` # yum安装php56,具体能安装哪些模块,可以通过yum search php56 来查看 yum -y install php56 php56-php-fpm php56-php-cli php56-php-bcmath php56-php-gd php56-php-json php56-php-mbstring php56-php-mcrypt php56-php-mysqlnd php56-php-opcache php56-php-pdo php56-php-pecl-crypto php56-php-pecl-mcrypt php56-php-soap php56-php-pecl-zip php56-php-process php56-php-pecl-yaf php56-php-xml php56-php-pecl-swoole4 php56-php-ldap php56-php-pear php56-php-xml php56-php-pecl-redis4 # yum安装php72 yum -y install php72 php72-php-fpm php72-php-cli php72-php-bcmath php72-php-gd php72-php-json php72-php-mbstring php72-php-mcrypt php72-php-mysqlnd php72-php-opcache php72-php-pdo php72-php-pecl-crypto php72-php-pecl-mcrypt php72-php-soap php72-php-pecl-zip php72-php-process php72-php-pecl-yaf php72-php-xml php72-php-pecl-swoole4 php72-php-ldap php72-php-pear php72-php-xml # yum安装php73 yum -y install php73 php73-php-fpm php73-php-cli php73-php-bcmath php73-php-gd php73-php-json php73-php-mbstring php73-php-mcrypt php73-php-mysqlnd php73-php-opcache php73-php-pdo php73-php-pecl-crypto php73-php-pecl-mcrypt php73-php-soap php73-php-pecl-zip php73-php-process php73-php-pecl-yaf php73-php-xml php73-php-pecl-swoole4 php73-php-ldap php73-php-pear php73-php-xml # yum安装php74 yum -y install php74 php74-php-fpm php74-php-cli php74-php-bcmath php74-php-gd php74-php-json php74-php-mbstring php74-php-mcrypt php74-php-mysqlnd php74-php-opcache php74-php-pdo php74-php-pecl-crypto php74-php-pecl-mcrypt php74-php-soap php74-php-pecl-zip php74-php-process php74-php-pecl-yaf php74-php-xml php74-php-pecl-swoole4 php74-php-ldap php74-php-pear php74-php-xml ``` 编辑对应版本的php-fpm的配置 ``` # vi /etc/opt/remi/php56/php-fpm.d/www.conf listen = 127.0.0.1:9056 # vi /etc/opt/remi/php73/php-fpm.d/www.conf listen = 127.0.0.1:9073 # vi /etc/opt/remi/php74/php-fpm.d/www.conf listen = 127.0.0.1:9074 ``` 启动服务 ``` systemctl start php56-php-fpm.service systemctl start php73-php-fpm.service systemctl start php74-php-fpm.service ``` 查看开启了哪些php-fpm服务 ``` ps -ef|grep php ``` 单独安装php扩展 ``` # 例如要安装php5.6对应的redis扩展 yum search php56 ```  ``` # yum -y install php56-php-pel-redis4 ``` 安装完成后查看php5.6加载的模块 ``` # /opt/remi/php56/root/usr/bin/php 是php5.6的二进制文件 /opt/remi/php56/root/usr/bin/php -m ``` 启服务生效 ``` systemctl restart php56-php-fpm.service ``` 转载:感谢您对Lucas个人博客网站平台的认可,非常欢迎各位朋友分享到个人站长或者朋友圈,但转载请说明文章出处“来源Lucas个人博客”。 很赞哦! ( 0 ) 上一篇:Linux开启或禁止PING 下一篇:Docker安装mysql 相关文章 定时任务 Curl无法发送https请求 Lnmp环境搭建 Windows的cmd指令 点击排行 生活不止眼前的苟且,还有诗和远方 十年一觉电影梦 奥地利基茨比厄尔 禅修治愈身心 自律成就自我 零边际成本社会 Modern PHP 鸟哥的Linux私房菜 本栏推荐 要技术,更要有创意 定时任务 Curl无法发送https请求 Lnmp环境搭建 常用的SQL函数 Windows的cmd指令 ueditor工具栏浮动bug 有趣的js插件 标签云 git laravel swoole javascript vue ajax html css sql linux docker flask django nginx apache thinkphp markdown sublime wechat layui photoshop nodejs mysql windows composer java maven springboot mybatis IDE 猜你喜欢 Swoole 基础篇一(初识) PHP进程管理器 正则的快速上手 Sublime代码格式化 Lnmp环境搭建 高并发库存防控超量 Linux之top命令 常用的SQL函数 站点信息 建站时间:2018-05-01 在线人数:1人 文章统计:263篇 总浏览量:222501次 统计数据:百度统计 个人信息:扫描二维码查看