下载PHP
wget -O下载时重命名压缩包
cd /usr/local/src // 压缩包放在 /usr/local/src
wget -O php-7.3.17.tar.gz https://www.php.net/distributions/php-7.3.17.tar.gz
解压
tar -xvzf php-7.3.17.tar.gz
安装
cd /usr/local/src/php-7.3.17
yum -y install libcurl-devel
yum -y install libXpm-devel
yum -y install libxml2-devel
./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-config-file-scan-dir=/usr/local/php/etc/php.d \
--with-mcrypt=/usr/include \
--enable-mysqlnd \
--with-mysqli \
--with-pdo-mysql \
--enable-fpm \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--with-gd \
--with-iconv \
--with-zlib \
--enable-xml \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--enable-mbregex \
--enable-mbstring \
--enable-ftp \
--enable-gd-native-ttf \
--with-openssl \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--without-pear \
--with-gettext \
--enable-session \
--with-curl \
--with-jpeg-dir \
--with-freetype-dir \
--enable-opcache
报错(错误主要是没有C编译器.)
configure: error: no acceptable C compiler found in $PATH
执行以下代码:
安装C编译器yum -y install gcc
,再次执行上面configure
报错
configure: error: Cannot find OpenSSL's <evp.h>
执行以下代码:
yum install openssl -y
yum install openssl-devel -y
再次执行上面configure,配置成功
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
Thank you for using PHP.
config.status: creating php7.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/fpm/php-fpm.conf
config.status: creating sapi/fpm/www.conf
config.status: creating sapi/fpm/init.d.php-fpm
config.status: creating sapi/fpm/php-fpm.service
config.status: creating sapi/fpm/php-fpm.8
config.status: creating sapi/fpm/status.html
config.status: creating sapi/phpdbg/phpdbg.1
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands
configure: WARNING: unrecognized options: --with-mcrypt, --enable-gd-native-ttf
编译安装
make && make install
删除临时文件
make clean
make distclean
配置php
在之前编译的源码包中,找到 php.ini-production,复制到/usr/local/php下,并改名为php.ini:
cp php.ini-production /usr/local/php/php.ini
date.timezone = Asia/Shanghai
将php源码编译目录下的 sapi/fpm/init.d.php-fpm 文件拷贝到系统配置 /etc/init.d 目录下并重命名为 php-fpm (复制启动脚本)
cp ./sapi/fpm/init.d.php-fpm.in /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
php-fpm -h //查看php的配置信息
php-fpm -m //查看加载了那些模块
添加 php-fpm 配置文件
将php安装目录下的 /usr/local/php/etc/php-fpm.conf.default 文件拷贝同目录下并重命名为 php-fpm.conf
添加 www.conf 配置文件
cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
将php安装目录下的 /usr/local/php/etc/php-fpm.d/www.conf.default 文件拷贝同目录下并重命名为 www.conf
cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
添加php安装目录到系统环境变量
创建并打开文件php.sh
vim /etc/profile.d/php.sh
添加内容如下:
export PATH=$PATH:/usr/local/php/bin/:/usr/local/php/sbin/
使用source立即生效刚刚添加的php环境变量
source /etc/profile.d/php.sh
设置php开机启动
修改系统配置目录下的 php-fpm 文件可执行权限
[root@localhost php-src-php-7.1.6]# chmod +x /etc/init.d/php-fpm
> 将系统配置目录下的 `php-fpm` 添加到 `系统服务`
[root@localhost php-src-php-7.1.6]# chkconfig --add php-fpm
> 设置 `php-fpm` `系统服务` 为开机启动
[root@localhost php-src-php-7.1.6]# chkconfig php-fpm on
启动php
/etc/init.d/php-fpm start #php-fpm启动命令
/etc/init.d/php-fpm stop #php-fpm停止命令
/etc/init.d/php-fpm restart #php-fpm重启命令
ps -ef | grep php 或者 ps -A | grep -i php #查看是否已经成功启动PHP