• We value your experience with Plesk during 2024
    Plesk strives to perform even better in 2025. To help us improve further, please answer a few questions about your experience with Plesk Obsidian 2024.
    Please take this short survey:

    https://pt-research.typeform.com/to/AmZvSXkx
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

Question Is it possible to change the server php version

TomP

Basic Pleskian
II am using Version 18.0.21 of Plesk on a centos server. I've been trying to do a variety of tasks on my Drupal sites using composer from a command line. One of the utilities I want to run will not accept that I'm using any version of php accept the one in the path that came installed:
/opt/plesk/php/5.6/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin

I ran the commands using the prefix: /opt/plesk/php/7.3/bin/php /usr/lib64/plesk-9.0/composer.phar as suggested, but it still errors out saying it can't use php 5.6.40.

I've tried to get my server tech support to answer this, but they seem like it's not possible to change the 5.6 version to 7.3. Is it possible to change it? If so how? Will it break Plesk or the server?
 
I would NOT recommend to change the base PHP version of your OS. Many components are depending on this PHP version.

You can try my suggestion below. I have been using composer on different PHP versions of Plesk without any issues.

I'm not sure which OS you are using,

In CentOS, you can create these files in the 'Home Directory' of the subscription. This is not the httpdocs directory, 'Home Directory'

.profile
Code:
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'
cd httpdocs

.bashrc
Code:
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'
cd httpdocs

Path of /opt/plesk/php/7.3/bin/php should be changed according to your OS.

Then you can change 'Access to the server over SSH' to '/bin/bash' and run the composer commands. Login to SSH of this subscription.

Eg- composer require aaaa/bbbbb

You can verify the the paths by

-bash-4.2$ php -v

This should show you the PHP version which you are trying to use.

(Please note any changes to the above files will not reflect while you are login in to the Bash. You will have to logout and login or run the .profile manually.)
 
Last edited:
Yes I'm using centos so that should work. I'll give it a try once I get back to my computer. So far it's been one program that failed. I was trying to use gocomposer to convert my 8.7 site over to a 8.8 one using composer from now on. Every time I try it fails because it only sees the 5.6 php version. I'm going to give your suggestion a try next.
 
/opt/plesk/php/7.3/bin/php /usr/lib64/plesk-9.0/composer.phar as suggested, but it still errors out saying it can't use php 5.6.40

Had the same problem some time ago.
.profile
Code:
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'
cd httpdocs
.bashrc
Code:
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'
cd httpdocs

This solved the problem for me back then.

Problem by just using "/opt/plesk/php/7.3/bin/php" is that the thing you execute is most probably using the shoprtcut "php" inside it. So this will use the standard PHP version which is set for this User. Pls change it like @AusWeb show above and execute again.

After this, you can just execute it with "php" without having to use "/opt/plesk/php/7.3/bin/php".
 
The solution here does work - kind of. For some reason, somewhere buried in the drush scripts it is still finding the server php version. Once it sees it, it crashes saying my php is too old. Apparently I'm not the only one that's pointed this out to the drush/drupal people. I found other forum posts talking about the same thing. All would be solved if I could just get rid of the old php, but I don't want to break plesk in the process.
 
What does:
"update-alternatives --config php"
displays?


And what:
"cd /etc/alternatives"
"ls -ls | grep php"

If you want to Hard-Set "php" to any other PHP-Version you can do so by doing this:

  1. Make a full backup as this may break you System

"cd /etc/alternatives"
"unlink php"
"ln -s /opt/plesk/php/7.3/bin/php php" (change to any PHP Version you want)

This will unlink the old PHP-Link (probably "/usr/bin/php7.0") and set the new one as "php"
But I honestly dont know if this will cause any problems as Plesk itself most probably will rely on PHP 7.0

Normally your script cant find "the old PHP Version" once its changed for the user which is executing the script.
Probably the script calls "php" as another user inside the script?
If the script is editable just replace all "php" calls with "/opt/plesk/php/7.3/bin/php php" this would be the cleanest solution!

If you try this, pls report back
 
What does:
"update-alternatives --config php"
displays?


And what:
"cd /etc/alternatives"
"ls -ls | grep php"

If you want to Hard-Set "php" to any other PHP-Version you can do so by doing this:

  1. Make a full backup as this may break you System

"cd /etc/alternatives"
"unlink php"
"ln -s /opt/plesk/php/7.3/bin/php php" (change to any PHP Version you want)

This will unlink the old PHP-Link (probably "/usr/bin/php7.0") and set the new one as "php"
But I honestly dont know if this will cause any problems as Plesk itself most probably will rely on PHP 7.0

Normally your script cant find "the old PHP Version" once its changed for the user which is executing the script.
Probably the script calls "php" as another user inside the script?
If the script is editable just replace all "php" calls with "/opt/plesk/php/7.3/bin/php php" this would be the cleanest solution!

If you try this, pls report back

