CentOS 7 安装 PHP

添加EPEL和REMI存储库

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

安装

# yum -y install yum-utils
# yum-config-manager --enable remi-php74
# yum -y install php php-cli
  • 安装插件
# yum -y install php php-cli php-fpm php-mysqlnd php-zip php-gd php-mcrypt php-mbstring php-xml php-pear php-bcmath php-redis php-memcached php-ldap php-intl php-pecl-imagick php-pecl-swoole php-devel php-curl php-json

使用国内源安装 - 安装方式二(推荐)

  • 编辑安装脚本
# vim php_install.sh
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum install -y --nogpgcheck https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-$(rpm -E %centos).rpm

find /etc/yum.repos.d/ -name "remi*.repo" | xargs sed -i "s/#baseurl/baseurl/g"
find /etc/yum.repos.d/ -name "remi*.repo" | xargs sed -i "s/mirrorlist/#mirrorlist/g"
find /etc/yum.repos.d/ -name "remi*.repo" | xargs sed -i "s@http://rpms.remirepo.net@https://mirrors.tuna.tsinghua.edu.cn/remi@g"

yum clean all
yum makecache
yum install yum-utils -y
yum-config-manager --enable remi-php74

yum -y install php php-cli php-fpm php-mysqlnd php-zip php-gd php-mcrypt php-mbstring php-xml php-pear php-bcmath php-redis php-memcached php-ldap php-intl php-pecl-imagick php-pecl-swoole php-devel php-curl php-json
  • 脚本授权
# chmod +x php_install.sh
  • 执行脚本
# ./php_install.sh

修改 php.ini 配置

  • 按实际修改即可
# vim /etc/php.ini
post_max_size = 10240M
upload_max_filesize = 10240M
memory_limit = 1024M
max_execution_time = 3600
max_input_time = 3600
cgi.fix_pathinfo=1

修改 www.conf 配置

  • 按实际修改即可
# vim /etc/php-fpm.d/www.conf
user = nginx
group = nginx
listen = /var/run/php-fpm.sock
listen.owner = nginx
listen.group = nginx
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 10
pm.max_spare_servers = 35

启停 PHP

  • 启动
# systemctl start php-fpm
  • 停止
# systemctl stop php-fpm
  • 重启
# systemctl restart php-fpm
  • 开机自启
# systemctl enable php-fpm

查看版本

# php -v

PHP 7.4.16 (cli) (built: Mar  2 2021 10:35:17) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

image.png

  • 查看已安装的插件
# php --modules


标题:CentOS 7 安装 PHP
作者:Mune
地址:https://cnxiaobai.com/articles/2021/04/21/1618997548877.html

    评论
    0 评论
avatar

取消