通过wget下载源码
PHP版本以及下载地址可以去 http://php.net/downloads.php 选择,这里我们以7.1.19来演示
1、cd /usr/local/src/
2、wget -O php-7.1.19.tar.gz http://cn2.php.net/get/php-7.1.19.tar.gz/from/this/mirror
2.安装PHP1、先将文件解压
tar -zxvf php-7.1.19.tar.gz
2、解压之后得到一个文件夹,进入这个文件夹
cd php-7.1.19
3、安装之前先安装一些支持库
yum -y install gcc
yum -y install openssl openssl-devel
yum -y install curl-devel
yum -y install libjpeg-devel
yum -y install libpng-devel
yum -y install freetype-devel
yum -y install libxslt-devel
yum -y install libxml2 libxml2-devel
yum -y install epel-release
yum -y install libmcrypt-devel
4、配置PHP
这块特别消耗时间,因此你可以干的别的事
./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc/ \
--with-curl \
--with-freetype-dir \
--with-gd \
--with-jpeg-dir \
--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-xmlrpc \
--with-xsl \
--with-zlib \
--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-xml \
--enable-zip
5、编译安装
make
make install
6、拷贝配置文件到PHP目录
cp php.ini-production /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
3.开启php-fpm开机自启动1、vi /etc/systemd/system/php-fpm.service
2、写入如下代码
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=simple
PIDFile=/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID
[Install]
WantedBy=multi-user.target
3、启动php-fpm
systemctl start php-fpm.service
4、添加到开机启动
systemctl enable php-fpm.service
4.配置环境变量1、vi /etc/profile
文件最底部写入
PATH=$PATH:/usr/local/php/bin:
export PATH
2、wq退出
3、执行命令使配置生效
php -v
安装完毕