centos就会将我们刚刚下载的PHP7解压到当前目录。ls查看我们会看到一个php7的文件夹。
安装依赖包
yum install -y libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel
打开php下载页
//www.php.net/downloads.php
最后通过wget下载这个地址里解析出来的文件就可以了。
也可以去github上找 php下载
cd /usr/local/src/
wget //www.php.net/distributions/php-7.3.7.tar.gz
我们在当前目录输入
tar -zvxf php-7.3.7.tar.gz
cd php-7.3.7
编译php
./configure --prefix=/usr/local/php7.3.7 \
--with-config-file-path=/usr/local/php7.3.7/etc \
--with-openssl \
--with-curl \
--with-mysql \
--with-pdo-mysql \
--with-mhash \
--with-xmlrpc \
--with-zlib \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--enable-fileinfo \
--enable-bcmath \
--enable-mbstring \
--enable-sockets \
--enable-xml \
--enable-fpm \
--enable-force-cgi-redirect \
--enable-zip \
--enable-soap \
--enable-ftp \
--without-pear
enable-bcmath php精度计算扩展
enable-fileinfo 文件操作
安装
make && make install
最后显示安装成功
Build complete.
Don't forget to run 'make test'.
Installing shared extensions: /usr/local/php7.3.7/lib/php/extensions/no-debug-non-zts-20180731/
Installing PHP CLI binary: /usr/local/php7.3.7/bin/
Installing PHP CLI man page: /usr/local/php7.3.7/php/man/man1/
Installing PHP FPM binary: /usr/local/php7.3.7/sbin/
Installing PHP FPM config: /usr/local/php7.3.7/etc/
Installing PHP FPM man page: /usr/local/php7.3.7/php/man/man8/
Installing PHP FPM status page: /usr/local/php7.3.7/php/php/fpm/
Installing phpdbg binary: /usr/local/php7.3.7/bin/
Installing phpdbg man page: /usr/local/php7.3.7/php/man/man1/
Installing PHP CGI binary: /usr/local/php7.3.7/bin/
Installing PHP CGI man page: /usr/local/php7.3.7/php/man/man1/
Installing build environment: /usr/local/php7.3.7/lib/php/build/
Installing header files: /usr/local/php7.3.7/include/php/
Installing helper programs: /usr/local/php7.3.7/bin/
program: phpize
program: php-config
Installing man pages: /usr/local/php7.3.7/php/man/man1/
page: phpize.1
page: php-config.1
/usr/local/src/php-7.3.7/build/shtool install -c ext/phar/phar.phar /usr/local/php7.3.7/bin
ln -s -f phar.phar /usr/local/php7.3.7/bin/phar
Installing PDO headers: /usr/local/php7.3.7/include/php/ext/pdo/
修改配置
复制php-fpm.conf 和php.ini配置文件
cp /usr/local/src/php-7.3.7/php.ini-production /usr/local/php/etc/php.ini
cp /usr/local/php7.3.7/etc/php-fpm.conf.default /usr/local/php7.3.7/etc/php-fpm.conf
1.然后 php.ini 修改
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/"
2.配置php-fpm.conf
vim /usr/local/php/etc/php-fpm.conf
php-fpm.pid 目录必须指向:/usr/local/php/var/run/php-fpm.pid
如果服务器上安装多个php版本需要修改端口
cp /usr/local/php7.3.7/etc/php-fpm.d/www.conf.default /usr/local/php7.3.7/etc/php-fpm.d/www.conf
修改 www.conf 文件中
listen = 127.0.0.1:9000
改为9001
3.配置环境变量
vi /etc/profile
在末尾追加
PATH=$PATH:/usr/local/php7/bin
export PATH
执行命令使得改动立即生效
source /etc/profile
php添加到liunx服务
1..拷贝php-fpm脚本至/etc/init.d目录
cp /usr/local/src/php-7.3.7/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm7.3.7
3.设置权限并启动php-fpm:
chmod +x /etc/init.d/php-fpm7.3.7
/etc/init.d/php-fpm7.3.7 start
chkconfig --add php-fpm7.3.7
最后,给出php-fpm以服务的方式启动、停止和重启:
service php-fpm7.3.7 start
service php-fpm7.3.7 stop
service php-fpm7.3.7 reload
PHP配置Configure报错:Please reinstall the libzip distribution
发生情景:
php执行配置命令configure时,报如下错误:
checking for libzip... not found
configure: error: Please reinstall the libzip distribution
错误含义:
没有找到libzip
请重新安装libzip的dev包。
尝试解决:
(1)移除旧的libzip:
yum remove libzip
(2)安装新版本:
curl -O //libzip.org/download/libzip-1.5.1.tar.gz
tar -zxvf libzip-1.5.1.tar.gz
cd libzip-1.5.1
mkdir build
cd build
cmake ..
make && make install
注意:如果提示cmake版本过低,需新版本,则需要重新安装cmake。