1. 安装必要的库
yum -y update
yum -y install gcc-c++ libxml2-devel libxslt-devel libcurl-devel libjpeg-devel libpng-devel openssl-devel bzip2-devel freetype-devel gmp-devel readline-devel libicu-devel
2. 升级libzip
Centos7.9 中源码编译安装 PHP7.3,需要升级libzip;openEuler22.03可以跳过
- 卸载原有低版本的 libzip-devel 包
yum remove libzip-devel
- 安装libzip( 最新稳定版:https://libzip.org/download/ )
# 添加remi的清华yum源,不添加的话yum无法自动为libzip5-devel解决依赖
yum install https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-7.rpm
# 使用rpm包在线安装libzip-devel
yum install https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/7/remi/x86_64/libzip5-devel-1.10.1-1.el7.remi.x86_64.rpm
3. 添加用户和组
groupadd nginx
useradd -g nginx nginx
4. 下载并编译安装php7.3
1. 下载最新php7.3
cd /usr/local/src
wget https://www.php.net/distributions/php-7.3.33.tar.gz
tar -zxvf php-7.3.33.tar.gz
./configure --prefix=/usr/local/php73 --with-config-file-path=/usr/local/php73/etc \
--with-fpm-user=nginx --with-fpm-group=nginx \
--disable-rpath \
--with-curl \
--with-gd --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir \
--with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd \
--with-openssl --with-openssl-dir \
--with-zlib --with-zlib-dir \
--with-libxml-dir --with-xmlrpc --with-mhash --with-readline --with-xsl \
--with-pcre-regex --with-bz2 --with-pcre-dir --with-gettext --with-gmp --with-onig --with-pear \
--enable-fpm \
--enable-mbstring --enable-zip --enable-xml --enable-fileinfo \
--enable-gd-jis-conv \
--enable-ftp --enable-exif --enable-bcmath --enable-sockets --enable-soap \
--enable-shmop --enable-calendar --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx
make && make install
5. 编译完成后,添加环境变量
# 添加搜索路径到配置文件
echo 'PATH=$PATH:/usr/local/php73/bin
export PATH' >> /etc/profile
# 刷新环境变量
source /etc/profile
6. 编辑配置文件
cp /usr/local/src/php-7.3.33/php.ini-production /usr/local/php73/etc/php.ini
cp /usr/local/php73/etc/php-fpm.conf.default /usr/local/php73/etc/php-fpm.conf
cp /usr/local/php73/etc/php-fpm.d/www.conf.default /usr/local/php73/etc/php-fpm.d/www.conf
7. 配置 php.ini 文件
vim /usr/local/php73/etc/php.ini
[PHP]
engine = On
short_open_tag = On
precision = 14
output_buffering = 4096
zlib.output_compression = Off
implicit_flush = Off
unserialize_callback_func =
serialize_precision = -1
disable_functions =
disable_classes =
zend.enable_gc = On
expose_php = OFF
max_execution_time = 300
max_input_time = 300
memory_limit = 1024M
error_reporting = E_ALL
display_errors = On
display_startup_errors = On
log_errors = On
log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
html_errors = On
variables_order = "GPCS"
request_order = "GP"
register_argc_argv = Off
auto_globals_jit = On
post_max_size = 500M
auto_prepend_file =
auto_append_file =
default_mimetype = "text/html"
default_charset = "UTF-8"
doc_root =
user_dir =
enable_dl = Off
cgi.fix_pathinfo=0
file_uploads = On
upload_max_filesize = 500M
max_file_uploads = 20
allow_url_fopen = On
allow_url_include = Off
default_socket_timeout = 60
[CLI Server]
cli_server.color = On
[Date]
date.timezone = Asia/Shanghai
[filter]
[iconv]
[imap]
[intl]
[sqlite3]
[Pcre]
[Pdo]
[Pdo_mysql]
pdo_mysql.default_socket=
[Phar]
[mail function]
SMTP = localhost
smtp_port = 25
mail.add_x_header = Off
[ODBC]
odbc.allow_persistent = On
odbc.check_persistent = On
odbc.max_persistent = -1
odbc.max_links = -1
odbc.defaultlrl = 4096
odbc.defaultbinmode = 1
[Interbase]
ibase.allow_persistent = 1
ibase.max_persistent = -1
ibase.max_links = -1
ibase.timestampformat = "%Y-%m-%d %H:%M:%S"
ibase.dateformat = "%Y-%m-%d"
ibase.timeformat = "%H:%M:%S"
[MySQLi]
mysqli.max_persistent = -1
mysqli.allow_persistent = On
mysqli.max_links = -1
mysqli.default_port = 3306
mysqli.default_socket =
mysqli.default_host =
mysqli.default_user =
mysqli.default_pw =
mysqli.reconnect = Off
[mysqlnd]
mysqlnd.collect_statistics = On
mysqlnd.collect_memory_statistics = On
[OCI8]
[PostgreSQL]
pgsql.allow_persistent = On
pgsql.auto_reset_persistent = Off
pgsql.max_persistent = -1
pgsql.max_links = -1
pgsql.ignore_notice = 0
pgsql.log_notice = 0
[bcmath]
bcmath.scale = 0
[browscap]
[Session]
session.save_handler = files
session.use_strict_mode = 0
session.use_cookies = 1
session.use_only_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.cookie_httponly =
session.cookie_samesite =
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 1440
session.referer_check =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.sid_length = 26
session.trans_sid_tags = "a=href,area=href,frame=src,form="
session.sid_bits_per_character = 5
[Assertion]
zend.assertions = 1
[COM]
[mbstring]
[gd]
[exif]
[Tidy]
tidy.clean_output = Off
[soap]
soap.wsdl_cache_enabled=1
soap.wsdl_cache_dir="/tmp"
soap.wsdl_cache_ttl=86400
soap.wsdl_cache_limit = 5
[sysvshm]
[ldap]
ldap.max_links = -1
[dba]
[opcache]
[curl]
[openssl]
8. 配置www.conf文件
vim /usr/local/php73/etc/php-fpm.d/www.conf
[www]
user = nginx
group = nginx
listen = 127.0.0.1:9073
pm = static
pm.max_children = 300
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.status_path = /php_status_73
slowlog = /var/log/php/php-fpm73.slow.log
request_slowlog_timeout = 3
rlimit_files = 65535
php_admin_value[error_log] = /var/log/php/php-fpm73.www.log
php_admin_flag[log_errors] = on
9.配置systemd守护
cp sapi/fpm/php-fpm.service /etc/systemd/system/php-fpm73.service
mkdir -p /var/log/php
chown nginx.nginx -R /var/log/php
systemctl start php-fpm73
systemctl enable php-fpm73
php-fpm.service 文件内容如下:
# It's not recommended to modify this file in-place, because it
# will be overwritten during upgrades. If you want to customize,
# the best way is to use the "systemctl edit" command.
[Unit]
Description=The PHP FastCGI Process Manager
After=network.target
[Service]
Type=simple
PIDFile=/usr/local/php73/var/run/php-fpm.pid
ExecStart=/usr/local/php73/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php73/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target