安装准备
PS:若提示-bash: sudo: command not found
请在root环境下运行

apt-get install sudo

先更新软件源

sudo apt-get update

开始安装
下载PHP 7.4源码,并解压

wget https://www.php.net/distributions/php-7.4.0.tar.gz
tar zxvf php-7.4.0.tar.gz
cd php-7.4.0/

安装编译环境及PHP所依赖的运行库

sudo apt-get install libzip-dev bison autoconf build-essential pkg-config git-core   libltdl-dev libbz2-dev libxml2-dev libxslt1-dev libssl-dev libicu-dev libpspell-dev   libenchant-dev libmcrypt-dev libpng-dev libjpeg8-dev libfreetype6-dev libmysqlclient-dev   libreadline-dev libcurl4-openssl-dev librecode-dev libsqlite3-dev libonig-dev

编译安装

./configure --prefix=/usr/local/php7 --with-config-file-scan-dir=/usr/local/php7/etc/php.d --with-config-file-path=/usr/local/php7/etc --enable-mbstring --enable-zip --enable-bcmath --enable-pcntl --enable-ftp --enable-xml --enable-shmop --enable-soap --enable-intl --with-openssl --enable-exif --enable-calendar --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-opcache --enable-fpm --enable-session --enable-sockets --enable-mbregex --enable-wddx --with-curl --with-iconv --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-zlib-dir=/usr --with-freetype-dir=/usr --enable-gd-jis-conv --with-openssl --with-pdo-mysql=mysqlnd --with-gettext=/usr --with-zlib=/usr --with-bz2=/usr --with-recode=/usr --with-xmlrpc --with-mysqli=mysqlnd
make
sudo make install

如果编译过程中提示:

virtual memory exhausted: Cannot allocate memory
Makefile:921: recipe for target ‘ext/fileinfo/libmagic/apprentice.lo’ failed
make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1

请先给服务器添加swap

复制配置文件

sudo cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
sudo cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
sudo cp php.ini-production /usr/local/php7/etc/php.ini

添加环境变量,编辑 /etc/profile,文件末尾添加一行:

PATH=/usr/local/php7/bin:/usr/local/php7/sbin:$PATH

使环境变量生效:

source /etc/profile

将php添加到sudo环境变量,编辑 /etc/sudoers文件中的 Defaults secure_path,后面加上PHP路径:

/usr/local/php7/bin:/usr/local/php7/sbin:

启动php-fpm

sudo php-fpm

如果提示:

[15-Nov-2019 15:53:49] ERROR: [pool www] cannot get gid for group ‘nobody’
[15-Nov-2019 15:53:49] ERROR: FPM initialization failed

就要先创建用户组:

sudo groupadd nobody
Last modification:February 1st, 2020 at 08:25 am
如果觉得我的文章对你有用,请随意赞赏