centos7下編譯安裝php7.3


一、下載php7.3的源碼

https://www.php.net/downloads.php

下載php-7.3.4.tar.gz

 

二、安裝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

 

四、創建用戶和組,並解壓

groupadd www
useradd -g www www
tar xf php-7.3.4.tar.gz
cd php-7.3.4

  

五、進行編譯安裝

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

  

上面的步驟有可能出現的問題:

1、configure: WARNING: unrecognized options: --with-mcrypt, --with-libmbfl, --enable-gd-native-ttf

說明上面的配置參數已經棄用了,刪除即可。

2、configure: error: DBA: Could not find necessary header file(s).

安裝下 yum install gdbm-devel

3、configure: error: Cannot find ldap libraries in /usr/lib

拷貝下文件 cp -frp /usr/lib64/libldap* /usr/lib/

4、configure: 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

5、configure: error: Please reinstall the libzip distribution

在 https://libzip.org/download/ 下載源碼,進行安裝

tar xf libzip-1.5.2.tar.gz
cd libzip-1.5.2
mkdir build && cd build && cmake .. && make && make install

6、CMake 3.0.2 or higher is required. You are running version 2.8.12.2

說明你的cmake版本過低,需要重新安裝

先刪除原有cmake

yum remove cmake

在 https://cmake.org/download/ 下載源碼

tar xf cmake-3.14.3.tar.gz
cd cmake-3.14.3
./bootstrap && make && make install

然后修改 vi /etc/profile,並加入如下內容

PATH=/usr/local/bin:$PATH
export PATH
source /etc/profile

  

六、配置php.ini文件

具體的路徑,大家可自行修改。

cp php.ini-development /data/nmp/php/etc/php.ini
cp /data/nmp/php/etc/php-fpm.conf.default /data/nmp/php/etc/php-fpm.conf
cp /data/nmp/php/etc/php-fpm.d/www.conf.default /data/nmp/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"

  

七、配置Systemd服務

其實php-fpm.service文件php已經幫我們配置好了,只需要我們復制到指定位置,並啟用就行了。

cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/

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

啟用php-fpm.service

systemctl enable php-fpm.service

啟動php-fpm

systemctl start php-fpm.service

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM