ubuntu 16.04编译php5.4.45

1.换源(清华源)

源配置文件位置/etc/apt/source.list

2.安装依赖

$ sudo apt install build-essential autoconf libtool bison re2c zlib1g-dev libbz2-dev libwebp-dev libjpeg-dev libpng12-dev libxpm-dev libfreetype6-dev libxml2-dev libxslt1-dev libpcre3-dev libenchant-dev libpspell-dev libaspell-dev libssl-dev libmcrypt-dev libgmp-dev libcurl4-openssl-dev libldap2-dev \libsasl2-dev libc-client2007e-dev libkrb5-dev libgettextpo-dev libtidy-dev libreadline6-dev libicu-dev libpq-dev firebird-dev librecode-dev libsnmp-dev libxt-dev libmysqlclient-dev apache2-dev

3.下载php5.4.45源码包

$ wget https://www.php.net/distributions/php-5.4.45.tar.bz2
$ tar -jxvf php-5.4.45.tar.bz2

4.编译php

$ cd php-5.4.45
$ export php_prefix='/opt/php/5.4'
$ ./configure \
--prefix=${php_prefix} \
--with-config-file-path=${php_prefix}/lib \
--with-config-file-scan-dir=${php_prefix}/lib/ini \
--with-sqlite3=shared \
--with-pdo-sqlite=shared \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-pgsql=shared,/usr/bin/pg_config \
--with-pdo-pgsql=shared,/usr/bin/pg_config \
--enable-posix \
--enable-pcntl \
--enable-shmop \
--enable-sysvshm \
--enable-sysvsem \
--enable-sysvmsg \
--enable-phar \
--enable-zip \
--with-zlib \
--with-zlib-dir=/usr \
--with-bz2=shared \
--with-gd=shared \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--with-webp-dir=/usr \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-xpm-dir=/usr \
--with-freetype-dir=/usr \
--enable-exif=shared \
--enable-json \
--enable-libxml \
--with-libxml-dir=/usr \
--enable-xml \
--enable-xmlreader \
--enable-xmlwriter \
--enable-simplexml \
--with-pear \
--with-xsl=shared \
--enable-dom \
--enable-soap=shared \
--enable-wddx=shared \
--with-xmlrpc=shared \
--enable-ctype \
--enable-filter \
--with-pcre-regex \
--with-pcre-jit \
--with-enchant=shared \
--with-pspell=shared \
--enable-fileinfo=shared \
--enable-intl=shared \
--with-icu-dir=/usr \
--enable-mbstring=shared \
--with-iconv \
--enable-hash \
--with-openssl=shared \
--with-mcrypt=shared \
--enable-bcmath \
--with-gmp=shared \
--enable-session \
--enable-sockets \
--enable-ftp \
--with-curl=shared \
--with-snmp=shared \
--with-ldap=shared \
--with-ldap-sasl \
--with-imap=shared \
--with-kerberos \
--with-imap-ssl \
--enable-calendar \
--with-gettext=shared \
--with-tidy=shared \
--with-readline \
--enable-tokenizer \
--enable-opcache \
--enable-cli \
--enable-cgi \
--enable-fpm \
--enable-phpdbg \
--with-gd \
--enable-phpdbg-webhelper \
--with-apxs2=/usr/bin/apxs

5.可能遇到错误解决

头文件或者链接库丢失

$ sudo ln -s /usr/lib/x86_64-linux-gnu/libldap.so /usr/lib/
$ sudo ln -s /usr/lib/x86_64-linux-gnu/liblber.so /usr/lib/
$ sudo ln -s /usr/lib/x86_64-linux-gnu/libXpm.so /usr/lib/
$ sudo ln -s /usr/include/x86_64-linux-gnu/gmp.h /usr/include/

6.apache服务无法重启

$ cd /etc/apache2/mods-enabled/
$ ln -s  ../mods-available/mpm_prefork.* .
$ systemctl restart apache2

7.apache无法解析php

在/etc/apache2/apache2.conf中添加如下三行并重启apache服务。

LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .html
AddHandler php5-script .php
posted @ 2021-04-11 20:38  Vlary  阅读(181)  评论(0编辑  收藏  举报