Software Development

How to Change PHP Configuration on a Dedicated Server

How to Change PHP Configuration on a Dedicated Server

PHP initially started as a small open source project that evolved as awareness spread about its versatility and usefulness. Rasmus Lerdorf created PHP way back in 1994.

PHP scripts are written, executed on the server, processed, and embedded in HTML. PHP can be integrated with popular databases. These include MySQL, Microsoft SQL Server, Oracle, etc. The latest release is version 8.13, released in February 2022.

There are many web hosting services that provide hosting with PHP and MySql. If you are looking to do your own coding via PHP, then a dedicated hosting plan is for you.

Changing the PHP configuration on a dedicated server will require you to edit the PHP.ini  file on the server. This guide will show you how to alter PHP configuration on an Apache Web Server. Read on for more information on how to edit an ini file.

How to View Your Current PHP Settings.

There is a built-in function called phpinfo() within PHP for viewing PHP settings. This can be useful if you need to check on the default PHP settings. It also comes in handy to follow up on changes in the PHP settings.

A file named phpinfo.php needs to be created to view the PHP settings.

Follow these steps for creating the file.

Step 1: Log in to the cPanel

Look for the File Manager option in the files section of the cPanel. Open it and navigate to the directory you are working with. This is an essential step as each folder can actually have different PHP settings.

In the top menu, locate the +File option in the top menu to create a new file. Type in phpinfo.php when prompted for a file name. It can be named anything as per your preference.

Once you locate the phpinfo.php file, right-click on it and choose the edit option.

  • A ‘Text Editor’ prompt will pop up. This is the PHP configuration editor. Select ‘utf-8’ from the drop-down list and select Edit.
  • The next step would be to enter the following code into the phpinfo.php file.
  • <? phpinfo(); ?>
  • Once that is done, click Save Changes

Step 2: Access the PHP File

Now that the phpinfo page has been created, you can proceed to access it and view the PHP settings. This page can be accessed on the browser. If the file was created in the public_html folder, type the URL https://example.com/phpinfo.php in the address bar.

Use ‘Ctrl+F’ and search for memory_limit to look for any specific value of the setting. The first value that you come across is the local value and is set for the current directory. The setting value is also referred to as the master value.

The local value is the setting that you are looking for. It is the critical value as the local values override the master value.

PHP Settings on the Apache Webserver

For global settings, the Apache Webserver uses the httpd.conf file and the .htaccess file for directory access settings. In older versions of Apache, the httpd.conf file was split up into access.conf, httpd.conf, and srm.conf, and some users prefer this arrangement.

If you have performed a standard installation, then the httpd.conf file can be found at /etc/httpd/conf.This is the default configuration file path of the php.ini file on the Apache Webserver.

PHP Settings on the Nginx Webserver

Text-based configuration files are used by Nginx to govern its behavior. The default location is usually /etc/nginx/. You may also find a few different config files here, though the location may vary depending on the installation settings. The primary configuration file is nginx.conf.

  • The Nginx configuration folder default location is:
  • /etc/nginx/
  • This is the most likely default location for all typical installations.

Also read: 15 Websites To Test Online Your Codes

How to Adjust Server-wide PHP Settings/limits

If you select the basic mode tab, you can specify the default PHP version to be set for all accounts created from this point on and the existing accounts affected by the change in the default PHP version.

If any of the cPanel accounts are required to use a different PHP version from the System one, you can specify that too. The user can alter most PHP settings in the MultiPHP Manager and MultiPHP INI Editor menus in the WHM.

WHM MultiPHP Manager

The WHM MultiPHP Manager allows the user to interface easily with the PHP FastCGI Process Manager (PHP-FPM) and PHP configurations of your system and those of the cPanel accounts.

In addition, the user can also manage the PHP version, PHP-FPM settings, and the PHP INI directives of the host.

WHM MultiPHP INI Editor

The MultiPHP INI Editor in the cPanel allows you to make changes to the configuration with regard to the PHP settings. The INI Editor complements the MultiMHP Manager that enables you to change the PHP version of your sites. The MultiPHP INI Editor has Basic and Editor modes.

How to Change the php.ini File Settings on a Dedicated Server

