centos7 編譯安裝 php7.4


1. 下載安裝編譯工具

yum groupinstall 'Development Tools'

2.安裝依賴包

yum 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

3.下載並解壓php7.4

wget http://php.net/distributions/php-7.4.0.tar.gz
tar -zxvf php-7.4.0.tar.gz 
cd php-7.4.0

4.編譯安裝(./configure --help 查看編譯參數)

 編譯前,新增用戶組,用戶,用於編譯使用

groupadd www
useradd -g www www

開始編譯(根據自己需要增減)

./configure \ 
--prefix=/usr/local/php \ 
--with-config-file-path=/etc \ 
--with-fpm-user=www \ 
--with-fpm-group=www \  
--with-curl \ 
--with-freetype-dir \ 
--enable-gd \ 
--with-gettext \  
--with-iconv-dir \ 
--with-kerberos \ 
--with-libdir=lib64 \ 
--with-libxml-dir \ 
--with-mysqli \ 
--with-openssl \ 
--with-pcre-regex \ 
--with-pdo-mysql \ 
--with-pdo-sqlite \ 
--with-pear \ 
--with-png-dir \ 
--with-jpeg-dir \ 
--with-xmlrpc \ 
--with-xsl \ 
--with-zlib \ 
--with-bz2 \ 
--with-mhash \ 
--enable-fpm \ 
--enable-bcmath \ 
--enable-libxml \ 
--enable-inline-optimization \ 
--enable-mbregex \ 
--enable-mbstring \ 
--enable-opcache \ 
--enable-pcntl \ 
--enable-shmop \ 
--enable-soap \ 
--enable-sockets \ 
--enable-sysvsem \ 
--enable-sysvshm \ 
--enable-xml \  
--enable-zip \ 
--enable-fpm

這里需要注意的是在php7.4 編譯參數 --with-gd  要改成了 --enable-gd

當報錯checking for libzip... configure: error: system libzip must be upgraded to version >= 0.11

#先刪除舊版本
yum remove -y libzip

#下載編譯安裝
wget https://nih.at/libzip/libzip-1.2.0.tar.gz
tar -zxvf libzip-1.2.0.tar.gz
cd libzip-1.2.0
./configure
make && make install

error: Package requirements (sqlite3 > 3.7.4) were not met

yum install libsqlite3x-devel -y

error: Package requirements (oniguruma) were not met

yum install oniguruma-devel -y

 當yum install 提示 "沒可用軟件包"

yum install -y epel-release

off_t undefined 報錯

configure: error: off_t undefined; check your library configuration

off_t 類型是在 頭文件 unistd.h中定義的,
在32位系統 編程成 long int ,64位系統則編譯成 long long int ,
在進行編譯的時候 是默認查找64位的動態鏈接庫,
但是默認情況下 centos 的動態鏈接庫配置文件/etc/ld.so.conf里並沒有加入搜索路徑,
這個時候需要將 /usr/local/lib64 /usr/lib64 這些針對64位的庫文件路徑加進去。

#添加搜索路徑到配置文件
echo '/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64'>>/etc/ld.so.conf

#然后 更新配置
ldconfig -v

/usr/local/include/zip.h:59:21: fatal error: zipconf.h: No such file or directory

cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h

編譯沒問題了,執行make && make install  安裝完畢

5.配置環境

執行完安裝命令后php7.4就已經安裝在到了/usr/local/php目錄下了

/usr/local/php/bin/php -v

查看版本

添加環境變量

vim /etc/profile

添加到最后

PATH=$PATH:/usr/local/php/bin
export PATH

更新環境變量

source /etc/profile

查看版本

php -v

6.配置php-fpm

cp php.ini-production /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
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm

啟動php-fpm

/etc/init.d/php-fpm start
或者
service php-fpm start


免責聲明!

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



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