How to Edit PHP Settings in Apache on an Ubuntu 18.04 VPS or Dedicated Server

How to Edit PHP Settings in Apache on an Ubuntu 18.04 VPS or Dedicated Server

PHP settings are controlled by a file named ‘php.ini’. The configuration file is read when Apache web server starts. To change the default PHP settings, you should edit the ‘php.ini’ file and restart your web server.

Out-of-the-box, PHP settings work pretty well but customizing the configuration file allows you to select what can work best for you depending on your hardware architecture and software design.

In this guide, we are going to show you how to edit the basic PHP settings on your Apache web server running on Ubuntu 18.04 VPS.


  • A VPS Plan (visit HostAdvice’s VPS reviews for the best VPS providers)
  • A non-root user with sudo privileges
  • Apache web server
  • PHP

Step 1: Determine the Location of your php.ini File

From time to time, you will need to manage the critical php.ini file. The file location may vary a bit depending on the PHP version running on your server.

The configuration file is located on:


For instance, if you are running PHP 7.0, the file will be located on:


The same case applies to PHP 7.2. You can find the configuration file at:


Step 2: Opening the PHP configuration file for editing

Once you determine the location of your file, the next step is editing it using a nano editor. Use the command below to open the file:

$ sudo nano php_ini_file

For instance:

$ sudo nano /etc/php/7.2/apache2/php.ini

Step 3: Making changes on the php.ini file

As mentioned at the beginning of the article, the default PHP settings may work for the majority of websites or web applications. However, your environment may demand some values to be tweaked a bit to ensure that your website is running smoothly.

In most cases, you will be editing the below PHP settings:

PHP max_execution_time

This sets the maximum execution time in seconds that a PHP script is allowed to run before it is terminated. Sometimes, you might have demanding scripts that should run for a few minutes and you need to change this value. The default value is 30 seconds but you can set it to a larger value

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 directive is 2M (two Megabytes). This value controls the maximum size of files that you upload using PHP scripts. Sometimes, it is necessary to change this value if you anticipate uploading big files.

For instance, if you are uploading a large database via phpMyAdmin, you will need to change this value.

Default value:


Change to a large value e.g. 16M


PHP post_max_size

This value limits the amount of data allowed on post data. It usually 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 e.g.

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 VPS. 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 VPS

memory_limit = -1

PHP Error Reporting Settings

You can control the behavior of error reporting in PHP using the below directives:

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 (

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


In this guide, we have discussed how to locate and edit PHP settings on your Ubuntu 18.04 server. We have also taken you through the basic settings that you should tweak to optimize the performance of your website or web applications. We believe that the changes you make on your PHP configuration file will help you to have a smoother environment for running your websites.


Check out these top 3 VPS services:

£3.16 /mo
Starting price
Visit Kamatera
Rating based on expert review
  • User Friendly
  • Support
  • Features
  • Reliability
  • Pricing
£2.36 /mo
Starting price
Visit Hostinger
Rating based on expert review
  • User Friendly
  • Support
  • Features
  • Reliability
  • Pricing
Liquid Web
£3.95 /mo
Starting price
Visit Liquid Web
Rating based on expert review
  • User Friendly
  • Support
  • Features
  • Reliability
  • Pricing

How to Install Apache and PHP-FPM on Debian 8

How to install the Apache web server with PHP-FPM (FastCGI Process Manager) on a
5 min read
Michael Levanduski
Michael Levanduski
Expert Hosting Writer & Tester

How to Install Apache Cassandra on an Ubuntu 18.04 VPS or Dedicated Server

This tutorial will help you install and configure Apache Cassandra (an opensourc
3 min read
Max Ostryzhko
Max Ostryzhko
Senior Web Developer, HostAdvice CTO

How to Configure Nginx and Apache on the same Ubuntu VPS or Dedicated Server

Nginx and Apache are great and powerful web servers. However, they both have dra
2 min read
Idan Cohen
Idan Cohen
Marketing Expert

How to Host Multiple Websites on an Ubuntu 18.04 VPS or Dedicated Server

This article will show you how to host two or more websites on a single Virtual
5 min read
Idan Cohen
Idan Cohen
Marketing Expert provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top