• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Question Help me understand PHP on Plesk

Caz

New Pleskian
Hi all,

I'm currently tinkering with Magento 2.3.5-p1 on Plesk Onyx 17.8.11.

I am having trouble executing commands for Magento. When trying to execute php commands, I get a message saying: Magento supports 7.1.3 or later.

I have the website/domain setup in Plesk to use version 7.3.20 - So how do I use it in terminal?

When typing php -v it produces the following [which I think may be the issue?]:

PHP 7.0.33-0ubuntu0.16.04.15 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with the ionCube PHP Loader (enabled) + Intrusion Protection from ioncube24.com (unconfigured) v10.0.3, Copyright (c) 2002-2017, by ionCube Ltd.
with Zend OPcache v7.0.33-0ubuntu0.16.04.15, Copyright (c) 1999-2017, by Zend Technologies
 
If you run the php command you wil run de default PHP version from the OS. You can run the different PHP versions that are managed by plesk simply by using /opt/plesk/php/7.3/bin/php.

So for example
Code:
/opt/plesk/php/7.3/bin/php -f /home/user/script.php
 
Last edited:
It's correct if we create an alias without -f ?
alias php='/opt/plesk/php/7.3/bin/php'
alias composer='/opt/plesk/php/7.3/bin/php /usr/lib64/plesk-9.0/composer.phar'

in my case I need to execute composer for install magento extension and I get back an error. The composer that I should execute is on the root of magento should be different path like that one ?

alias composer='/var/www/vhosts/mydomain.com/subdomain.omydomain.com/composer.phar'
Which one is the correct ?
 
If you run the php command you wil run de default PHP version from the OS. You can run the different PHP versions that are managed by plesk simply by using /opt/plesk/php/7.3/bin/php.
Or you could use update-alternatives to change it permanently. E.g.
Code:
update-alternatives --install /usr/bin/php php /opt/plesk/php/7.4/bin/php 74
update-alternatives --install /usr/bin/phar phar /opt/plesk/php/7.4/bin/phar 74
update-alternatives --install /usr/bin/phar.phar phar.phar /opt/plesk/php/7.4/bin/phar.phar 74
 
Hi Mow,
If I update permanently the path to php, that's mean that I can execute composer without PHP's path ?
 
If I update permanently the path to php, that's mean that I can execute composer without PHP's path ?
That updates the OS default, so yes, you would just run "php whatever".

alias only works for commands though, not arguments, so
alias composer='/var/www/vhosts/mydomain.com/subdomain.omydomain.com/composer.phar'
wouldn't help.
We usually cd to the magento directory and then just run php composer.phar.
 
Thank you Mow, just one more question...

Or you could use update-alternatives to change it permanently. E.g.
Code:
update-alternatives --install /usr/bin/php php /opt/plesk/php/7.4/bin/php 74
update-alternatives --install /usr/bin/phar phar /opt/plesk/php/7.4/bin/phar 74
update-alternatives --install /usr/bin/phar.phar phar.phar /opt/plesk/php/7.4/bin/phar.phar 74
this will change permanently for all the domains/sites ? Because some domain works on php 5.4 and can't be upgraded . Then I should create a permanent alias instead update alternatives?
We usually cd to the magento directory and then just run php composer.phar.
it's mandatory update alternatives for Magento property use ?
It seams that use the right php simplify run commands , install extensions also check php and don't match, also my cronjob is setting in Plesk schedule task.
Do you set there too ?
 
this will change permanently for all the domains/sites?

this will change the shell command "php" for the whole server. Web is not affected as php-fpm et al. do not go through the shell expansion at all as plesk starts them directly.
So if you never do anything by shell in the other subscriptions, they will not be affected.

it's mandatory update alternatives for Magento property use ?
It seams that use the right php simplify run commands , install extensions also check php and don't match, also my cronjob is setting in Plesk schedule task.
Do you set there too ?
We have set the cronjobs via "crontab -e subscriptionuser" and we use the full path to php in there because in crontab you should use full paths anyway as you can't rely on the PATHs being set as they would in the shell. And it's just best practice to avoid nasty surprises.
 
Back
Top