How to check PHP version and configuration

ByJUJU-dev

How to check PHP version and configuration

How to check PHP version and configuration

There are two ways to check PHP version set for the account. By default, we have PHP 5.6 set on our shared servers.
To check what PHP version is selected for your account go to cPanel Software section > Select PHP version menu:

How to check PHP version and configuration
You will see the current PHP version above PHP extensions:

How to check PHP version and configurationAnother way to check PHP version is PHPinfo() function, commonly used to check the current state of PHP configuration. It can also be used for debugging purposes as it contains all EGPCS (Environment, GET, POST, Cookie, Server) data.

for cPanel Basic theme:

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

How to check PHP version and configuration

2. Navigate to public_html directory, click on New File and create a phpinfo.php file:

How to check PHP version and configuration

How to check PHP version and configuration

3. Find the newly created file in the list and click on Code Editor:

How to check PHP version and configuration

4. Add the lines of the code provided below to the file and click on Save Changes:

<?php
phpinfo();
?>

How to check PHP version and configuration

5. To see the detailed information about PHP configuration of your account, open http://yourdomain.com/phpinfo.php link in your browser, replacing yourdomain.com with your main domain name.

NOTE: For security reasons, do not forget to delete the file once you check all the necessary information.

for cPanel Retro theme:

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

How to check PHP version and configuration

2. Navigate to the public_html directory, click on New File and create a phpinfo.php file:

How to check PHP version and configuration

3.Find the newly created file in the list and click on Code Editor:

How to check PHP version and configuration

4. Add the lines of the code provided below to the file and click on Save Changes:


<?php
phpinfo();
?> 

How to check PHP version and configuration

5. To see the detailed information about PHP configuration of your account, open http://yourdomain.com/phpinfo.php link in your browser, replacing yourdomain.com with your main domain name.

NOTE: 
For security reasons, do not forget to delete the file once you check all the necessary information.

That’s it!

ByJUJU-dev

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!

ByJUJU-dev

LSPHP directive for php.ini on shared servers

The LSPHP directive is a powerful tool for managing PHP versions on shared servers. Here’s what you need to know:

What is LSPHP?

LSPHP (Linux Shared PHP) is a module that allows you to manage multiple PHP versions on a single server, giving you more flexibility and control over your PHP configurations.

How does LSPHP work?

LSPHP creates a separate PHP-FPM (FastCGI Process Manager) instance for each PHP version, allowing you to run multiple PHP versions simultaneously. This enables you to switch between different PHP versions for different domains or subdomains.

Configuring LSPHP

To configure LSPHP, you’ll need to edit the php.ini file and add the following directives:

[lsphp]
; Set the PHP version
php_version = 7.4

; Set the document root for this PHP version
document_root = /path/to/document/root

; Set the socket file for this PHP-FPM instance
listen = /path/to/socket/file

; Set the user and group for this PHP-FPM instance
user = username
group = groupname

Replace php_version with the desired PHP version (e.g., 7.4, 7.3, or 5.6), and document_root with the path to your website’s document root.

Enabling LSPHP

To enable LSPHP, add the following line to your httpd.conf file (or apache2.conf on Ubuntu-based systems):

Include /path/to/lsphp.conf

Restart Apache

After making changes to the configuration files, restart Apache to apply the changes:

sudo service apache2 restart

Switching between PHP versions

To switch between PHP versions, simply update the php_version directive in your php.ini file and restart Apache.

For example, if you want to switch from PHP 7.4 to PHP 7.3:

[lsphp]
php_version = 7.3

Then, restart Apache:

sudo service apache2 restart

Tips and considerations

  • Make sure to update the php.ini file for each domain or subdomain that requires a specific PHP version.
  • You can have multiple LSPHP instances running on the same server, allowing you to run different PHP versions for different domains or subdomains.
  • Be cautious when updating the php.ini file, as it can affect all domains or subdomains using that PHP version.
  • If you’re not familiar with LSPHP configuration, consider consulting your hosting provider’s documentation or seeking assistance from their support team.

By mastering LSPHP, you can gain more control over your PHP configurations and take advantage of the latest features and security patches.

ByJUJU-dev

PHP modules and extensions on shared hosting servers

On a shared hosting server, the availability of PHP modules and extensions can vary depending on the hosting provider and the specific plan you’re using. However, here’s a general overview of the most common PHP modules and extensions that are typically available on shared hosting servers:

