in All Posts Basic ~ read.
Compiling another version PHP in Direct Admin

Compiling another version PHP in Direct Admin

Hi,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 : http://php.net/downloads.php

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 :

make && make install

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 :

#!/bin/bash



if [ -z "$1" ]; then

 Please enter php56.sh xxxx ---> where xxx is the userid that you need to run PHP 5.6

 exit

fi



USER_ID=$1



mkdir /fcgi

mkdir -p /fcgi/$USER_ID/public_html/

touch /fcgi/$USER_ID/public_html/fcgid.sh

chown -R $USER_ID:$USER_ID /fcgi/$USER_ID





echo '#!/bin/sh' > /fcgi/$USER_ID/public_html/fcgid.sh

echo 'export PHP_FCGI_MAX_REQUESTS=0' >> /fcgi/$USER_ID/public_html/fcgid.sh

echo 'exec /usr/local/php5.6/bin/php-cgi \' >> /fcgi/$USER_ID/public_html/fcgid.sh

echo ' -c /usr/local/php5.6/etc/php.ini -d \' >> /fcgi/$USER_ID/public_html/fcgid.sh

echo ' -d open_basedir=/home/$USER_ID/ \' >> /fcgi/$USER_ID/public_html/fcgid.sh

echo ' -d upload_tmp_dir=/tmp \' >> /fcgi/$USER_ID/public_html/fcgid.sh

echo ' -d session.save_path=/tmp \' >> /fcgi/$USER_ID/public_html/fcgid.sh

echo ' $1' >> /fcgi/$USER_ID/public_html/fcgid.sh



chmod 755 /fcgi/$USER_ID/public_html/fcgid.sh

This will create a file called fcgid.sh 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/fcgid.sh' .php

 Options ALL

 allow from all

</Files>



if subdomain



|*if SUB="(subdomain)"|

 <Files ~ (\.php)>

 SetHandler fcgid-script

 FCGIWrapper '/fcgi/(username)/public_html/fcgid.sh' .php

 Options ALL

 allow from all

 </Files>

|*endif|
// reference //Initialize ghostHunter