安装wget命令
yum install wget
安装依赖包
yum install gcc autoconf gcc-c++
yum install libxml2 libxml2-devel openssl openssl-devel
yum install bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel
yum install libpng libpng-devel freetype freetype-devel gmp gmp-devel
yum install readline readline-devel libxslt libxslt-devel
yum install systemd-devel
yum install openjpeg-devel
yum install sqlite-devel
yum install -y epel-release
yum install -y oniguruma oniguruma-devel
编译安装依赖包 pcre2
网址: https://ftp.pcre.org/pub/pcre/
wget https://ftp.pcre.org/pub/pcre/pcre2-10.34.tar.bz2
tar xjvf pcre2-10.34.tar.bz2
cd pcre2-10.34
./configure --prefix=/usr/local/pcre2 \
--enable-pcre2-16 \
--enable-pcre2-32 \
--enable-jit \
--enable-jit-sealloc
make && make install
export PKG_CONFIG_PATH=/usr/local/pcre2/lib/pkgconfig/
编译安装 libzip
yum remove libzip
wget https://libzip.org/download/libzip-1.2.0.tar.gz
tar -zxvf libzip-1.2.0.tar.gz
cd libzip-1.2.0
./configure
make && make install
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig/":$PKG_CONFIG_PATH
下载php7.4 ,编译安装
cd /usr/local/src/
wget https://www.php.net/distributions/php-7.4.21.tar.gz
tar zxvf php-7.4.21.tar.gz
cd php-7.4.21/
添加php-fpm用户 创建群组
groupadd php-fpm
创建一个用户,不允许登陆和不创主目录
useradd -s /sbin/nologin -g php-fpm -M php-fpm
编译参数
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-zlib-dir \
--with-freetype \
--enable-mbstring \
--enable-xmlreader \
--enable-xmlwriter \
--enable-soap \
--enable-calendar \
--with-curl \
--with-zlib \
--enable-gd \
--with-pdo-sqlite \
--with-pdo-mysql \
--with-mysqli \
--with-mysql-sock \
--enable-mysqlnd \
--disable-rpath \
--enable-inline-optimization \
--with-bz2 \
--with-zlib \
--enable-sockets \
--enable-sysvsem \
--enable-sysvshm \
--enable-pcntl \
--enable-mbregex \
--enable-exif \
--enable-bcmath \
--with-mhash \
--with-zip \
--with-external-pcre \
--with-pcre-jit \
--with-jpeg \
--with-openssl \
--enable-ftp \
--with-kerberos \
--with-gettext \
--with-xmlrpc \
--with-xsl \
--enable-fpm \
--with-fpm-user=php-fpm \
--with-fpm-group=php-fpm \
--with-fpm-systemd \
--disable-fileinfo
生成和测试环境的参数:
开发环境:
--enable-phpdbg\
--enable-dtrace\
生产环境:
--disable-phpdbg\
--disable-dtrace\
php-ini:
源码包里面有配置文件:
php.ini-development 测试开发环境 php.ini-production 生产环境
复制一份到指定的目录下(根据自己的情况选用,自己可以对比下这两个文件的差异):
cp php.ini-production /usr/local/php/etc/php.ini
php-fpm复制一份新的php-fpm配置文件:
cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf
vim php-fpm.conf
配置错误日志和配置pid文件:
error_log = /usr/local/php/var/php-fpm.log pid = /usr/local/php/var/run/php-fpm.pid
配置php-fpm
cd /usr/local/php/etc/php-fpm.d cp www.conf.default www.conf
管理php-fpm配置:
cd /usr/local/src/php-7.4.21
cp ./sapi/fpm/php-fpm.service 到 /usr/lib/systemd/system/下
配置php-fpm:
- 开机启动
systemctl enable php-fpm
- 启动php-fpm:
systemctl start php-fpm
- 查看状态:
systemctl status php-fpm
添加环境变量:
vim /etc/profile
export PATH=$PATH:'/usr/local/php/bin/'
source /etc/profile
测试
php -v
|