Thanks for the info, but that sounds kinda scary. I might give that a try, but first I think I'll try and get ahold of the people that maintain Drush and see if they know where this could be happening within the code. Maybe they have a quick code fix for me.
If I end up trying your suggestion, I will post the results.
 
Try this,

Delete both .profile and .bashrc files from the 'Home Directory' If you have already created them.

Create a new file in the 'Home Directory' called .bash_profile with the content,

.bash_profile
Code:
export PATH=/opt/plesk/php/7.3/bin:$PATH
alias composer='/opt/plesk/php/7.3/bin/php /usr/lib64/plesk-9.0/composer.phar'
cd httpdocs

Logout and Log back in, if you are already logged in to bash.

or Run, $ . ~/.bash_profile In the 'Home Directory'

If everything ok, $which php and $php -v should show you the path and the php version.

There is a different between export and alias. I think this should work for you.
 
Last edited:
Try this,

Delete both .profile and .bashrc files from the 'Home Directory' If you have already created them.

Create a new file in the 'Home Directory' called .bash_profile with the content,

.bash_profile
Code:
export PATH=/opt/plesk/php/7.3/bin:$PATH
alias composer='/opt/plesk/php/7.3/bin/php /usr/lib64/plesk-9.0/composer.phar'
cd httpdocs

Logout and Log back in, if you are already logged in to bash.

or Run, $ . ~/.bash_profile In the 'Home Directory'

If everything ok, $which php and $php -v should show you the path and the php version.

There is a different between export and alias. I think this should work for you.

I did as suggested. Sorry, but both 'which php' and 'php -v' come back as: /opt/plesk/php/5.6/bin/php. The other way showed pointing to 7.3 when I used 'php -v'. Which php always showed 5.6.
 
Firefox_Screenshot_2020-01-05T05-29-08.365Z.png

Firefox_Screenshot_2020-01-05T05-23-55.812Z.png


This is not possible. Do you have any other dot files (.) other than .bash_profile in Home Directory of this subscription? Current example using PHP 7.1
 
Last edited:
Sorry I can't insert the image, but this my home dir with the .profile and.bashrc (see attached)

I'll try the .bash_profile again today.
 

Attachments

  • hom-dir.jpg
    hom-dir.jpg
    24.9 KB · Views: 12
Yes, delete the .profile and.bashrc files and create the .bash_profile as i have described in the previous post. You should be ok.
 
I removed both files.
I added .bash_profile:
export PATH=/opt/plesk/php/7.3/bin:$PATH
alias composer='/opt/plesk/php/7.3/bin/php /usr/lib64/plesk-9.0/composer.phar'
cd httpdocs​

I logged out then back in.
php -v and which php both show version 5.6.

Yes this is really starting to get frustrating. Not you helping me, just my server and it's antique php version.
 
One last try,

What is your output for,

# cd /opt/plesk/php/7.3/bin

As Root user?


[root@server2 httpdocs]# cd /opt/plesk/php/7.3/bin
[root@server2 bin]# pwd
/opt/plesk/php/7.3/bin
[root@server2 bin]# dir
lsphp pear peardev pecl phar phar.phar php php-cgi phpdbg
 
I have no idea what is happening.

Specially when you claim you get PHP 5.6 and its the Plesk path.

I have been using command line PHP for many projects with Plesk. Never had and any issues.

Are you login to 'Bash' with the same user as the this subscription? I'm just wondering
 
I have no idea what is happening.

Specially when you claim you get PHP 5.6 and its the Plesk path.

I have been using command line PHP for many projects with Plesk. Never had and any issues.

Are you login to 'Bash' with the same user as the this subscription? I'm just wondering

Yes I'm doing all this while logged in as the user for the site.
Everything works great except when I'm trying to use Drupal's utility: Drush. It's the main reason I started all this. Composer seems to be happy with the setup using the .bashrc and .profile as stated. Somewhere in the drush program it's finding the old php version then it crashes.
 
What does:
"update-alternatives --config php"
displays?


And what:
"cd /etc/alternatives"
"ls -ls | grep php"

If you want to Hard-Set "php" to any other PHP-Version you can do so by doing this:

  1. Make a full backup as this may break you System

"cd /etc/alternatives"
"unlink php"
"ln -s /opt/plesk/php/7.3/bin/php php" (change to any PHP Version you want)

This will unlink the old PHP-Link (probably "/usr/bin/php7.0") and set the new one as "php"
But I honestly dont know if this will cause any problems as Plesk itself most probably will rely on PHP 7.0

Normally your script cant find "the old PHP Version" once its changed for the user which is executing the script.
Probably the script calls "php" as another user inside the script?
If the script is editable just replace all "php" calls with "/opt/plesk/php/7.3/bin/php php" this would be the cleanest solution!

If you try this, pls report back
I looked into my /etc/alternatives directory and there is no php listed there.
 
Back
Top