The PHP settings are managed in a file named ‘php.ini’. The Apache webserver reads this file whenever it starts. Altering the default apache PHP settings will require you to edit the ‘php.ini’ file and restart the webserver. To edit the ‘php.ini’ file, access to the files and SSh login is required. The phi.ini location is in the cPanel.

If you’re looking to configure the php.ini on Ubuntu, it can be done fairly straightforwardly. The information shared below will help you locate the PHP configuration file (php.ini).

Run the following command to bring up the php.ini file with the terminal open. This is the php.ini location in ubuntu.

  • sudo nano /etc/php5/apache2/php.ini
  • The default php.ini location in Linux is /etc/php.ini. To edit the php.ini, you need to type in sudo mcedit /etc/php5/cli/php.ini.

Increasing PHP memory in the php.ini

If you get the error message ‘The uploaded file exceeds the upload_max_filesize directive in php.ini’, you will need to increase the memory limit in the php.ini file.

PHP memory_limit

This directive controls the amount of memory a script may consume. The value specified should be greater than your file size.

The

PHP ‘memory_limit’ default value is usually 128M. Below par PHP scripts may consume a high amount of the server’s memory. This will lead to a spillover effect and affect other applications running on the dedicated server. To avoid this, the amount of memory allocated to a script is controlled by the PHP ‘ memory_limit.’

Once you are done editing the php.ini file, close the file after saving your work. The server should be restarted for the settings to take effect.

How to Install and Enable Custom Modules

A PHP module is an extension of PHP that allows for more features within PHP

The following prerequisites are necessary to install PHP modules:

  • A server with PHP installed.
  • Administrative or sudo permissions on the server.
  • The PHP-CLI module.

Steps to install the module:

First, verify the PHP version and existing modules on the server with the following command line:

yum list installed | grep -i PHP

Now you can install the chosen module with the line:

yum install<module>

For enabling the PHP module, add the following line:

extension = extension name.so

How to adjust single cPanel account PHP settings/limits

Occasionally you may need to tweak PHP settings like upload size, post size, memory limit, execution time, etc., to ensure the proper functioning of the Websites. All this can be done via the cPanel. Simply navigate to the Select PHP Version under the Software section.

Before you can tweak the PHP settings, the PHP file must be created similar to when you need to view the settings. Open the FileManager on the cPanel, navigate to the directory and create the phpinfo.php file. Now you can add the below code and save the file.

<?php phpinfo(); ?>

Also read: Top 5 Free Tools to Monitor Your website Changes

How To Change PHP Error Reporting Settings.

There is a possibility of a PHP application producing errors during its execution. Developers should be able to spot these errors to carry out the troubleshooting process. PHP applications, however, stop functioning as intended instead of highlighting the mistakes.

The surefire way to display all php errors and warnings is to include these line to your PHP code:

ini_set(‘display_errors’, 1);

ini_set(‘display_startup_errors’, 1);

error_reporting(E_ALL);

The display_errors and display_startup_errors directives are just two of the available directives. The objective of display_errors directive is to determine if the errors are to be displayed or hidden from the user. The display_startup_errors is a separate directive that handles errors at startup.

Steps to Format the Current Date and Time in PHP

When developing websites, you will undoubtedly have to work with dates and times. Time and date stamps are used to track when blog posts were uploaded, track changes to the website, and even display countdown timers for special events.

Thankfully, PHP comes with in-built date and time functions. They are quite handy for displaying time and date stamps in various formats.

The most commonly used data and time function available in PHP is the date($format, $timestamp). The first parameter is the desired output format for the date and an integer for the timestamp value. This value is converted to the specified date format.

While the second parameter is optional, omitting it will display the current time and date in the string format.

The $format parameter accepts a series of characters as valid values. These characters usually have straightforward meanings. Y displays the numeric representation year in 4 digits (2022), while y will display only the last two digits of the year (22). Similarly, H displays the hour in 24-hour format, while h will display the hour only in the 12-hour format.

Also read: 20 Best Free Website Builders for Small Business

Common Problems when Updating your php.ini file

