PHP 7.4可以设置好repo库之后直接用yum安装, 没有特殊需求不需要使用编译安装.
首先安装必要的程序包
yum install epel-release yum-utils yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
Centos 8
dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
启用remi 仓库
yum-config-manager --enable remi-php74 yum update
Cnetos 8
Error: Problem: cannot install the best candidate for the job - nothing provides libedit-devel(x86-64) needed by php72-php-devel-7.2.33-1.el8.remi.x86_64 (try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages) # dnf config-manager --set-enabled PowerTools
You need to enable the PowerTools repository (equiv. of upstream CodeReady Linux Builder channel) which provide most of the developer stuff.
unable to install php-devel on CentOS 8
搜索可以安装的程序
yum search php74 | more yum search php74 | egrep 'fpm|gd|mysql|memcache' php74-php-fpm.x86_64 : PHP FastCGI Process Manager php74-php-gd.x86_64 : A module for PHP applications for using the gd graphics php74-php-mysqlnd.x86_64 : A module for PHP applications that use MySQL php74-php-pecl-mysql.x86_64 : MySQL database access functions php74-php-pecl-mysql-xdevapi.x86_64 : MySQL database access functions
安装 PHP 7.4 和必要扩展
yum install php74 php74-php-devel php74-php-fpm php74-php-gd php74-php-json php74-php-mbstring php74-php-mysqlnd php74-php-xml php74-php-xmlrpc php74-php-opcache php74-php-mcrypt
检查PHP版本
php74 --version php74 --modules
在nginx 启用PHP
# 检查服务启动参数 cat /usr/lib/systemd/system/php74-php-fpm.service cat /etc/systemd/system/multi-user.target.wants/php74-php-fpm.service # 检查nginx用户组 egrep '^(user|group)' /etc/nginx/nginx.conf # 创建sock 目录 (临时) mkdir -p /var/run/php-fpm/ # 创建sock 目录 (永久) vim /usr/lib/systemd/system/php74-php-fpm.service ExecStartPre=/bin/mkdir -p /var/run/php-fpm/ systemctl edit php74-php-fpm [Service] ExecStartPre=/bin/mkdir -p /var/run/php-fpm/
修改php-fpm 配置
vim /etc/opt/remi/php74/php-fpm.d/www.conf user = nginx group = nginx listen = /var/run/php-fpm/php-fpm.sock listen.owner = nginx listen.group = nginx
修改 session 文件夹所有权
chown -R nginx:nginx /var/opt/remi/php74/lib/php
修改nginx 配置文件
vim /etc/nginx/nginx.conf server { .... # 其他配置参数 location ~ \.php$ { fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name; include fastcgi_params; } }
启动php-fpm 和nginx
systemctl enable php74-php-fpm systemctl restart php74-php-fpm systemctl restart nginx
在你的网站目录下丢一个phpinfo.php
的文件测试吧
<?php // test script for CentOS/RHEL 7+PHP 7.4+Nginx phpinfo(); ?>
Xdebug 2.9.x + VS Code
把 phpinfo 页面完整复制 https://xdebug.org/wizard.php
根据步骤安装
服务器主动与客户端通信, 远程调试客户端需要开放设置的端口
/etc/opt/remi/php74/php.ini
# find / -name "phpize" /opt/remi/php74/root/usr/bin/phpize # find / -name "php-config" ./configure --with-php-config=/opt/remi/php74/root/usr/bin/php-config zend_extension = /opt/remi/php74/root/usr/lib64/php/modules/xdebug.so [xdebug] xdebug.auto_trace = true xdebug.remote_enable = true xdebug.remote_autostart = true xdebug.remote_connect_back = true xdebug.remote_port = 4000 xdebug.collect_vars = On xdebug.collect_return = On xdebug.collect_params = On xdebug.show_local_vars = On xdebug.default_enable = On xdebug.max_nesting_level = 10000
vscode
{ "version": "0.2.0", "configurations": [ { "name": "Listen for XDebug", "type": "php", "request": "launch", "port": 4000, "pathMappings": { "/usr/share/nginx/html": "${workspaceRoot}", }, }, { "name": "Launch currently open script", "type": "php", "request": "launch", "program": "${file}", "cwd": "${fileDirname}", "port": 9000 } ] }
Chrome 插件 (未工作
Xdebug helper
How to install PHP 7.2 on CentOS 7/RHEL 7
Cento7にphp-fpmをインストールし、nginxと連携する