Applicable to:
- Plesk for Linux
Question
How to add a custom PHP version?
Answer
Warning: ALL THE INSTRUCTIONS BELOW ARE TO BE PERFORMED AT OWN WILL AND RISK
On Linux systems, you can install any PHP version you need and then make it available in Plesk by registering it with the php_handler
command-line utility.
To add an arbitrary PHP version in Plesk:
- Install the desired PHP version on your server. For installation guidelines, refer to the official PHP documentation available at http://php.net/manual/en/install.php. In brief, the installation includes the following main steps.
Warning: These steps are provided for demonstration purposes only and not supported by Plesk. Depending on your operating system and the desired configuration, installation steps can differ significantly. When you install an additional PHP version on your server, read the official PHP documentation on installation.
- Connect to the server via SSH
-
Install C compiler and XML library with the following commands:
RHEL based OSes:
# yum install gcc -y && yum install libxml2-devel -y
Debian based OSes:
# apt-get install build-essential && apt-get install libxml2-dev
- Obtain the PHP source you need from the official website (http://php.net/downloads.php or http://php.net/releases/) and unpack it:
# gunzip php-NN.tar.gz
# tar -xf php-NN.tar
- Configure and build PHP. This is when you can customize PHP with various options, such as specifying which extensions will be enabled. Run
./configure --help
for a list of available options.# cd ../php-NN
# ./configure --prefix /usr/local/phpNN
# make
# make install
- Set up your
php.ini
:# cp php.ini-development /usr/local/lib/php.ini
You may edit your
.ini
file to set PHP options. If you prefer havingphp.ini
in another location, run theconfigure
utility with the option--with-config-file-path=/some/path
in step 3.
- Register the new PHP version in Plesk:
# /usr/local/psa/bin/php_handler --add -displayname <NN> -path <path to php cgi> -phpini <path to php.ini> -type <php handler> -id <NN-custom> -clipath <path to php cli>
where
-displayname
<NN> is the PHP version name that will be shown in the Plesk UI. We recommend that you include the version number in thedisplayname
, for example, you can name the version "5.3.3-custom".-path
<path to php cgi> is the location of the PHP CGI binary file. You can find this in the output of the commandmake install
in the line Installing PHP CGI binary. For example, if you see the line Installing PHP CGI binary: /usr/local/bin/, the location you need to specify is /usr/local/bin/php-cgi. Learn more at http://php.net/manual/en/install.unix.commandline.php.-clipath
<path to php cli> is the location of the PHP CLI binary file. You can find this in the output of the command make install in the line Installing PHP CLI binary. For example, if you see the line Installing PHP CLI binary: /usr/local/bin/, the location you need to specify is /usr/local/bin/php. Learn more at http://php.net/manual/en/install.unix.commandline.php.-phpini
<path to php.ini> is the location of thephp.ini
file, for example,/some/path/php.ini
.-type
<php handler> is the type of the PHP handler associated with this version. Learn more about PHP handlers in the section PHP Handlers.Note: Important: Either the CGI or FastCGI PHP handler can be set. mod_php is not supported.
- (Optional)
-id
<NN-custom> is the identifier that you will use for referring to this PHP version when adjusting or removing it.
After you register the PHP version in Plesk, it will be available for selection in service plan settings (Service Plans > plan name > PHP Settings) and in the PHP settings individual websites (Websites & Domains > PHP Settings). See the picture below.
Note: The aforementioned example is for CGI handlers. If FPM handler is needed, some extra information such as the <service name> the <path to the pool.d directory> will be needed.
More information on this can be seen through the command below:
# /usr/local/psa/bin/php_handler --help
Check our official Plesk documentation in order to install your custom PHP version.
Comments
26 comments
hello i want to update PHP version because my laravel app version is newer then plesk version,please give me solution.
Hello @final coat app!
As I can see the most recent Laravel version requires PHP 7.1.3 or higher. Such PHP versions are provided by Plesk Onyx and may be installed at Tools & Settings > Updates and Upgrades > Add/Remove Components.
In case you have Plesk 12.5 or lower, the easiest solution would be to Upgrade to Plesk Onyx.
In case you want to install custom PHP version manually, follow the steps from this article.
thanks for replay,
my plesk version is onyx 17.5.3 (1.png) and in plesk server PHP version is 7.0.30 but my composer says your plesk version is 5.4.16 (2.png) ,please give me solution . see below images
Hello @final coat app, the reason of such behavior is that composer uses OS PHP version, not the PHP version set for subscription.
You may upgrade system PHP at your own risk. Alternatively, consider migration to Plesk server with OS supplied by more modern PHP version out of the box.
but my OS PHP version is 7.2.1 and plesk server version is 7.0.30 but error still come on composer update.composer show PHP version is 5.4.16
@final, could you, please, show the output of the following commands:
plesk -v
php -v
What would be the proper way to remove / rollback an installation made with the instructions in this article?
Besides, what if a new PHP configuration option is needed after installation?
Hello @Cirrus Tecnologia,
> What would be the proper way to remove / rollback an installation made with the instructions in this article?
1. Find ID of registered PHP
/usr/local/psa/bin/php_handler --list
2. Unregister PHP from Plesk
/usr/local/psa/bin/php_handler --remove ID_from_step_1
3. Optionally:
Remove folder where PHP was compiled
> Besides, what if a new PHP configuration option is needed after installation?
Compile PHP again with new option
Please update this page so old php 5.6x will be useable with ubuntu 18.04. that comes only with php 7.2
Unfortunately I tried the above step and plesk show me PHP 5.6-40 but the domain was not able to connect to the Database.
Might someone help with this last step so this php5.6.40 addition will actually work?
/usr/local/psa/bin/php_handler --add -displayname <NN> -path <path to php cgi> -phpini <path to php.ini> -type <php handler> -id <NN-custom> -clipath <path to php cli>
@Robert
This command was successfully used on my test machine:
/usr/local/psa/bin/php_handler --add -displayname 5.6.40 -path /usr/local/php56/bin/php-cgi -phpini /usr/local/lib/php.ini -type fastcgi -id PHP5.6.40 -clipath /usr/local/php56/bin/php
Check the following article, it is possible that mysql socket is not specified for 5.6.40: https://support.plesk.com/hc/en-us/articles/213394269-Unable-to-open-a-website-after-switching-to-additional-PHP-Error-establishing-a-database-connection
Yes this might include php 5.6, but has no mysql connection.
Please talk to your plesk colleague as i have received a working installation guide.
@Robert
Just checked - it was needed to add the mysql module to the new PHP handler. Glad that you have found the cause!
After weeks I succeeded, I put the link of the commands to run on centos to install plesk with php + argon2
https://github.com/xdasty/plesk-php-argon2
@dasty,
This may help other Plesk users, thank you.
Hi a working guide to fix the mysql connection would be nice. Could you update the article please!?
Thanks for your help
Peer
Hi @Peer Hoffmann
Could you please elaborate on this? Please send me the error message, may be we have another article for your issue
this link does not work:
https://support.plesk.com/hc/en-us/articles/213394269-Unable-to-open-a-website-after-switching-to-additional-PHP-Error-establishing-a-database-connection
Hi @kriskrkpl,
The article was deleted due to being non-actual.
I would suggest you checking other ones.
can you help me find an article that fixes the problem described in the article above?
@kriskrkpl,
As a troubleshooting step, try switching PHP version on a affected domain to another one in Domains > example.com > PHP Settings.
In case it'll make a trick, the most possible cause is that mysql socket isn't specified in php.ini for the previous chosen version of PHP.
The socket can be specified either in Plesk UI in Tools & Settings > PHP Settings > PHP 5.6 (chose the version according to your needs) or via command line:
php.ini
file:# grep -ir mysql.sock /opt/plesk/php/5.6/etc/php.ini |grep -v ';'
mysql.default_socket = /var/lib/mysql/mysql.sock
Note: for Debian 9 the socket path should be
/var/run/mysqld/mysqld.sock.
The path to php.ini should be adjusted according to the PHP version.Re-apply PHP settings on a domain in Domains > example.com > PHP Settings after changes in main php.ini file.
If it won't help, submit a ticket to the Support Team to look deeper into the issue.
Hi Anzhelika,
I am using Ubuntu 18.04. I am trying to install and register PHP5.3.29
I received no errors in the install or registration with Plesk.
I am getting the same mysql issue as above.
My php.ini file for 5.3.29 included the uncommented mysql.default_socket = line. Inserting the /var/lib...... did not fix the issue. Also, PHP 5.3.29 is installed in /usr/local/php-5.3.29, will that change anything?
In Tools & Settings > PHP Settings > PHP 5.3.29 no extensions are shown either. Do I have to install mysql for php5 as well as the other extensions?
Hi Nathan,
If you don't have mysql or mysqli extension, then at least one of them should be installed to be able to establish MySQL connections when using this PHP.
> In Tools & Settings > PHP Settings > PHP 5.3.29 no extensions are shown either.
As for this issue, try to run this command:
Then, log in to Plesk as admin and go to Tools & Settings - Server Components and click "Refresh".
If it does not help, I suggest you contacting support at https://support.plesk.com/hc/en-us/requests/new.
For all that are in the need to compile PHP 5.6.0 to a plesk version so all will work including MYSQL:
This quire worked nice on my INTEL CPU machine with Ubuntu 18.04.
Plesk add custom PHP 5.6 with mysql module support on Ubuntu 18 (Intel cpu) :
1. Unpack sources
wget https://www.php.net/distributions/php-5.6.40.tar.gz
gunzip php-5.6.40.tar.gz
tar -xf php-5.6.40.tar
cd php-5.6.40/
2. Install and configure required libraries:
apt-get install libbz2-dev libcurl4-gnutls-dev libdb-dev libenchant-dev libjpeg-turbo8-dev libpng-dev libxpm-dev libfreetype6-dev libgmp-dev libgmp3-dev libc-client-dev libkrb5-dev libmcrypt-dev unixodbc-dev libsqlite3-dev libedit-dev libreadline-dev libtidy-dev libxslt-dev php-dev
ln -s /usr/include/x86_64-linux-gnu/curl /usr/include/curl
ln -s /usr/include/x86_64-linux-gnu/gmp.h /usr/include/gmp.h
3. Configure PHP:
./configure --prefix=/opt/plesk/php/5.6.40 --bindir=/opt/plesk/php/5.6.40/bin --sbindir=/opt/plesk/php/5.6.40/sbin --libexecdir=/opt/plesk/php/5.6.40/lib --datadir=/opt/plesk/php/5.6.40/share --sysconfdir=/opt/plesk/php/5.6.40/etc --sharedstatedir=/opt/plesk/php/5.6.40/com --localstatedir=/opt/plesk/php/5.6.40/var --libdir=/opt/plesk/php/5.6.40/lib/x86_64-linux-gnu --includedir=/opt/plesk/php/5.6.40/include --infodir=/opt/plesk/php/5.6.40/share/info --mandir=/opt/plesk/php/5.6.40/share/man --build=x86_64-linux-gnu --host=x86_64-linux-gnu --with-libdir=lib --cache-file=../config.cache --with-config-file-path=/opt/plesk/php/5.6.40/etc --with-config-file-scan-dir=/opt/plesk/php/5.6.40/etc/php.d --disable-debug --without-pear --with-pic --disable-rpath --with-bz2 --with-freetype-dir=/usr --with-png-dir=/usr --with-xpm-dir=/usr --enable-gd-native-ttf --without-gdbm --with-gettext --with-gmp --with-iconv --with-jpeg-dir=/usr --with-openssl --with-zlib --with-layout=GNU --enable-exif --enable-ftp --enable-sockets --enable-sysvsem --enable-sysvshm --enable-sysvmsg --with-kerberos --enable-calendar --with-libxml-dir=/usr --enable-xml --enable-phpdbg --with-enchant=shared,/usr --with-litespeed --enable-pcntl --with-imap=shared --with-imap-ssl --enable-mbstring=shared --enable-mbregex --with-gd=shared --enable-bcmath=shared --enable-dba=shared --with-xmlrpc=shared --enable-mysqlnd=shared --with-mysql=shared,mysqlnd --with-mysqli=shared,mysqlnd --with-mysql-sock=/var/run/mysqld/mysqld.sock --enable-dom=shared --enable-soap=shared --with-xsl=shared,/usr --enable-xmlreader=shared --enable-xmlwriter=shared --with-curl=shared,/usr --enable-pdo=shared --with-pdo-odbc=shared,unixODBC,/usr --with-pdo-mysql=shared,mysqlnd --with-pdo-sqlite=shared,/usr --with-sqlite3=shared --enable-json=shared --enable-zip=shared --without-readline --with-libedit --enable-phar=shared --with-mcrypt=shared,/usr --with-tidy=shared,/usr --with-unixODBC=shared,/usr --enable-fileinfo=shared --enable-intl=shared --with-icu-dir=/usr --enable-sysvmsg=shared --enable-sysvshm=shared --enable-sysvsem=shared --enable-posix=shared build_alias=x86_64-linux-gnu host_alias=x86_64-linux-gnu
4. From here we get patch to make 5.6 work with openssl 1.1:
https://github.com/oerdnj/deb.sury.org/issues/566
wget http://zettasystem.com/PHP-5.6.31-OpenSSL-1.1.0-compatibility-20170801.patch
patch -p1 < PHP-5.6.31-OpenSSL-1.1.0-compatibility-20170801.patch
5. Complilation:
make
make install
6. Done, now a bit of PHP ocnfiguration + adding modules:
mkdir -p /opt/plesk/php/5.6.40/etc/php.d
cp php.ini-production /opt/plesk/php/5.6.40/etc/php.ini
7. Enable mysql module:
cd ./ext/mysql
phpize
./configure --with-php-config=/opt/plesk/php/5.6.40/bin/php-config
make
make install
printf "zend_extension=opcache.so\nextension=mysqlnd.so\nextension=bcmath.so\nextension=curl.so\nextension=dba.so\nextension=dom.so\nextension=enchant.so\nextension=fileinfo.so\nextension=gd.so\nextension=imap.so\nextension=intl.so\nextension=json.so\nextension=mbstring.so\nextension=mcrypt.so\nextension=mysql.so\nextension=mysqli.so\nextension=odbc.so\nextension=pdo.so\nextension=pdo_mysql.so\nextension=pdo_odbc.so\nextension=pdo_sqlite.so\nextension=phar.so\nextension=posix.so\nextension=soap.so\nextension=sqlite3.so\nextension=sysvmsg.so\nextension=sysvsem.so\nextension=sysvshm.so\nextension=tidy.so\nextension=xmlreader.so\nextension=xmlrpc.so\nextension=xmlwriter.so\nextension=xsl.so\nextension=zip.so" >> /opt/plesk/php/5.6.40/etc/php.ini
8. Register in Plesk:
/usr/local/psa/bin/php_handler --add -displayname 5.6.40 -path /opt/plesk/php/5.6.40/bin/php-cgi -phpini /opt/plesk/php/5.6.40/etc/php.ini -type fastcgi -id 5.6.40 -clipath /opt/plesk/php/5.6.40/bin/php
Thank you @Robert,
This may be useful for other Pleskians.
Ivan, i hope this guide still works as on my new sever Amd cpu I had some trouble with icu and intl library
Yes, it should work, thought we did not test it on all possible configurations (
Please sign in to leave a comment.