怎样迅速安装PHP

2019年10月29日 | 分类: 【技术】

编译安装:https://amon.org/php73-compiling

【安装PHP内核(yum)】

CentOS 7 环境:

dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm && dnf -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm

安装 PHP 7.3 :

yum --enablerepo=remi-php73 install php php-fpm
yum --enablerepo=remi-php73 install php-cli php-json php-xml php-bcmath php-gd php-imap php-xmlrpc php-opcache php-mbstring php-intl php-soap php-mcrypt php-pdo php-mysqlnd php-zip

CentOS 8 环境:

dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm && dnf -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm

查看 PHP 包:

sudo dnf module list | grep php

输出:

php                  7.2 [d]         common [d], devel, minimal               PHP scripting language
php                  7.3             common [d], devel, minimal               PHP scripting language
php                  7.4             common [d], devel, minimal               PHP scripting language
php                  7.2 [d]         common [d], devel, minimal               PHP scripting language
php                  7.3             common [d], devel, minimal               PHP scripting language
php                  7.4             common [d], devel, minimal               PHP scripting language
php                  remi-7.2        common [d], devel, minimal               PHP scripting language
php                  remi-7.3        common [d], devel, minimal               PHP scripting language
php                  remi-7.4 [e]    common [d] [i], devel, minimal           PHP scripting language
php                  remi-8.0        common [d], devel, minimal               PHP scripting language
php                  remi-8.1        common [d], devel, minimal               PHP scripting language
php                  remi-8.2        common [d], devel, minimal               PHP scripting language              

安装 PHP 7.4 :

dnf module install php:remi-7.4
dnf install php-cli php-json php-xml php-bcmath php-gd php-imap php-xmlrpc php-opcache php-mbstring php-intl php-soap php-mcrypt php-pdo php-mysqlnd php-gmp php-zip

卸载 PHP 7.4 :

dnf module remove php:remi-7.4
dnf remove php-cli php-json php-xml php-bcmath php-gd php-imap php-xmlrpc php-opcache php-mbstring php-intl php-soap php-mcrypt php-pdo php-mysqlnd php-gmp php-zip
dnf module reset php:remi-7.4

卸载 PHP 7.3 :

dnf module remove php:remi-7.3
dnf remove php-cli php-json php-xml php-bcmath php-gd php-imap php-xmlrpc php-opcache php-mbstring php-intl php-soap php-mcrypt php-pdo php-mysqlnd php-gmp php-zip
dnf module reset php:remi-7.3

注意:卸载后升级需要重新配置 PHP

1. https://amon.org/php-ioncube

2. ERROR: unable to bind listening socket for address ‘/run/php-fpm/www.sock’: No such file or directory (2)

创建目录 /run/php-fpm :

cd /run/ && mkdir php-fpm

然后重启 php-fpm :

service php-fpm start

输出:

Starting php-fpm  done

查看版本:

php -v

【路径】

php 文件路径:

find / -name php

输出:

/usr/bin/php
/usr/share/php
/usr/lib64/php
/var/lib/php

php.ini 路径:

find / -name php.ini

输出:

/etc/php.ini 

PHP 扩展模块路径:

/usr/lib64/php/modules/

【安装其他PHP扩展】

安装 ioncube :

参考:https://amon.org/php-ioncube

安装 redis :

参考:https://amon.org/php-redis

dnf install php-redis

安装 memcached :

参考:https://amon.org/php-memcached

dnf install php-memcached

【配置】

php 配置文件路径:

/etc/php.ini

php-fpm 配置文件路径:

/etc/php-fpm.conf
/etc/php-fpm.d/www.conf

编辑 php-fpm服务的配置文件 /etc/php-fpm.d/www.conf

修改用户和组为nginx:

user = nginx
group = nginx

创建目录 /run/php-fpm :

cd /run/ && mkdir php-fpm

编辑 /etc/init.d/php-fpm :

php_fpm_BIN=/usr/sbin/php-fpm
php_fpm_CONF=/etc/php-fpm.conf
php_fpm_PID=/run/php-fpm/php-fpm.pid

php-fpm 服务设置:

dos2unix 转换/设置执行权限/注册成服务/设置开机启动

dos2unix /etc/init.d/php-fpm && chmod a+x /etc/init.d/php-fpm && chkconfig --add php-fpm && chkconfig php-fpm on

使用 service 来启动 php-fpm:

service php-fpm start
service php-fpm stop

【排错】

报错:connect() failed (111: Connection refused) while connecting to upstream … upstream: “fastcgi://127.0.0.1:9000

查看 /etc/php-fpm.d/www.conf

listen = /run/php-fpm/www.sock

或:

listen = 127.0.0.1:9000

编辑 nginx.conf :

			# fastcgi_pass 127.0.0.1:9000;
			fastcgi_pass unix:/run/php-fpm/www.sock;

报错:open(SESSION_FILE, O_RDWR) failed: Permission denied (13)

phpMyAdmin报错。

mkdir /var/lib/php && mkdir /var/lib/php/session && chmod -R 777 /var/lib/php/session

如果目录存在却依然报错,尝试:

chmod -R 777 /var/lib/php/session