安装依赖
apt install gcc -y &&
apt install make -y &&
apt install openssl -y &&
apt install curl -y &&
apt install libbz2-dev -y &&
apt install libxml2-dev -y &&
apt install libjpeg-dev -y &&
apt install libpng-dev -y &&
apt install libfreetype6-dev -y &&
apt install libzip-dev -y &&
apt install libssl-dev -y &&
apt install libsqlite3-dev -y &&
apt install libcurl4-openssl-dev -y &&
apt install libgmp3-dev -y &&
apt install libonig-dev -y &&
apt install libreadline-dev -y &&
apt install libxslt1-dev -y &&
apt install libffi-dev -y
下载php源码并解压安装
wget https://www.php.net/distributions/php-7.4.9.tar.gz
tar -zxvf php-7.4.9.tar.gz
cd php-7.4.9
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--enable-fpm \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--with-xmlrpc \
--with-mhash \
--with-sqlite3 \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--with-openssl \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--with-openssl-dir \
--with-zlib-dir \
--enable-gd-jis-conv \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-pdo-sqlite \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--with-xsl \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-opcache \
--with-zip \
--with-ffi
#错误一
bzip2
apt-get install libbz2-dev
#错误二
configure: error: GNU MP Library version 4.2 or greater required.
apt install libgmp3-dev
#错误三
No package 'oniguruma' found
wget https://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz -O oniguruma-6.9.4.tar.gz
tar -zxvf oniguruma-6.9.4.tar.gz
cd oniguruma-6.9.4/
./autogen.sh
./configure
makemake install
#错误四
Please reinstall readline - I cannot find readline.h
apt install libreadline-dev
make && make install
配置文件
cp php.ini-development /usr/local/php/etc/php.ini
cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf
cd /usr/local/php/etc/php-fpm.d
cp www.conf.default www.conf
vim /usr/local/php/etc/php-fpm.conf
;pid = run/php-fpm.pid 去掉;(第17行)
vim /usr/local/php/etc/php-fpm.d/www.conf
user = www
group = www
增加php环境变量
vim /etc/profile
# PHP PATH
export PHP_HOME=/usr/local/php
export PATH=$PHP_HOME/bin:$PATH
source /etc/profile
php-fpm服务化(Systemd)
touch /lib/systemd/system/php-fpm.service
vim /lib/systemd/system/php-fpm.service
写入
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=forking
PIDFile=/usr/local/php/var/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
开启php-fpm
cd /usr/local/php/sbin
./php-fpm
服务开机启动
sudo systemctl enable php-fpm.service
启动、停止、重启、状态
sudo systemctl start php-fpm.service
sudo systemctl stop php-fpm.service
sudo systemctl restart php-fpm.service
sudo systemctl status php-fpm.service
来源:oschina
链接:https://my.oschina.net/u/4221859/blog/4485997