This article will show you How to Make Changes to php.ini
Step 1: Determine the Location of your php.ini File
The configuration file is located in:
· /etc/php/php_version/apache2/php.ini
If you are running PHP 7.0, the file will be located on:
· /etc/php/7.0/apache2/php.ini
For PHP 7.2.
· /etc/php/7.2/apache2/php.ini
Step 2: Opening the PHP configuration file for editing
· $ sudo nano /etc/php/7.2/apache2/php.ini
Step 3: Making changes on the php.ini file
PHP max_execution_time
This sets the maximum execution time in seconds that a PHP script is allowed to run before it is terminated. The default value is 30 seconds
Default value:
· max_execution_time =30
Change to any value e.g. 1800
· max_execution_time =1800
PHP upload_max_filesize
The default value for this is 2 (two Megabytes). This value controls the maximum size of files that you upload using PHP scripts.
Default value:
· upload_max_filesize=2M
Change to a large value e.g. 16M
· upload_max_filesize=16M
PHP post_max_size
This value limits the amount of data allowed on post data. It affects PHP scripts that use a lot of web forms. The value also controls files uploaded via a PHP script, hence, it should always be larger than ‘upload_max_filesize’. The default value for ‘post_max_size’ is 8M.
Default value:
· post_max_size =8M
Customize it depending on your needs
· post_max_size =32M
PHP memory_limit
The default value for PHP 7.2 ‘memory_limit’ is 128M. Sometimes, poorly written PHP scripts may consume a lot of server’s memory and affect other applications running on your server. To avoid this, PHP ‘memory_limit’ controls the amount of memory allocated to a script.
Default value
· memory_limit = 128M
Custom value example
· memory_limit = 256M
You can also use -1 if you want to allocate an unlimited amount of memory to your PHP script depending on the available RAM on your server
· memory_limit = -1
PHP Error Reporting Settings
display_errors: Set this value to ‘On’ or ‘Off’ depending on whether you want PHP to display errors when scripts are run. In PHP 7.2 the default value is ‘Off’
· display_errors = Off
You can turn error reporting on by changing the value to ‘On’:
· display_errors = On
log_errors: This value tells whether errors from a script should be saved on the server’s log file. Instead of displaying errors to regular users in a production environment, you should log them. The default value in PHP 7.2 is ‘On’
· log_errors = On
You can switch error logging off by changing the value to:
· log_errors = Off
error_reporting: This directive dictates the error reporting level. For PHP versions greater than 5.3, the default value is ‘E_ALL & ~E_DEPRECATED & ~E_STRICT’
· error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
You may change the value depending on the errors that you want to be reported. For instance, to include notices, use the value below
· error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE
PHP Date/Time settings
You can also change the default timezone used by PHP scripts.
Find the line:
· $ ; date.timezone=
Uncomment it by removing the semicolon and then enter your preferred time zone. You can check the list of support time zones on the official PHP website (http://php.net/manual/en/timezones.php)
For instance, if you want to change the time zone to New York City, use the value below:
· date.timezone= “America/New_York”
Once you finish editing the php.ini file, press CTRL + X, Y and hit Enter to save the changes. You should also restart Apache for the settings to be reloaded using the command below:
· $ sudo service apache2 restart