Even though an updated version of PHP will bring tangible benefits like enhanced stability and security, there may be the occasional bugs that accompany a PHP version upgrade. There are some ways in which these errors can be countered.

  • Deprecation errors may crop when you view your website after a PHP upgrade. This happens because certain functions or features used by your site have been removed. Modifying the site code to suit the update or reverting to the previous PHP version are options.
  • If you get a “500 Internal Server Error” after updating the PHP version on your website, access the .htaccess file in your public_html directory. At the end of the .htaccess file, you should see text similar to the following:

# Start A2 Switcher Block

# Do not remove or modify this block! Added by PHP Switcher from cPanel to use an alternate PHP version. Contact Support for details.

<IfModule mod_suphp.c>

AddHandler application/x-httpd-php-8.0.0.php

</IfModule>

# End A2 Switcher Block

The AddHandler value is the PHP version of your site. You should ensure that the correct version is specified and the formatting is proper. Lines of text may have been merged depending on how the .htaccess file was configured. This could cause errors as well.

Conclusion

In this guide, we have shared how the PHP settings are located and edited. The basic settings that you should tweak to optimize the performance of your website or web applications have been elaborated upon. The procedure to track and troubleshoot errors has been highlighted as well. This will further help to complement the other PHP programming techniques shared.

If you decide to go through with the suggested changes on your PHP configuration file, you will be guaranteed a smoother experience while running your websites.

FAQs: PHP Configuration on a Dedicated server

 How to Edit a php.ini File?

The domain level php.ini file can be edited using the Plesk Control Panel. Follow the steps outlined below for editing the php.ini file.

  1. First, select the Websites and domain tab.
  2. Next, expand the advanced options and select PHP settings from the menu.
  3. You will find the most common PHP directives available on this page and ready to be modified. The most common options can be selected from the drop-down menus, or you can also create your own by using the “Custom Variable” option.
  4. Click “OK” at the bottom to save.

Users can edit the domain-level php.ini file by following the below steps.

  1. Click on the Websites and domain tab.
  2. Expand the advanced options.
  3. Select PHP settings from the menu.
  4. Users can select the most common options from the drop-down menus or create their own with the “Custom Variable” option.
  5. Click “OK” to save.

 How to Locate the php.ini in the cPanel?

The php.ini file is usually located in the domain root directory(public_html folder). This is its default location. It can be accessed by opening the File Manager section under Files in the cPanel.

 How to Change the PHP Version on a Dedicated Server?

  1. Changing the PHP Version on a dedicated server is usually done in the Web Host Manager or WHM.
  2. Log into WHM (Web Host Manager). Accessing WHM
  3. Use the search field to search for EasyApache or the webserver you are using.
  4. Look for the customized option to alter the profile.
  5. On the next page, avoid any changes unless you wish to change the Apache version.
  6. Choose your PHP version on the next page and proceed.
  7. On the final page, you can enable any mods or extensions or scroll down and click on Save.
  8. As soon as you click Save, the server will take approximately 15 minutes to recompile, and then Apache will briefly restart.

If you are looking to change the PHP Version on the cPanel, then carry out the following steps:

  1. After logging into the cPanel, click on the select ‘PHP Version’ icon.
  2. Here the PHP version for your account can be changed by selecting the appropriate version from the drop-down menu.
  3. You can choose from the list of available PHP versions. Once you’re done, you can click on Save.
Written by
Aiden Nathan

Aiden Nathan is vice growth manager of The Tech Trend. He is passionate about the applying cutting edge technology to operate the built environment more sustainably.

Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Articles

Linux Development
Software Development

Linux Development Acceleration for Ubuntu, RedHat, and Fedora

You’re either a Linux fan or you aren’t – either way, you’ll...

Modern Contact Centers
Software Development

Securing the Front Lines: Advanced Cybersecurity for Modern Contact Centers

In the digital age, where customer interactions have moved predominantly online, contact...

Medical Software
Software Development

An Overview of the Most Common Types of Medical Software

Imagine a healthcare system where information flows freely, tasks run smoother, and...

Navigating MVP Development
Software Development

Navigating MVP Development: Strategies, Innovation, and Agile Integration

New products appear on the market every day, and most of them...