Tag Archive change PHP version

How to change PHP version and update PHP extensions on Shared servers

How to change PHP version and update PHP extensions on Shared servers

In some cases, the correct functioning of your website depends on a PHP version installed on the server.
This guide describes how to change php version on Shared servers (Stellar, Stellar Plus plans and old Value, Professional, Ultimate plans). For Business SSD servers, use this guide.

Thanks to the PHP Selector function, it is possible to select the necessary PHP version as well as enable/disable certain PHP modules and functions.

To check what PHP version is currently in use, refer to this article.

Change PHP version and/or manage extensions

1. Log into your cPanel account.
2. Scroll down to the Select PHP Version:
For cPanel Basic Theme:
How to change PHP version and update PHP extensions on Shared servers

How to change PHP version and update PHP extensions on Shared servers

For cPanel Retro Theme:

How to change PHP version and update PHP extensions on Shared servers

3. Here you will see the list of available modules and extensions.

If you do not need to change the PHP version and just want to turn on/off specific extensions, you can do this by checking/unchecking the corresponding boxes.

Use the PHP Version drop-down box to select the required version, click on Set as current in order to apply the changes.

NOTE: The ‘native’ PHP version does not allow changing any options. You can set the desired values using a php.ini file:

How to change PHP version and update PHP extensions on Shared servers

4. To change individual settings within the PHP version in question, click on Switch to PHP Options.

By clicking on one of the options in grey, you will be presented with a drop-down list to change specific settings. Hit Apply to implement the settings:

How to change PHP version and update PHP extensions on Shared servers

NOTE 1: It is recommended to update your website scripts and use PHP 5.6. If the latest software you run for your websites is not yet compiled for PHP 5.6, please contact the script vendor for a compatibility patch.

NOTE 2: If you used a php.ini file for editing your account PHP configuration before, you will need to replicate the custom values using PHP Selector tool.

NOTE 3: In order to increase the max upload size, make sure to modify both post_max_size and upload_max_filesize values.

NOTE 4: max_execution_time can be increased up to 300 seconds.

Change PHP version for addon domain

Sometimes your website may need to use a different PHP version from the one assigned to your domain on your cPanel account.

To set a different PHP version for an addon domain, you need to add a special code to your .htaccess file. To do this, follow the steps below.

1. Find the .htaccess file for the addon domain in question. The steps for how to find it can be located here.

2. Add the following line to your .htaccess file:

<FilesMatch ".(?:html|php)$">
SetHandler application/x-lsphpXX
</FilesMatch>

where XX is the PHP version you wish to set. It can be 52, 53, 54, 55, 56, 70, 71,72, or 73.

For example:

How to change PHP version and update PHP extensions on Shared servers

3. Click “Save changes”.

NOTE: When a different PHP version is set for the addon domain, there are no PHP extensions enabled by default. To make a website work correctly, you will need to upload a php.ini file to the folder of the addon domain. You can check this article (see point 6) to help you with uploading files to the hosting account.You can download the php.ini file for different PHP versions from the Attachments section at the end of this guide. Do not forget to rename the file to php.ini once it is uploaded to the hosting account.

Alternatively, you can run the command below via SSH:

cp /opt/alt/default_php_ini/phpXX.ini /home/cPanel_username/path_to_the_folder/php.ini
  • XX is PHP version you wish to set (it can be 52, 53, 54, 55, 56, 70, 71, 72 or 73),
  • cPanel_username should be replaced with your actual cPanel username, and
  • path_to_the_folder is a path to the folder of the addon domain.

For example:

How to change PHP version and update PHP extensions on Shared servers

You can find details on how to access a hosting account via SSH here.

The process is similar if you wish to set a different PHP version for a subdomain.

How to install Composer on shared servers

How to install Composer on shared servers

Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on, and it will manage (install/update) them for you. Composer is not a package manager in the same sense as Yum or Apt are. Yes, it deals with ‘packages’ or libraries, but it manages them on a per-project basis, installing them in a directory (e.g., vendor) inside your project. By default, it will never install anything globally. Thus, it is a dependency manager.

To install Composer:

1. SSH access should be enabled for your hosting account with us. Follow the steps provided in this article to switch SSH access on.

2. To access your account via SSH, download and install one of the available SSH clients. You can find the list of free SSH clients here. In case you are using a Unix-based OS (Linux or OSX), you can easily run the Terminal application and connect to the server using the command:

ssh username@servername -pPORT

ssh – command for logging into the remote server
username – your cPanel username
servername– name of the server where your hosting account is located (you can find it using this tutorial)
PORT – connection port – 21098 for a Shared Hosting servers, 22 – for a VPS/Dedicated server 

3. Open your SSH client, put your domain name or the IP address of the server into the Host Name field, enter 21098 or 22 into the Port field, choose SSH as your connection type and press the Open button:

