下载PHP源代码
首先需要从PHP官网下载PHP7.3.1的源代码,保存为php-7.3.1.tar.xz。http://cn2.php.net/distributions/php-7.3.1.tar.xz
在上述文件保存的目录中打开终端,使用命令将其解压,并使用cd进入解压后的目录
tar -xvJf ./php-7.3.1.tar.xz
cd php-7.3.1
1.安装依赖
其次,需要安装一些编译PHP所需要的依赖
sudo apt update
sudo apt install gcc
sudo apt install make
sudo apt install openssl
sudo apt install curl
sudo apt install libbz2-dev
sudo apt install libxml2-dev
sudo apt install libjpeg-dev
sudo apt install libpng-dev
sudo apt install libfreetype6-dev
sudo apt install libzip-dev
2.预编译PHP
在编译前,需要对PHP进行配置,以供其生成对应的makefile文件
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli --with-pdo-mysql --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts
配置成功后会出现如下字样
+--------------------------------------------------------------------+
| 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.
3.编译并安装PHP
make
make install
4.验证PHP
可以使用如下指令来输出PHP的版本,来验证是否正确安装
/usr/local/php/bin/php -v
如果正确安装,将会出现如下内容
PHP 7.3.1 (cli) (built: Jan 18 2019 20:11:04) ( ZTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.1, Copyright (c) 1998-2018 Zend Technologies
到这一步为止,PHP7.3.1便成功从源代码编译安装了。
5.复制php.ini
编译安装后的目录并不会有现成的php.ini,需要手动复制过去。
在解压出来的源代码目录中,有供开发环境使用的php.ini-development和供生产环境使用的php.ini-production。
cp php.ini-development /usr/local/php/etc/php.ini
cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
/usr/local/php5/sbin/php-fpm
启动php报错
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
#/usr/local/php/sbin/php-fpm
[29-Nov-2019 13:04:49] ERROR: [pool www] cannot get uid for user 'www'
[29-Nov-2019 13:04:49] ERROR: FPM initialization failed
创建www用户组
直接创建nginx用户和用户组
useradd nginx
groupadd nginx
usermod -G nginx nginx
/usr/local/php5/sbin/php-fpm
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。