PHP版本5到7的源碼編譯安裝

安裝成功的樣子:

[root@localhost /]# systemctl status php-fpm
● php-fpm.service - php-fpm
   Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2020-04-02 15:22:00 CST; 2 days ago
 Main PID: 6251 (php-fpm)
    Tasks: 4
   CGroup: /system.slice/php-fpm.service
           ├─2298 php-fpm: pool www
           ├─6251 php-fpm: master process (/opt/php/etc/php-fpm.conf)
           ├─6474 php-fpm: pool www
           └─9585 php-fpm: pool www

Apr 02 15:22:00 localhost systemd[1]: Starting php-fpm...
Apr 02 15:22:00 localhost systemd[1]: Started php-fpm.
[root@localhost /]# 
[root@localhost /]# /opt/php/bin/php -version
PHP 7.3.16 (cli) (built: Mar 31 2020 16:20:17) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.16, Copyright (c) 1998-2018 Zend Technologies
[root@localhost /]# 
[root@localhost /]#cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 7.6 (Maipo)
[root@localhost /]#


平臺:RedHat Linux 7.6


編譯命令

適合於php ver 5 到 php 7.4.4,不同的版本部分參數不生效,編譯時會自動忽略,該編譯參數已包含常用的庫。

./configure \
--prefix=/opt/php \
--with-config-file-path=/usr/local/php/etc \
--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-gettext \
--with-zlib \
--with-gd \
--with-curl \
--with-mhash \
--with-openssl \
--with-xmlrpc \
--with-bz2 \
--with-gettext \
--with-xsl \
--with-ldap \
--with-kerberos \
--with-libdir=lib64 \
--with-pcre-regex \
--with-pear \
--with-png-dir \
--with-imap-ssl \
--with-imap \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-pcntl \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--enable-pcntl \
--enable-session \
--enable-libxml \
--enable-sockets \
--enable-soap \
--enable-short-tags \
--enable-static \
--enable-ftp \
--enable-opcache \
--enable-ctype \
--enable-calendar \
--enable-mbregex \
--enable-mbstring \
--enable-dom \
--enable-zip \
--with-libevent \
--with-mcrypt \
--enable-gd-native-ttf \
--enable-gd \
--with-zip \
--with-freetype \
--with-jpeg \

make
make install

cp php.ini-development /opt/php/etc/php.ini
cp /opt/php/etc/php-fpm.conf.default /opt/php/etc/php-fpm.conf
cp /opt/php/etc/php-fpm.d/www.conf.default /opt/php/etc/php-fpm.d/www.conf


添加服務

vi /lib/systemd/system/php-fpm.service
寫入以下內容(注意路徑)
[Unit]
#服務描述
Description=php-fpm
#服務類別
After=network.target
[Service]
#後臺運行的方式
Type=forking
#運行命令
ExecStart=/www/lnmp/php/sbin/php-fpm
#獨立的臨時空間
PrivateTmp=true
[Install]
WantedBy=multi-user.target


服務啓停命令:

systemctl start php-fpm
systemctl stop php-fpm
systemctl restart php-fpm
systemctl enable php-fpm
systemctl dislabe php-fpm
systemctl status php-fpm


GD庫沒有安裝

checking whether to enable JIS-mapped Japanese font support in GD... no
checking for fabsf... yes
checking for floorf... yes
configure: error: jpeglib.h not found

解決辦法

yum install libjpeg.x86_64 libpng.x86_64 freetype.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64 libjpeg-turbo-devel -y


PHP編譯出錯:--enable-opcache=no

錯誤消息

configure: error: Don't know how to define struct flock on this system, set --enable-opcache=no

出錯的原因:

因libmcrypt是手動編譯的,需要將這個編譯後的庫文件目錄加入到/etc/ld.so.conf.d/local.conf文件中:

vim /etc/ld.so.conf.d/local.conf
/usr/local/lib
ldconfig

 

LDAP編譯不通過的解決辦法

故障現象:

configure: error: Cannot find ldap.h

解決辦法:

yum install openldap-devel -y

如果安裝了openldap-devel1還是不行,嘗試繼續下面的命令

cp -frp /usr/lib64/libldap* /usr/lib/

如果上述都無法解決,請留言


解決 utf8_mime2text() has new signature 問題

configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing. This should not happen. Check config.log for additional information.
yum install libc-client-devel


解決 libxslt 問題

configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
yum install libxslt-devel -y


故障:libtool: link: `ext/readline/readline_cli.lo' is not a valid libtool object

出錯原因暫時搞不清楚

make clear
make


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章