1.首先更新依赖包。
yum -y update
2.安装依赖包
yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses curl gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel expat-devel xmlrpc-c xmlrpc-c-devel libicu-devel libmcrypt-devel libmemcached-devel libzip gcc-c++
3.转到 /usr/local/src 目录,下载php7.3.5
cd /usr/local/src
wget https://www.php.net/distributions/php-7.3.5.tar.gz
4.解压安装包,并进入目录
tar -zxvf php-7.3.5.tar.gz
cd php-7.3.5
5.添加用户和组
groupadd www
useradd -g www www
6.开始编译
./configure \
--prefix=/usr/local/php\
--enable-fpm\
--with-fpm-user=www\
--with-fpm-group=www\
--with-config-file-path=/usr/local/php/conf\
--disable-rpath\
--enable-soap\
--with-libxml-dir\
--with-xmlrpc\
--with-openssl\
--with-mhash\
--with-pcre-regex\
--with-zlib\
--enable-bcmath\
--with-bz2\
--enable-calendar\
--with-curl\
--enable-exif\
--with-pcre-dir\
--enable-ftp\
--with-gd\
--with-openssl-dir\
--with-jpeg-dir\
--with-png-dir\
--with-zlib-dir\
--with-freetype-dir\
--enable-gd-jis-conv\
--with-gettext\
--with-gmp\
--with-mhash\
--enable-mbstring\
--with-onig\
--with-mysqli=mysqlnd\
--with-pdo-mysql=mysqlnd\
--with-zlib-dir\
--with-readline\
--enable-shmop\
--enable-sockets\
--enable-sysvmsg\
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx\
--with-libxml-dir\
--with-xsl\
--enable-zip\
--with-pear
这里会提示 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
yum remove libzip -y
cd /usr/local/src
wget https://libzip.org/download/libzip-1.5.2.tar.gz
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 # 使之生效
再次编译PHP7.3
make && make install
7.编译完成后,添加环境变量
vi /etc/profile
#添加以下内容到最后
PATH=$PATH:/usr/local/php/bin
export PATH
#刷新环境变量
source /etc/profile
8.编辑配置文件
cp php.ini-production /usr/local/php/conf/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文件
max_execution_time = 120
max_input_time = 120
memory_limit = 1024M
post_max_size = 128M
date.timezone = PRC
extension_dir = "/data/nmp/php/lib/php/extensions/no-debug-zts-20180731"
9.把systemctl文件加入开机启动文件
cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/php-fpm.service
systemctl start php-fpm.service
systemctl enable php-fpm.service
php-fpm.service文件内容如下:
[Unit]
Description=The PHP FastCGI Process Manager
After=network.target
[Service]
Type=simple
PIDFile=/data/nmp/php/var/run/php-fpm.pid
ExecStart=/data/nmp/php/sbin/php-fpm --nodaemonize --fpm-config /data/nmp/php/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
扩展可参考:
安装gcc,gcc-c++,kernel-devel
yum -y install gcc gcc-c++ kernel-devel
安装php需要的依赖库
yum -y install wget pcre pcre-devel openssl openssl-devel libicu-devel 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的路径 --prefix 和配置文件 --with-config-file-path 路径大家可以自行设置
./configure --prefix=/data/nmp/php \
--with-config-file-path=/data/nmp/php/etc \
--with-fpm-user=www \
--with-fpm-group=www \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir \
--with-ldap=shared \
--with-gdbm \
--with-pear \
--with-gettext \
--with-curl \
--with-xmlrpc \
--with-openssl \
--with-mhash \
--with-gd \
--enable-fpm \
--enable-mysqlnd \
--enable-mysqlnd-compression-support \
--enable-xml \
--enable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--enable-mbregex \
--enable-mbstring \
--enable-intl \
--enable-ftp \
--enable-gd-jis-conv \
--enable-pcntl \
--enable-sockets \
--enable-zip \
--enable-soap \
--enable-fileinfo \
--enable-opcache \
--enable-maintainer-zts \
编译安装
make -j 4 && make install
本文提供了一份详细的PHP7.3从源码编译安装的步骤指南,包括依赖库的安装、用户组配置、编译选项说明及解决常见错误的方法。
551

被折叠的 条评论
为什么被折叠?