PHP Core Modules

  1. ctype: Provides functions for checking and manipulating character types.
  2. date: Functions for working with dates and times.
  3. fileinfo: Provides information about file types and contents.
  4. filter: A filtering system for input data.
  5. gd: Library for image manipulation.
  6. iconv: Character set conversion functions.
  7. json: JSON encoding and decoding functions.
  8. mcrypt: Encryption and decryption functions.
  9. mysql: MySQL database extension.
  10. openssl: SSL/TLS encryption functions.
  11. pcre: Perl-compatible regular expressions.
  12. pdo: PHP Data Objects for database interactions.
  13. ** Reflection**: Object reflection and introspection.
  14. session: Session management functions.
  15. spl: Standard PHP Library for working with arrays, strings, and other data types.

Additional PHP Extensions

  1. apcu: Alternative PHP Cache Userland Extension (a caching system).
  2. curl: CURL library for transferring data over HTTP, HTTPS, FTP, etc.
  3. domxml: Document Object Model (DOM) parser for XML files.
  4. exif: EXIF metadata reader and writer for images.
  5. fannypdf: PDF generation and manipulation library.
  6. ftp: FTP client library.
  7. gd2: Image manipulation library (successor to gd).
  8. imagick: ImageMagick library for image manipulation.
  9. ioncube_loader: IonCube loader for encoded PHP code.
  10. mhash: Message-Digest Algorithm 5 (MD5) hash functions.
  11. oci8: Oracle Database extension.
  12. pgsql: PostgreSQL database extension.
  13. soap: SOAP web services extension.
  14. wddx: WDDX (Web Distributed Data Exchange) serialization format.

Third-Party Extensions

Many third-party extensions are also available, which can be installed manually or through the cPanel control panel’s “PHP Select Python” interface:

  1. Xdebug: A debugging extension for PHP code.
  2. XCache: A caching system for improving performance.
  3. Zend Guard: An obfuscation tool for protecting PHP code.

Keep in mind that not all hosting providers may have all these extensions available, so it’s essential to check with your hosting provider to see which ones are supported on your specific plan.

If you need a specific extension not listed here, you can try contacting your hosting provider to see if they can install it for you or recommend an alternative solution.

ByJUJU-dev

How to change PHP version on shared servers

Changing PHP version on a shared server can be a bit tricky, but it’s doable. Here’s a step-by-step guide to help you through the process:

Before you begin:

  1. Check if you have access: Make sure you have the necessary permissions and access to modify the server configuration.
  2. Check the hosting provider’s documentation: Familiarize yourself with your hosting provider’s documentation on how to change PHP versions.

Method 1: Using cPanel (if available)

  1. Log in to your cPanel account.
  2. Click on the “Software” section and select “MultiPHP Manager”.
  3. Click on the “Select PHP Version” dropdown menu and choose the desired PHP version from the list.
  4. Click “Update” to apply the changes.
  5. Restart your website or reload the page to ensure the changes take effect.

Method 2: Using .htaccess file (if cPanel is not available)

  1. Log in to your file manager (e.g., FileZilla) and navigate to your website’s root directory.
  2. Open the .htaccess file and add the following lines at the end:
<IfModule mod_php7.c>
    PHPIniDir /path/to/php.ini
</IfModule>

<IfModule mod_php8.c>
    PHPIniDir /path/to/php8.ini
</IfModule>

Replace /path/to/php.ini and /path/to/php8.ini with the actual paths to your PHP configuration files.

Method 3: Using SSH (if you have SSH access)

  1. Connect to your server using SSH.
  2. Navigate to your website’s root directory using the command cd /path/to/website.
  3. Create a new file called php.conf with the following contents:
<?php
php_flag[display_errors] = On
php_value[error_reporting] = E_ALL
?>

This sets PHP’s error reporting level to E_ALL and displays errors. 4. Save the file and then update the Apache configuration by running:

sudo /usr/local/apache/bin/apachectl restart

This restarts Apache and applies the changes.

Verify PHP version

To verify that you have successfully changed the PHP version, you can use one of the following methods:

  1. Check your website’s phpinfo() function: Create a new file with a .php extension (e.g., info.php) and add the following code:
<?php phpinfo(); ?>

Open this file in a web browser to see the PHP information, including the version. 2. Check your hosting provider’s control panel: If you’re using a control panel like cPanel, you can check the PHP version from there.

Remember to always test your website after changing PHP versions to ensure everything is working as expected.

Keep in mind that changing PHP versions can affect your website’s functionality, so be cautious when making these changes, especially if you’re not familiar with PHP or have a complex setup.