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' ):
In order to manually create a service for the PHP handler the *.service file from the downloaded source needs to be copied to the local configuration
# cp /root/php-X.X/sapi/fpm/php-fpm.service /etc/systemd/system/php-fpm-X.X.service
enable and start the service:
# systemctl enable php-fpm-X.X.service
# systemctl start php-fpm-X.X.service
# systemctl status php-fpm-X.X.service# 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
12 comments
Hi
Followng this article (and some additional help from https://talk.plesk.com/threads/unable-to-start-service-unable-to-manage-service-by-phpinimng.369863/) I was able to add and run PHP 7.1 (FPM) on a Plesk Obsidian 18.0.52 update3 (Debian 11.7).
However in the Plesk Tools&Settings / PHP settings / 7133-phpfpm page the EXTENSION TAB remains empty
Whatever I write in the PHP.ini (the second tab) phpinfo shows me that mysqli is not loaded.
I tried to add the following lines without success:
extension=msql.dll
extension=msql.so
extension=mysqli
extension=php_mysqli
extension=php_mysqli.dll
Maybe the solution was to compile the PHP 7.1 WITH the extensions as I could understand it on your § 1.4 but then what is the right syntax to add mysqli please?
I tried without success:
thanks for your help
Cyril
@Cyril this requires investigation, please create a ticket to Plesk Technical support
Alexander Tsmokalyuk
Yes I already created https://talk.plesk.com/threads/custom-php-7-1-with-extensions.370131/
thanks
Hi, did you manage to solve the problem?
we are experiencing the same difficulty after installing the PHP version following instructions from Plesk....
I'll leave it here:
./configure --prefix /opt/plesk/php/7.2 --enable-fpm --with-fpm-group=www-data --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd
after that in info.php mysqli and pdo_mysql appeared, I didn't do anything in php.ini.
I think the situation is the same with other extensions. An example of installation can be taken from the "Configure Command" section of any version of PHP available for installation and in the Plesk panel.
Hi,
Followed this article, however, Im stuck by point 2 further down it says:
-service
<PHP FPM service name>: It's the PHP FPM service nameWhat do I actually put as the service name? It doesn't take spaces and simply PHP-FPM errors out 'service not found'.
Appreciate any clarification
Hi J L
The service name can be fpm5.6-custom or 5.6fpm, you can name the service according to your preference. White spaces are not allowed, indeed. I will update the instructions accordingly.
Thanks Alex.
As suggested, I ended up doing just "fpm" as the service name and it was registered successfully.
JL
Hello, I followed the instructions but stuck with
plesk bin php_handler --add -displayname 5.6.40-custom -path /usr/local/5.6.40/bin/ -phpini /usr/local/lib/php.ini -type fpm -id 5.6.40-custom -clipath /usr/local/5.6.40/bin/ -service fpm5.6-custom -poold /usr/local/5.6.40/etc/
Message: 7583:65f709c00831b ERR [util_exec] proc_close() failed ['/usr/local/psa/admin/bin/php_handlers_control' '--add' '--path' '/usr/local/5.6.40/bin/' '--phpini' '/usr/local/lib/php.ini' '--type' 'fpm' ' --displayname' '5.6.40-custom' '--id' '5.6.40-custom' '--clipath' '/usr/local/5.6.40/bin/' '--service' 'fpm5.6-custom' '--poold' '/usr/local/5.6.40/etc/'] with exit code [1]
Unable to register the PHP handler: can not get version from /usr/local/5.6.40/bin/
Any idea what I did wrong
bernhard
plesk bin php_handler --add -displayname 5.6.40-custom -path /usr/local/5.6.40/bin/xxxx -phpini /usr/local/lib/php.ini -type fpm -id 5.6.40-custom -clipath /usr/local/5.6.40/bin/yyyy -service fpm5.6-custom -poold /usr/local/5.6.40/etc/
xxxx is the name of the fpm binary (ex. php-fpm)
yyyy is the name of the cli binary (ex. php56)
Hello all...
Here is my 5.6 command line and I am not sure what I have wrong:
plesk bin php_handler --add -displayname 56-custom -path /usr/local/php56/sbin/php-fpm -phpini /usr/local/lib/php.ini -type fpm -id 56-custom -clipath /usr/local/php56/bin/ -service fpm56 -poold /usr/local/php56/etc/
Steven Petrillo
-clipath /usr/local/php56/bin/yyyy
yyyy is the name of the cli binary (ex. php56)
Please sign in to leave a comment.