14) Optimize PHP

<-- Previous    Next –>

The important parameter to look at in the php.ini file is memory_limit which controls how much memory is allocated to PHP.

Edit the php.ini file. This file will be located in the /php/ folder. Its location will depend on the version of PHP that you are running. In my case it is:

sudo nano /etc/php/7.3/apache2/php.ini

Check that the following are set and are not commented out with a semicolon character (;)

max_execution_time = 30
memory_limit = 128M
display_errors = Off
register_globals = Off

The 128M setting for memory_limit is a general guideline but should be sufficient for most websites although larger websites may require 256 megabytes or more.

Save the changes by pressing Ctrl-X and then pressing Y to save.

You may want to allow logging in which case the php.ini file should have the following:

log_errors = On
error_log = /var/log/php/error.log

Create the /var/log/php/ directory for the PHP error log with the following command:

sudo mkdir -p /var/log/php

Change the owner of the /var/log/php/ directory to www-data, which the PHP user runs as:

sudo chown www-data /var/log/php

Restart Apache using:

sudo service apache2 restart

The above assumes that logging is to the /var/log/php/ directory, but if you have installed a USB drive you may want to install this on the USB drive in which case the error_log setting in the php.ini file will be different.

<-- Previous    Next –>