Skip to content

Instantly share code, notes, and snippets.

@L1so
Last active November 3, 2021 04:01
Show Gist options
  • Save L1so/23835a6bb249dd5451d99757fbb6e95a to your computer and use it in GitHub Desktop.
Save L1so/23835a6bb249dd5451d99757fbb6e95a to your computer and use it in GitHub Desktop.
Install php 5.6.40 from source

Installing php 5.6.40 on Ubuntu 16.04

Make sure you update the package index.

sudo apt-get update

Install dependency package before building.

sudo apt-get install \
    checkinstall \
    apache2-dev \
    libreadline-dev \
    libmcrypt-dev \
    libxml2-dev \
    libcurl4-openssl-dev \
    libjpeg-dev \
    libpng-dev \
    libxpm-dev \
    libmysqlclient-dev \
    libpq-dev \
    libicu-dev \
    libfreetype6-dev \
    libldap2-dev \
    libxslt-dev \
    libssl-dev \
    libldb-dev

Create symbolic link.

sudo ln -s /usr/lib/x86_64-linux-gnu/libldap.so /usr/lib/libldap.so
sudo ln -s /usr/lib/x86_64-linux-gnu/liblber.so /usr/lib/liblber.so

Download php 5.6 from official site, extract it then.

wget https://www.php.net/distributions/php-5.6.40.tar.gz
tar -xvzf php-5.6.40.tar.gz
cd php-5.6.40

Perform building.

'./configure' '--prefix=/opt/php' '--with-config-file-path=/opt/php' '--with-apxs2=/usr/bin/apxs' '--enable-fpm' '--enable-calendar' '--with-mhash' '--with-readline=/usr' '--enable-opcache' '--enable-mbstring' '--with-curl' '--with-openssl' '--enable-zip' '--with-gd' '--with-jpeg-dir' '--with-png-dir' '--with-mysql=mysqlnd' '--with-mcrypt' '--with-pgsql' '--enable-embedded-mysqli' '--with-freetype-dir' '--with-ldap' '--enable-intl' '--with-xsl' '--with-zlib'
make
sudo checkinstall

Create a link for php.

sudo ln -s /opt/php/bin/* /usr/local/bin/

Paste php configuration file, link them after.

sudo cp php.ini-production /opt/php/php.ini
sudo ln -s /opt/php/php.ini /etc

Execute php and see the result.

$ php -v
PHP 5.6.40 (cli) (built: Sep 30 2021 09:20:11) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

Optional steps #1

If you happens to own multi core server (which I do), you can utilize that to make command.

make -j4

Where 4 is your core number, parameter is-j{core_number}.

Optional steps #2

Upon restarting apache, I get such error.

Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe. You need to recompile PHP

Luckily, the solution is quite easy.

sudo a2dismod mpm_event && sudo a2enmod mpm_prefork
sudo /etc/init.d/apache2 restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment