1 安装扩展包并更新系统内核
yum install epel-release -y
yum update
2 YUM安装PHP依赖组件(包含Nginx依赖):
yum -y install php-mcrypt libmcrypt-devel libxml2 libxml2-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel libxslt libxslt-devel cyrus-sasl-plain cyrus-sasl cyrus-sasl-devel cyrus-sasl-lib m4 autoconf gcc gcc-c++ openssl openssl-devel pcre pcre-devel zlib zlib-devel wget net-tools zip
3 编译安装配置PHP
3.1 下载应用软件包
下载地址:http://www.php.net/downloads.php
php-7.3.2.tar.gz (sig) [18,954Kb]
3.2 解压应用软件包
tar -xvf php-7.3.2.tar.gz
cd php-7.3.2
3.3 编译
./configure --prefix=/opt/php/php7.3 \
--with-config-file-path=/opt/php/php7.3/etc \
--with-curl \
--with-gd \
--with-gettext \
--with-iconv-dir \
--with-kerberos \
--with-libdir=lib64 \
--with-libxml-dir \
--with-openssl \
--with-pcre-regex \
--with-pdo-sqlite \
--with-pear \
--with-xmlrpc \
--with-xsl \
--with-zlib \
--enable-fpm \
--enable-bcmath \
--enable-libxml \
--enable-inline-optimization \
--enable-mbregex \
--enable-mbstring \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-xml \
--enable-zip \
--enable-static \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--disable-debug \
--disable-fileinfo
此过程如果出错可以参考下面我遇到错误的解决方法
3.4 安装
make clean && make -j 4 && make install
3.5配置
cp /root/php-7.3.2/php.ini-production /opt/php/php7.3/etc/php.ini
cp /opt/php/php7.3/etc/php-fpm.conf.default /opt/php/php7.3/etc/php-fpm.conf
cp /opt/php/php7.3/etc/php-fpm.d/www.conf.default /opt/php/php7.3/etc/php-fpm.d/www.conf
cp /root/php-7.3.2/sapi/fpm/php-fpm.service /usr/lib/systemd/system/php-fpm.service
cp /opt/php/php7.3/bin/php /usr/local/bin/php
#附:centos6添加服务
cp sapi/fpm/init.d.php-fpm /etc/init.d/php7-fpm && chmod 755 /etc/init.d/php7-fpm
3.6启动PHP
systemctl start php-fpm.service
systemctl enable php-fpm.service
安装时遇到的错误解决方法
错误1
configure: error: off_t undefined; check your library configuration
解决方法:
#添加搜索路径到配置文件
echo '/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64'>>/etc/ld.so.conf
更新配置
ldconfig -v
错误2
configure: error: Please reinstall the libzip distribution
解决方法:
yum remove libzip -y
yum -y remove libzip-devel
wget https://libzip.org/download/libzip-1.3.2.tar.gz
tar xvf libzip-1.3.2.tar.gz
cd libzip-1.3.2
./configure
make -j 4
make install
错误3
[root@11111]# systemctl status php-fpm.service
● php-fpm.service - The PHP FastCGI Process Manager
Loaded: error (Reason: Invalid argument)
Active: inactive (dead)
Apr 26 14:00:08 VM_0_2_centos systemd[1]: php-fpm.service lacks both ExecStart= and ExecStop= setting. Refusing.
Apr 26 14:00:19 VM_0_2_centos systemd[1]: [/usr/lib/systemd/system/php-fpm.service:7] Not an absolute path, ignoring: ${prefix}/var/run/php-fpm.pid
Apr 26 14:00:19 VM_0_2_centos systemd[1]: [/usr/lib/systemd/system/php-fpm.service:8] Executable path is not absolute, ignoring: ${exec_prefix}/sbin/php-fpm --nodaemonize --fpm-config ${prefi…c/php-fpm.conf
Apr 26 14:00:19 VM_0_2_centos systemd[1]: php-fpm.service lacks both ExecStart= and ExecStop= setting. Refusing.
Apr 26 14:14:38 VM_0_2_centos systemd[1]: [/usr/lib/systemd/system/php-fpm.service:7] Not an absolute path, ignoring: ${prefix}/var/run/php-fpm.pid
Apr 26 14:14:38 VM_0_2_centos systemd[1]: [/usr/lib/systemd/system/php-fpm.service:8] Executable path is not absolute, ignoring: ${exec_prefix}/sbin/php-fpm --nodaemonize --fpm-config ${prefi…c/php-fpm.conf
Apr 26 14:14:38 VM_0_2_centos systemd[1]: php-fpm.service lacks both ExecStart= and ExecStop= setting. Refusing.
Apr 26 14:14:45 VM_0_2_centos systemd[1]: [/usr/lib/systemd/system/php-fpm.service:7] Not an absolute path, ignoring: ${prefix}/var/run/php-fpm.pid
Apr 26 14:14:45 VM_0_2_centos systemd[1]: [/usr/lib/systemd/system/php-fpm.service:8] Executable path is not absolute, ignoring: ${exec_prefix}/sbin/php-fpm --nodaemonize --fpm-config ${prefi…c/php-fpm.conf
Apr 26 14:14:45 VM_0_2_centos systemd[1]: php-fpm.service lacks both ExecStart= and ExecStop= setting. Refusing.
# vim /usr/lib/systemd/system/php-fpm.service
将其中的${prefix}和${exec_prefix}改成/usr/local/php然后保存
1.下载php7的phpredis扩展库
php官网下载redis扩展页面:http://pecl.php.net/package/redis
wget http://pecl.php.net/get/redis-4.0.2.tgz
2、编译安装phpredis扩展库
tar -xzvf redis-4.0.2.tgz
cd redis-4.0.2
/opt/php/php7.3/bin/phpize
./configure --with-php-config=/opt/php/php7.3/bin/php-config
make && make install
3.添加配置
vim /opt/php/php7.3/etc/php.ini
#文件尾增加下面代码
extension=redis.so
cd /usr/local/src/
wget http://sourceforge.net/projects/re2c/files/0.16/re2c-0.16.tar.gz
tar zvxf re2c-0.16.tar.gz
cd re2c-0.16
./configure && make && make install
cd php-7.3.2/ext/fileinfo/
/opt/php/php7.3/bin/phpize
./configure --with-php-config=/opt/php/php7.3/bin/php-config
make && make install