源码安装 PHP7.4X 手记

环境

1. 系统:Centos 8 mariadb-10.5.2

安装部署

1. 依赖处理 推荐一个rpm包网站:https://pkgs.org/

2. 创建程序目录 请按需修改

代码语言:javascript
复制
mkdir /usr/local/php7

3. 编译安装 请按需修改

代码语言:javascript
复制
    ./configure --prefix=/usr/local/php7 \
    --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 \
    --with-png --with-zlib --with-freetype --enable-gd-jis-conv \
    --with-openssl --with-pdo-mysql=mysqlnd \
    --with-gettext --with-zlib --with-bz2 --with-recode --with-xmlrpc \
    --with-pdo-mysql=/usr/local/mariadb \
    -enable-mysqlnd \
    --with-mysqli=mysqlnd
    --with-pear

make -j 4
make install


4. 修改配置、添加启动项 请按需修改

代码语言:javascript
复制
rm -rf /etc/php.ini
cp php.ini-production /usr/local/php7/etc/php.ini
ln -s /usr/local/php7/etc/php.ini /etc/php.ini
cd /usr/local/php7/etc/
cp php-fpm.conf.default php-fpm.conf
rm -f /etc/php-fpm.conf
ln -s /usr/local/php7/etc/php-fpm.conf /etc/php-fpm.conf

修改配置文件

php-fpm.conf 末行 include=/usr/local/php7/etc/php-fpm.d/*.conf 修改为 include=/usr/local/php7/etc/php-fpm.d/www.conf.default

修改文件 /usr/local/php7/etc/php-fpm.d/www.conf.default,按如下修改(用户请按需指定):
user = nobody => user = www
group = nobody => group = www

;listen.owner = nobody => listen.owner = www
;listen.group = nobody => listen.group = www

listen = 127.0.0.1:9000 行下添加 listen = /var/run/php-fpm.sock

代码语言:javascript
复制
cp /usr/local/src/php-7.4.4/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
chmod 0660 /var/run/php-fpm.sock
chown www:www /var/run/php-fpm.sock
chmod 755 /etc/rc.d/init.d/php-fpm
chkconfig php-fpm on
systemctl start php-fpm
systemctl status php-fpm

5. php.ini 文件配置 请按需修改

5.1 php 安全设置,此选项代表禁用 详见 官网

代码语言:javascript
复制
disable_functions =
passthru,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space

5.2 PHP 版本关闭显示 详见 官网

代码语言:javascript
复制
expose_php = Off

5.3 文件上传功能限制配置

代码语言:javascript
复制
file_uploads = On
upload_max_filesize = 2M // 上传文件大小限制

5.4 PHP 时区设置

代码语言:javascript
复制
date.timeZone = Asia/Shanghai

FAQ