Compiling another version PHP in Direct Admin


First login to your server via ssh.

Proceed to /usr/local/directadmin/custombuild/

Here you can download any PHP version that you would like to compile, get it here :

After successfully downloaded the file compressed file, extract the files.

While in the directory, launch below command to make sure it does not change the existing PHP version (default) in your server.

Let say I'm compiling PHP version 5.6 :
'./configure' '--with-curl=/usr/local/lib' '--with-gd' '--enable-gd-native-ttf' '--with-gettext' '--with-jpeg-dir=/usr/local/lib' '--with-freetype-dir=/usr/local/lib' '--with-kerberos' '--with-openssl' '--with-mcrypt' '--with-mhash' '--with-mysql' '--with-mysqli' '--with-pcre-regex=/usr/local' '--with-pdo-mysql' '--with-pear' '--with-png-dir=/usr/local/lib' '--with-xsl' '--with-zlib' '--with-zlib-dir=/usr/local/lib' '--enable-zip' '--with-iconv=/usr/local' '--enable-bcmath' '--enable-calendar' '--enable-ftp' '--enable-sockets' '--enable-mbstring' '--enable-exif' '--prefix=/usr/local/php5.6' '--sysconfdir=/usr/local/php5.6/etc' '--bindir=/usr/local/php5.6/bin'

If it does not return any errors, then we can proceed to compile new PHP by using :

[simterm]make && make install[/simterm]

This will install a new PHP version under /usr/local/php5.6/

After done compiling, proceed to copy php.ini-production in the extracted new PHP folder to /usr/local/php5.6/etc/php.ini

Next, we create a symlink with by going to /usr/local/php5.6/lib then use below command :
 ln -s /usr/local/php5.6/etc/php.ini php.ini

You may change the max_upload_filesize and post_max_size as desired here.

Lets create a script to generate a custom config for users in Direct Admin that want to use the one we installed just now :

Below is the script :

if [ -z "$1" ]; then
Please enter xxxx ---> where xxx is the userid that you need to run PHP 5.6


mkdir /fcgi
mkdir -p /fcgi/$USER_ID/public_html/
touch /fcgi/$USER_ID/public_html/
chown -R $USER_ID:$USER_ID /fcgi/$USER_ID

echo '#!/bin/sh' > /fcgi/$USER_ID/public_html/
echo 'export PHP_FCGI_MAX_REQUESTS=0' >> /fcgi/$USER_ID/public_html/
echo 'exec /usr/local/php5.6/bin/php-cgi \' >> /fcgi/$USER_ID/public_html/
echo ' -c /usr/local/php5.6/etc/php.ini -d \' >> /fcgi/$USER_ID/public_html/
echo ' -d open_basedir=/home/$USER_ID/ \' >> /fcgi/$USER_ID/public_html/
echo ' -d upload_tmp_dir=/tmp \' >> /fcgi/$USER_ID/public_html/
echo ' -d session.save_path=/tmp \' >> /fcgi/$USER_ID/public_html/
echo ' $1' >> /fcgi/$USER_ID/public_html/

chmod 755 /fcgi/$USER_ID/public_html/

This will create a file called that user can use in their custom httpd config in Direct Admin.

Just insert below :
<Files ~ (\.php)>
SetHandler fcgid-script
FCGIWrapper '/fcgi/(username)/public_html/' .php
Options ALL
allow from all

if subdomain

|*if SUB="(subdomain)"|
<Files ~ (\.php)>
SetHandler fcgid-script
FCGIWrapper '/fcgi/(username)/public_html/' .php
Options ALL
allow from all

Thank you.