作者环境:CentOS Linux release 7.6.1810 (Core) --Docker
1. 更新yum(Yellow dogUpdater, Modified)源已经切过源请忽略
# 备份
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bk
# 已经安装wget跳过此步
yum install -y wget
# 使用aliyun
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
2. 安装依赖
yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel \
freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses \
ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap \
openldap-devel nss_ldap openldap-clients openldap-servers libxslt-devel libxslt
3. 下载php7,这里使用的版本是 【7.0.33】
# 切换目录
cd /usr/local/src
# 下载php源代码
wget http://am1.php.net/distributions/php-7.0.33.tar.gz
# 解压
tar -zxvf php-7.0.33.tar.gz
mv php-7.0.33 ../
cd ../php-7.0.33
4. 编译安装
./configure --prefix=/usr/local/php7 --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir \
--with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql \
--with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 \
--with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf \
--enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap \
--enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip
# 安装
make && make install
# 创建软链,方便使用命令
ln -s /usr/local/php7/sbin/php-fpm /usr/local/bin/
ln -s /usr/local/php7/bin/php /usr/local/bin/
ln -s /usr/local/php7/bin/phpize /usr/local/bin/
# 如果/usr/local/bin没有加入PATH,可以执行下面的命令
echo 'export PATH=/usr/local/bin:$PATH' >>~/.bashrc && source ~/.bashrc
5. 配置
安装完成后,运行php -i
查看默认的配置文件目录为:Configuration File (php.ini) Path => /usr/local/php7/lib
, 可以从源代码中拷贝官方默认配置
cp /usr/local/php-7.0.33/php.ini-development /usr/local/php7/lib/php.ini
网友评论