php.ini is a configuration file used by web servers to control PHP-related settings. This file contains the settings that are necessary for the correct execution of scripts and programs written with the PHP programming language.
The php.ini file is usually located in paths such as "/etc/php.ini" in Linux operating systems or "C:\php\php.ini" in Windows. But the exact path may be different in some distributions or installations. To find the exact location of the php.ini file on your system, you can refer to the documentation related to your web server or PHP installation. This file has various settings that can be changed by server administrators. Some important php.ini settings are as follows:
display_errors: Specifies whether PHP errors should be displayed as warnings.
error_reporting: Specifies which levels of PHP errors should be reported. You can use different values for this setting to enable or disable different error levels.
upload_max_filesize: This attribute specifies the maximum file size that users can send to the server through upload forms.
post_max_size: This parameter specifies the maximum size of POST data (submitted by forms) that can be sent to the server.
memory_limit: This parameter specifies the amount of memory allowed to execute a PHP script
The mentioned items are just some examples of the settings in the php.ini file. There are additional settings that can be changed by server administrators to meet the specific needs of applications and servers.
How to edit the php.ini file?
To edit the php.ini file, just follow the steps below:
Finding the location of the php.ini file: First, you need to find the location of the php.ini file in your system. Normally, this file is located in paths such as "/etc/php.ini" in Linux operating systems or "C:\php\php.ini" in Windows. But the exact path may be different in different distributions or installations.
Open the php.ini file: After finding the location of the php.ini file, you can use a text editor such as Notepad++, Sublime Text, Vim or any other editor and open the php.ini file.
Editing settings: In the php.ini file, you can find and edit the settings you want. For example, you can change the value of display_errors to On or Off, or change the value of upload_max_filesize to your desired size. In each setting, note that you must follow the syntax rules of PHP and set the values correctly.
Save the php.ini file: After applying the desired changes, save the php.ini file.
Restart the PHP service: After saving the php.ini file, you need to restart the PHP service for the changes to take effect. Depending on the type of operating system and PHP installation, you may need to run commands related to restarting Apache or Nginx.
The important thing to pay attention to is that before editing the php.ini file, it is better to create a backup copy of the file so that in case of an error, you can return to the previous state. Also, note that some settings may require administrative access (such as root access).
Restart the PHP service
To restart the PHP service after editing the php.ini file, you must stop and restart your web service. How to restart the PHP service depends on your operating system and installation. In the following, we will examine the usual methods for restarting the PHP service in common operating systems:
1. Restart Apache:
On Linux operating systems, use the following command:
sudo service apache2 restart
Or
sudo systemctl restart apache2
In Windows, right-click on the icon of WampServer, XAMPP, or whatever service you are using, and select "Restart".
2. Restart Nginx:
On Linux operating systems, use the following command:
sudo service nginx restart
Or
sudo systemctl restart nginx
In Windows, right-click on the Nginx icon and select "Restart".
3. Restart PHP-FPM:
On Linux operating systems, use the following command:
sudo service php-fpm restart
Or
sudo systemctl restart php-fpm
Note that in some cases, in addition to restarting the PHP service, it may be necessary to restart the web service (such as Apache or Nginx) for the changes to take effect.
How can we restart the web service for the changes in the php.ini file to take effect?
To restart the web service in order to apply the changes to the php.ini file, it depends on the type of web service and your operating system. In the following, we will examine the methods of restarting the web service in common operating systems:
1. Restart Apache:
On Linux operating systems, use the following command:
sudo service apache2 restart
Or
sudo systemctl restart apache2
In Windows, right-click on the icon of WampServer, XAMPP, or whatever service you are using, and select "Restart".
2. Restart Nginx:
On Linux operating systems, use the following command:
sudo service nginx restart
Or
sudo systemctl restart nginx
In Windows, right-click on the Nginx icon and select "Restart".
3. Restart the PHP-FPM service:
On Linux operating systems, use the following command:
sudo service php-fpm restart
Or
sudo systemctl restart php-fpm
4. Restart the IIS service (for Windows):
Right-click on "Computer" or "This PC" in the Start menu and select "Manage".
In the "Computer Management" window, in the "Services and Applications" section, click "Services".
In the list of services, find the "World Wide Web Publishing Service" service, right-click and select "Restart".
Note that in some cases, restarting the web service requires administrative access (such as root access on Linux). Also, how to restart the web service may differ between distributions and installations.
Create a backup copy of the php.ini file
To create a backup copy of the php.ini file, you can copy the file in the following ways:
1. Creating a backup in the command line (Linux and Windows):
On Linux, use the cp command:
cp /path/to/php.ini /path/to/backup/php.ini.backup
On Windows, use a similar command:
copy C:\path\to\php.ini C:\path\to\backup\php.ini.backup
2. Create a backup using file management (Windows):
Locate the php.ini file using a file management program such as Windows Explorer or Total Commander.
Right click on the php.ini file and select "Copy".
Right-click on the desired location to save the backup copy and select the "Paste" option.
By executing these commands, a backup copy of the php.ini file named php.ini.backup (or any other name you want) will be created in the desired location. This backup can be used to restore application changes if needed.
Can we create a backup automatically?
The answer is yes. You can automatically create a backup copy of the php.ini file. For this, you can use scripts and automatic operating system backup tools or systems management tools. In the following, we will examine two common methods for creating an automatic backup copy of the php.ini file:
1. Using scripts to automatically backup the operating system:
On Linux, you can use tools like rsync, cron, and tar to make automatic backups of the php.ini file.
On Windows, you can use tools like PowerShell or third-party backup programs like Acronis True Image.
2. Using system management tools:
On Linux operating systems, system management tools such as Ansible, Puppet, and Chef can be used to create automatic backups of the php.ini file.
On Windows, system management tools such as Microsoft System Center and PowerShell DSC can be used to create automatic backups of the php.ini file.
Using the above methods, you can create automatic and regular backups of the php.ini file and thus restore the changes and edits made in the php.ini file if needed.
How to use cPanel to create a backup?
To create a backup copy of the php.ini file using cPanel, you can use the features in the "Backup" section of cPanel. Next, I will explain the steps to create a backup copy:
1. Login to cPanel:
Open the browser and enter the address along with https://. Be careful not to forget /cpanel at the end after entering the site name and address.
Enter your cPanel username and password.
Click on "Login".
2. Search for the Backup section:
On the cPanel home page, in the "Files" section, click "Backup". In the "Files" section, the corresponding section may be named with other names such as "Backups" or "Backups & Restore".
3. Create a backup copy:
On the Backup page, there should be various options for creating a backup.
Some common options include "Backup", "Generate/Download Full Backup" or "Download a Home Directory Backup".
Click on the desired option and wait for the backup process to complete.
4. Download the backup:
After the backup is created, you will usually be shown a link to download the backup.
Click and download the backup copy and store it in a safe place.
Some cPanel settings may vary depending on your cPanel version and hosting settings. If in doubt, you can contact your hosting provider or refer to the cPanel documentation.
How to use Plesk to create a backup?
To create a backup copy of the php.ini file using Plesk, you can use the features in the "Backup Manager" section of Plesk. Next, I will explain the steps to create a backup copy:
1. Login to Plesk:
Open your browser and enter https://site_name.com:8443 (replace site_name with your actual website name).
Enter your Plesk username and password.
Click on "Login".
2. Search for the Backup Manager section:
On the main page of Plesk, in the left menu, click on "Backup Manager".
In some versions of Plesk, the corresponding section may be named with other names such as "Backup & Restore" or "Server Backup".
3. Create a backup copy:
On the Backup Manager page, there should be several options for creating a backup.
Some common options include "Back Up", "Create Backup" or "Backup Now".
Click on the desired option and wait for the backup process to complete.
4. Download the backup:
After the backup is created, you will usually be shown a link to download the backup.
Click and download the backup copy and store it in a safe place.
Some Plesk settings may differ depending on the version of Plesk and your host settings. If there is a problem, it is better to contact your hosting service provider or refer to the Plesk documentation.