php編譯安裝可以讓組件配置更靈活,但需要你對php的各種配置非常熟悉,具體的編譯參數可以在php解壓的路徑下執行“./configure --help”進行詳細查看。以下為大致安裝流程,可供參考。
安裝依賴包
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
下載安裝包並解壓
wget http://php.net/distributions/php-7.3.2.tar.gz
tar -zxvf php-7.3.2.tar.gz
cd php-7.3.2
編譯安裝(./configure --help可查看編譯參數)
./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
注意:如果在配置時報libzip版本太低,請卸載重新安裝高版本
完成后,再進行編譯及安裝,執行 make && make install 即可安裝。
注意:如果編譯時報:php7 configure: error: off_t undefined; check your library configuration錯誤,請執行以下操作:
# 添加搜索路徑到配置文件
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 錯誤,請執行以下操作:
在安裝完新版的 libzip 時可能會出現打不到 zipconf.h,手動復制一下
cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
安裝后配置
執行完安裝命令后php7就已經安裝在到了/usr/local/php目錄下了。
/usr/local/php/bin/php -v
查看安裝是否成功。
為了以后方便,可以編輯 /etc/profile 添加環境變量 ,添加到最后面
PATH=$PATH:/usr/local/php/bin
export PATH
然后更新環境變量。
source /etc/profile
查看環境變量
echo $PATH
查看php版本
php -v
配置php-fpm
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-fpm加入啟動服務
cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/php-fpm.service
啟動php-fpm
systemctl start php-fpm.service
如果報這種錯誤
Starting php-fpm [2-Feb-2019 21:02:25] ERROR: [pool www] cannot get uid for user 'www'
說明沒有該用戶,直接執行
groupadd www
useradd -g www www
然后再啟動php-fpm