- Overview
- Available PHP Versions
- How to Update PHP
- Fix MultiPHP Error
- php.ini
- Limits
- View Settings
The php.ini file is a special file for PHP. It is where you declare changes to your PHP settings. The server is already configured with standard settings for PHP, which your site will use by default. Unless you need to change one or more settings, there is no need to create or modify a php.ini file. If you would like to make any changes to settings, please do so through the MultiPHP INI Editor.
- How To Modify PHP Settings
- How To Create a New php.ini File
How To Modify PHP Settings via the MultiPHP INI Editor
There may be times where you need to change some of the default PHP settings, and below we've outlined those steps. However, keep in mind that there are PHP Settings That Cannot Be Changed on our Shared, Cloud, & Reseller hosting.
To modify the PHP settings:
- Log in to cPanel.
- In the Software section, click on the MultiPHP INI Editor icon.
- On the MultiPHP INI Editor page, select Home Directory or the specific domain you wish to update from the Configure PHP INI basic settings dropdown.
- Select the new setting for each
PHP directive you would like to change.
- Click Apply at the bottom to save your changes.
How to Create a New php.ini File
Important Note: HostGator won't know why you want or need to change these settings. You would change this at the advice of your web designer or the developer of your script. HostGator can only show you where to make the change.
- For Plesk users, the file should already exist in the directory /var/www/vhost/$DOMAIN/etc/php.ini.
- For the cPanel, this file should be created in your Home directory (/home/username/).
The username is your actual cPanel username, and $DOMAIN is your actual domain.
To create a new php.ini file in your cPanel:
- In the
Files section of your cPanel, click on the File Manager icon.
- Select the root directory for your site. The default for the primary is public_html.
- Click the + File button at the top left of the page.
- In the pop-up box, enter php.ini in the New File Name field. Make sure the root directory is in the bottom box.
- Click Create New File.
- Locate and right-click the new php.ini file and select Edit, then click the Edit button again.
- You can now input the contents of your php.ini file. Click Save to save your changes.
Last updated on June 7th, 2022 | 2 replies
As there are multiple versions of PHP with different sever configurations, php.ini could be located in several different folders.
Method 1
One way to find out exactly which php.ini file your web sever is using is by creating a new PHP file in document root called info.php.
info.php
<?php phpinfo(); ?>Load this file in your browser, press CTRL + F (or Command + F on Mac) and search for “Loaded Configuration File”. You should see something like
/etc/php/8.1/apache2/php.ini
This will tell you the exact location of the php.ini file you want to edit.
Method 2
In Linux, run this command to locate the PHP.ini configuration file.
php -i | grep "Loaded Configuration File"
Or in Windows Command Line:
php -i | findstr /c:"Loaded Configuration File"
The result should be something like this:
Loaded Configuration File => /etc/php/8.1/cli/php.ini
In the above example, we can see that the PHP install is located in /etc/php/8.1. Note that there are three different configuration files you should we aware of:
CLI
/etc/php/8.1/cli/php.ini is for the CLI PHP program. Changes to this config file will only affect PHP as it runs in the terminal – it will NOT affect the web server.
Apache
/etc/php/8.1/apache2/php.ini is for the PHP plugin used by Apache. This is the one you need to edit if you are using the Apache web server.
Nginx or Apache with PHP-FPM
/etc/php/8.1/fpm/php.ini is a fastcgi-compatible ‘wrapper’ for PHP processing. This is the one you need to edit if you’re using the Nginx web server or Apache with PHP-FPM.
Method 3
Using the locate command in Linux,. If it’s not already installed, run sudo apt update && sudo apt install mlocate.
You should see a list of php.ini files here. Try editing one of them and restarting you web server to see if makes the required changes.
Editing php.ini in Linux
Apache
On Apache, php.ini is usually located in /etc/php/8.1/apache2/php.ini. Replace 8.1 with your own version, e.g, php5.6, php7.4, etc.
To edit:
sudo nano /etc/php/8.1/apache2/php.ini
However, if you are using PHP FPM, it may be located in /etc/php/8.1/fpm/php.ini. Replace 8.1 with your own version, e.g, php5.6, php7.4, etc.
To edit:
sudo nano /etc/php/8.1/fpm/php.ini
To save file and exit, press CTRL + X, press Y and then press ENTER
You must restart Apache after altering php.ini.
sudo systemctl restart apache2
If you are using PHP-FPM, you must restart that service. Replace php8.1 with your own version, e.g, php5.6, php7.4, etc.
sudo service php8.1-fpm restart
Nginx or Apache with PHP-FPM
Nginx uses PHP FPM and php.ini is usually located in /etc/php/8.1/fpm/php.ini. Replace 8.1 with your own version, e.g, php5.6, php7.4, etc.
sudo nano /etc/php/8.1/fpm/php.ini
Save and exit (press CTRL + X, press Y and then press ENTER)
You must restart Nginx after altering php.ini.
sudo systemctl reload nginx
Older Versions
For versions of Ubuntu lower than 16.04, /etc/php/5.6/,/etc/php/7.0/,/etc/php/7.1/, and so on, are replaced by /etc/php5/ and so on. Otherwise, these paths remain accurate.
Let me know if this helped. Follow me on Twitter, Facebook and YouTube, or 🍊 buy me a smoothie.
p.s. I increased my AdSense revenue by 200% using AI 🤖. Read my Ezoic review to find out how.