centos7安装php教程
时间: 2023-11-20 12:57:12 浏览: 186
以下是CentOS 7安装PHP的两种方法:
1. 通过yum安装
```shell
# 安装epel-release仓库
yum install epel-release -y
# 安装remi仓库
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
# 安装PHP7.4
yum install php74 -y
# 安装常用扩展
yum install php74-php-mysqlnd php74-php-gd php74-php-xml php74-php-mbstring -y
# 启动PHP-FPM服务
systemctl start php74-php-fpm.service
# 设置开机自启动
systemctl enable php74-php-fpm.service
```
2. 编译安装
```shell
# 安装编译PHP所需的依赖
yum install -y gcc gcc-c++ make autoconf libtool-ltdl-devel \
libxml2-devel libjpeg-devel libpng-devel freetype-devel \
openssl-devel curl-devel libxslt-devel libmcrypt-devel \
bzip2-devel readline-devel libedit-devel
# 下载PHP源码包
wget https://www.php.net/distributions/php-7.4.30.tar.gz
# 解压源码包
tar -zxvf php-7.4.30.tar.gz
# 进入解压后的目录
cd php-7.4.30
# 配置编译参数
./configure --prefix=/data/server/php \
--with-config-file-path=/data/server/php/lib \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir \
--with-freetype \
--with-jpeg \
--with-png \
--with-zlib \
--with-libxml-dir \
--enable-simplexml \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-soap \
--enable-zip \
--with-curl \
--enable-mbstring \
--with-openssl \
--with-mhash \
--enable-opcache \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-maintainer-zts \
--with-readline \
--with-libedit
# 编译并安装
make && make install
# 复制php.ini文件
cp php.ini-production /data/server/php/lib/php.ini
# 启动PHP-FPM服务
/data/server/php/sbin/php-fpm
# 设置开机自启动
echo "/data/server/php/sbin/php-fpm" >> /etc/rc.local
chmod +x /etc/rc.local
```
阅读全文