Applicable to:
- Plesk for Linux
Question
How to add a custom PHP version in Plesk for Linux?
Answer
Warning: All the instructions below are to be performed at own will and risk. These steps are provided for demonstration purposes only and not supported by Plesk. Depending on the operating system and the desired configuration, installation steps might differ significantly. When installing an additional PHP version on the server, read the official PHP documentation on installation. It's recommended to perform the installation on a test environment before modifying the production environment.
On Linux systems, you can install any PHP version you need and then make it available in Plesk by registering it with the plesk bin php_handler
command-line utility.
Click on a section to expand
Install the desired PHP version on the 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.
-
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
-
-
Download the PHP source you need from the official website (http://php.net/downloads.php or http://php.net/releases/) to the server and unpack it:
# gunzip php-NN.tar.gz
# tar -xf php-NN.tar
-
Configure and build PHP:
Note: In this step, it's possible to customize PHP with various options, such as specifying which extensions will be enabled in the compiled PHP version. Run
./configure --help
to see a list of the available options.# cd ../php-NN
# ./configure --prefix /usr/local/phpNN --enable-fpm --with-fpm-group=www-data
# make
# make install
-
Set up the
php.ini
:Note: Edit the
.ini
file to set the desired PHP options. If it's required to configure thephp.ini
file in another location, run theconfigure
utility with the option--with-config-file-path=/some/path
in the previous step.# cp php.ini-development /usr/local/lib/php.ini
-
Connect to the server via SSH
-
Register the new PHP version in Plesk:
Note: More information can be found with the following command:
plesk bin php_handler --help
2.1- CGI/FastCGI example:
# plesk bin php_handler --add -displayname <NN> -path <path to php-cgi binary> -phpini <path to php.ini> -type <php handler> -id <NN-custom> -clipath <path to php cli>
Where:
-displayname
<NN>: It's the PHP version name that will be shown in the Plesk UI. It's recommended to include the version number in thedisplayname
, for example:7.4.5-custom
-path
<path to php-cgi binary>: It's the location of the PHP CGI binary file. The location is shown in the output shown by the commandmake install
in the line Installing PHP CGI binary. For example, if the output contains the line Installing PHP CGI binary: /usr/local/bin/, the location 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>: It's the location of the PHP CLI binary file. The location is shown in the output of the commandmake install
in the line Installing PHP CLI binary. For example, if the output contains the line Installing PHP CLI binary: /usr/local/bin/, the location to specify is /usr/local/bin/php. Learn more at: http://php.net/manual/en/install.unix.commandline.php-phpini
<path to php.ini>: It's the location of thephp.ini
file, for example:/usr/local/lib/php.ini
-type
<php handler>: It's the type of the PHP handler associated with the installed PHP version. This example is for cgi , fpm or fastcgi PHP handlers and the mod_php is not supported- (Optional)
-id
<NN-custom>: It's the identifier that will be used for referring to this PHP version when adjusting or removing it viaplesk bin php_handlers
utility
2.2- FPM example (Notes: systemctl unit should also be created manually, if it specific for OS distribution; To add the PHP handler as a dedicated application, append '-fpm-dedicated' to the hander ID when registering; To add PHP as a 'usual' FPM application, add the handler second time, without the '-fpm-dedicated' ):
# plesk bin php_handler --add -displayname <NN> -path <path to php-fpm binary> -phpini <path to php.ini> -type fpm -id <NN-custom> -clipath <path to php cli> -service <PHP FPM service name> -poold <path to php-fpm.d pool folder>
Where:
-path
<path to php-fpm binary>: It's the location of the PHP FPM binary file. The location is shown in the output shown by the commandmake install
in the line Installing PHP-FPM binary-service
<PHP FPM service name>: It's the PHP FPM service name-poold
<path to php-fpm.d pool folder>: It's the location containing the pool configuration files
Once the custom PHP versions are registered after applying the steps above, the custom PHP versions will be available:
-
Assign the custom PHP version:
-
Service Plan level: Go to Service Plans > Service Plan Name > PHP Settings
-
Domain level: Go to Domains > example.com > PHP Settings
-
Additional Information
Official Plesk documentation: Adding Custom PHP Versions (Linux)
Comments
40 comments
Hello Vương Công Minh
To unregister handler from Plesk you will need this command:
plesk bin php_handler --remove -id 123
ID 123 is n example, for more information use this documentation article: https://docs.plesk.com/en-US/obsidian/cli-linux/using-command-line-utilities/php_handler-php-handlers.72490/
Custom PHP version packages are to be removed from the server manually.
Hello
Here are the steps I have used to achieve the installation of php 5.6 on Debian 10 (Buster) with Plesk 18.0.29
Installation of PHP 5.6
- Source : https://deb.sury.org/
- Source : https://www.howtoforge.com/tutorial/how-to-install-php-7-for-ispconfig-3-from-debian-packages-on-debian-8-and-9/
Commands :
sudo apt update
sudo apt upgrade
sudo apt install ca-certificates apt-transport-https lsb-release
wget -q https://packages.sury.org/php/apt.gpg -O- | sudo apt-key add -
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
sudo apt update
sudo apt-get install php5.6 php5.6-cli php5.6-cgi php5.6-fpm php5.6-gd php5.6-mysql php5.6-imap php5.6-curl php5.6-intl php5.6-pspell php5.6-recode php5.6-sqlite3 php5.6-tidy php5.6-xmlrpc php5.6-xsl php5.6-zip php5.6-mbstring php5.6-soap php5.6-opcache libicu65 php5.6-common php5.6-json php5.6-readline php5.6-xml
/usr/local/psa/bin/php_handler --add -displayname 5.6.40 -path /usr/bin/php-cgi5.6 -phpini /etc/php/5.6/php.ini -type fastcgi -id 5.6.40 -clipath /usr/bin/php5.6
Hope it helps
Kind regards
Hello @moonone
Thank you for sharing this!
You're welcome ! @...
Don't hesitate to vote "yes" with the arrow up icon on any of those comments you find useful.
Regards
@Robert unfortunately php installed using your guide result in php files being downloaded instead of executed.
However this guide for Ubuntu 18 worked for me https://dx3webs.com/blog/enable-php-56-ubuntu-plesk-1804
How can I add the older PHP version in Plesk GUI as mod_php and not FastCGI ?
Thanks in advance
I tried following the instructions here and in the Official Documentation Page, to add PHP 8.1 as a handler, seeing that it will probably be a while before it becomes available in Plesk. However I would like to start testing it on some projects of mine, so I would like to be able to assign "PHP 8.1" to the subdomains of my choosing.
After installing PHP 8.1 on my system using Ondrej Sury's deb repository, and installing the related extensions, I ran this command:
However when attempting to select "PHP 8.1" for a subdomain I get this error:
Any ideas on what the problem could be or how to fix it?
John D'Orazio, I think you need to specify the php-fpm binary for the -path argument, not the cli php binary. In your case the argument would probably look like this:
Samuel Boczek thank you for pointing me in the right direction. Using the php-fpm binary in the -path argument, and also fixing the correct location of php.ini both made it work, I used this:
And now I can correctly assign PHP 8.1 to a subdomain without any errors.
hello i'm on ubuntu 14 and plesk 17.1 i need php 7.4 but the problem i cant format the server since there is a webmail service that it used by a client and cant stop it. is there a way to manually add php 7.4 because in 17.8 there is 7.3.5 but not 7.4 why ?
Please sign in to leave a comment.