How to install Composer on shared servers
4. If you receive PuTTY Security Alert, press Yes:
How to install Composer on shared servers

When prompted, enter your cPanel username and password (when you enter the password, it is automatically hidden for security purposes):

How to install Composer on shared servers

5. Composer requires PHP 5.5+ version, so we need to check whether the needed version is set up. Type the php -v command in PuTTY (or in Terminal) and you will get the following output:

How to install Composer on shared servers

6. If you need to change PHP version, log in to your cPanel, navigate to Software and Services section >> Select PHP Version menu:

How to install Composer on shared servers

7. Select 5.5-7.2 version from the drop-down menu and then click on the Set as current button:

How to install Composer on shared servers

NOTE: Composer requires allow_url_fopen. It is enabled by default for all php versions on our shared servers. Still, you may check if it is On by going to Switch to PHP Settings in Select PHP version menu:

How to install Composer on shared servers

You can also find additional information about PHP selector here.

8. Next, navigate to the folder you want to install Composer in. In our example, we will install Composer in public_html:

cd public_html

How to install Composer on shared servers

9. Now, you will need to find or create the php.ini file and some values to it. Log in to cPanel and navigate File Manager menu:

How to install Composer on shared servers

10. Go to the folder your Composer will be installed in and create a new file named php.ini using the +File button:

How to install Composer on shared servers

11. Open it by right-clicking the created php.ini file >>  Edit:

How to install Composer on shared servers

12. Then add the following values to the file and hit the Save Changes button:

max_execution_time = 300
max_input_time = 300
memory_limit = 512M
suhosin.executor.include.whitelist = phar
detect_unicode = Off

How to install Composer on shared servers

13. When all the preparations are done, you are ready to install Composer. Open PuTTY window where you have logged into your cPanel account and fill in the following command:

php -r “readfile(‘https://getcomposer.org/installer’);” | php -c php.ini

This will execute the Composer installation:

How to install Composer on shared servers

To run composer commands use:
php composer.phar

How to install Composer on shared servers

In case you get a notification Some settings on your machine make Composer unable to work properly, make sure that the PHP version is 5.5 or higher and all the changes in the php.ini file are saved.

 

How to edit php.ini on Shared servers

How to edit php.ini on Shared servers

This guide describes how to edit the php.ini file on shared servers (Stellar and Stellar Plus plans, as well as old Value, Professional, and Ultimate plans).

If your account is hosted on the Business server (Stellar Business or old Business SSD plans), use this guide.
With the help of PHP Selector implemented on our Shared Hosting servers, you can easily modify basic PHP settings via your cPanel >> the Software section >> Select PHP Version menu. You can find detailed guidelines here.

 

However, advanced PHP settings are missing from the Select PHP Version tool and must be manually configured in the php.ini file. You can either create the file or upload the existing one to your account.

How to create a php.ini file

How to upload and edit an existing php.ini file

How to create a php.ini file

1. Log into your cPanel account, go to the Files section >> the File Manager menu.

For cPanel Basic Theme:

 

How to edit php.ini on Shared servers

For cPanel Retro Theme:

How to edit php.ini on Shared servers

2. Navigate to the root directory of the domain, click on New File, and create a file named php.ini:

How to edit php.ini on Shared servers

3. Find the newly created file in the list, right-click, and choose Edit:

How to edit php.ini on Shared servers

4. Add the required PHP settings and click on Save Changes in the top right corner:

How to edit php.ini on Shared servers

When all updates are completed, make sure to add lsapi_phpini directive.
To check the current PHP version and configuration, refer to this article.If you wish to change values for the PHP settings (e.g., max_execution_timememory_limitpost_max_sizeupload_max_filesize, etc.), you must reset the values in the Select PHP version menu. This way, it will be possible to overwrite PHP settings using php.ini.1. Log into your cPanel account, go to Software section >> Select PHP version menu.For cPanel Basic Theme:

How to edit php.ini on Shared servers

For cPanel Retro Theme:

How to edit php.ini on Shared servers

2. Go to the Switch to PHP Options menu:

3. Reset the option in question:

4. You may then apply changes to the required value in the php.ini file:

How to upload and edit an existing php.ini file

1. Log into your cPanel account, go to the Files section >> the File Manager menu.

For cPanel Basic Theme:

For cPanel Retro Theme:

2. Navigate to the root directory of the domain name in question, upload the php.ini file that corresponds to your current PHP version. Feel free to download php.ini for different PHP versions below in the Attachments section at the end of the guide.

3. Once done, use the Extract option:

4. After that, right-click on php.ini.txt to Rename it php.ini, then another right-click to use the Edit option:

5. Here, you can use the search option and find the needed limit or value. In this example, it is upload_max_filesize.

 

6. Once all the required changes are made, click Save.

In order for the php.ini to work, add lsapi_phpini directive.

That’s it!