美文网首页
php7.3源码编译安装之生产篇

php7.3源码编译安装之生产篇

作者: 我爱张智容 | 来源:发表于2021-02-08 14:16 被阅读0次

安装扩展包并更新系统内核:

$ yum install epel-release -y
$ yum update

安装php依赖组件(包含Nginx依赖):

$ yum -y install wget vim pcre pcre-devel openssl openssl-devel libicu-devel gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn libidn-devel openldap openldap-devel nss_ldap jemalloc-devel cmake boost-devel bison automake libevent libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel

创建用户和组,并下载php安装包解压:

$ cd 
$ userdel www
$ groupadd www
$ useradd -g www -M -d /data/www -s /sbin/nologin www &> /dev/null
$ wget https://www.php.net/distributions/php-7.3.15.tar.gz
$ tar xvf php-7.3.15.tar.gz
$ cd php-7.3.15

设置变量并开始源码编译:

./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-mysqlnd-compression-support \
--with-iconv-dir \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-mbstring \
--enable-intl \
--with-gd \
--enable-gd-jis-conv \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--with-gettext \
--enable-opcache \
--enable-maintainer-zts \
--without-gdbm \
--enable-fileinfo

=======所遇问题=========

这里会提示 configure: error: Please reinstall the libzip distribution,我们需要溢出libzip,手动安装最新版本,

先编译安装最新版cmake

cd /usr/local/src

wget https://github.com/Kitware/CMake/releases/download/v3.14.3/cmake-3.14.3.tar.gz

tar -zxvf cmake-3.14.3.tar.gz

cd cmake-3.14.3

./bootstrap

make && make install

再编译安装libzip (下载慢,就去github上下载)

yum remove libzip -y
cd /usr/local/src
wget https://libzip.org/download/libzip-1.5.2.tar.gz    或者 github下载 (https://github.com/nih-at/libzip/releases)
tar -zxvf libzip-1.5.2.tar.gz
cd libzip-1.5.2
mkdir build
cd build
cmake ..
make && make install

再次编译php7.3,继续报错 error: off_t undefined; check your library configuration
执行以下命令

vi /etc/ld.so.conf
添加如下几行
/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64
保存退出
:wq

ldconfig -v # 使之生效

开始安装:

$ make -j 4 && make install

完成安装后配置php.ini文件:

$ cp php.ini-development /usr/local/php/etc/php.ini
$ cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
$ cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

修改 php.ini 相关参数:

$ vim /usr/local/php/etc/php.ini
expose_php = Off
short_open_tag = ON
max_execution_time = 300
max_input_time = 300
memory_limit = 128M
post_max_size = 32M
date.timezone = Asia/Shanghai
extension = ldap.so

修改php-fpm相关参数

sed -i 's,user = nobody,user=www,g'  /opt/php/etc/php-fpm.d/www.conf
sed -i 's,group = nobody,group=www,g'  /opt/php/etc/php-fpm.d/www.conf
sed -i 's,^pm.min_spare_servers = 1,pm.min_spare_servers = 5,g'  /opt/php/etc/php-fpm.d/www.conf
sed -i 's,^pm.max_spare_servers = 3,pm.max_spare_servers = 64,g'  /opt/php/etc/php-fpm.d/www.conf
sed -i 's,^pm.max_children = 5,pm.max_children = 100,g'  /opt/php/etc/php-fpm.d/www.conf
sed -i 's,^pm.start_servers = 2,pm.start_servers = 20,g'  /opt/php/etc/php-fpm.d/www.conf
sed -i 's,;pid = run/php-fpm.pid,pid = run/php-fpm.pid,g'  /opt/php/etc/php-fpm.d/www.conf
sed -i 's,;error_log = log/php-fpm.log,error_log = /data/logs/php/php-fpm.log,g'  /opt/php/etc/php-fpm.d/www.conf
sed -i 's,;slowlog = log/$pool.log.slow,slowlog = /data/logs/php/\$pool.log.slow,g'  /opt/php/etc/php-fpm.d/www.conf

设置 OPcache 缓存:

[opcache]
zend_extension=opcache.so
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1

安装启动文件 或 安装服务启动

install -v -m755 ./sapi/fpm/init.d.php-fpm  /etc/init.d/php-fpm
/etc/init.d/php-fpm start

把systemctl文件加入开机启动服务

cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/php-fpm.service
systemctl start php-fpm.service  //启动fpm 
systemctl enable php-fpm.service  //开机启动 (centos推荐这种方式)

下一步安装必要扩展

redis
mongodb
swoole

完毕

相关文章

网友评论

      本文标题:php7.3源码编译安装之生产篇

      本文链接:https://www.haomeiwen.com/subject/ihfdaktx.html