Open php ini in ubuntu

Alternatively execute the following command to locate the loaded php.ini configuration file for the command line (cli)

php --ini | grep Loaded
Loaded Configuration File:         /etc/php/7.3/cli/php.ini
3 command:

php --ini | grep Loaded
Loaded Configuration File:         /etc/php/7.3/cli/php.ini

Please, note that the above php.ini file location is used by

php --ini | grep Loaded
Loaded Configuration File:         /etc/php/7.3/cli/php.ini
3command. For the Apache web-server the above path will translate to:

The php.ini file is a default configuration file that read on PHP starts up. The PHP settings and configuration can be modified by the php.ini file.

If you want to change the PHP settings on Ubuntu, php.ini file is an easy and most effective way to do it. Follow the below steps to modify the PHP configuration file (php.ini) using the command line on Ubuntu.

  • Open the terminal and run the following command to open the php.ini file.
    sudo nano /etc/php5/apache2/php.ini
  • Change the PHP settings. For example, if you want to increase the execution time, increase the max_execution_time variable value in seconds.
    max_execution_time = 90
  • Once you modified the PHP configuration values as per your needs, save changes and exit editor.
  • Now restart the web server to enable the changes you have done.
    sudo service apache2 restart

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.

Prerequisites

  • 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:

/etc/php/php_version/apache2/php.ini

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

/etc/php/7.0/apache2/php.ini

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

/etc/php/7.2/apache2/php.ini

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:

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

/etc/php/7.0/apache2/php.ini
0

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

/etc/php/7.0/apache2/php.ini
1

Custom value example

/etc/php/7.0/apache2/php.ini
2

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

/etc/php/7.0/apache2/php.ini
3

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’

/etc/php/7.0/apache2/php.ini
4

You can turn error reporting on by changing the value to ‘On’:

/etc/php/7.0/apache2/php.ini
5

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’

/etc/php/7.0/apache2/php.ini
6

You can switch error logging off by changing the value to:

/etc/php/7.0/apache2/php.ini
7

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’

/etc/php/7.0/apache2/php.ini
8

You may change the value depending on the errors that you want to be reported. For instance, to include notices, use the value below

/etc/php/7.0/apache2/php.ini
9

PHP Date/Time settings

You can also change the default timezone used by PHP scripts.

Find the line:

/etc/php/7.2/apache2/php.ini
0

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:

/etc/php/7.2/apache2/php.ini
1

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:

/etc/php/7.2/apache2/php.ini
2

Conclusion

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.

How to access PHP ini in Ubuntu?

To open the default php. ini file for editing, use one of the following commands (depending on which Linux distribution you're using): Ubuntu 16.04: sudo nano /etc/php/7.0/apache2. CentOS 7: sudo nano /etc/php.

How do I view PHP ini?

The PHP ini file can be found in the displayed output of phpinfo() function and is labeled loaded configuration file.

How do I open a .ini file in Linux?

Solution for others who also faced such difficulty:.
Right click on your . ini file..
Choose 'open file with other applications'.
Press 'view all applications'.
Choose your text file editor. In my case it was called 'Text editor'..
Next time it should open it with a double-click, as per usual..

Where is Linux PHP ini?

ini file is the default configuration file for running applications that require PHP. It is used to control variables such as upload sizes, file timeouts, and resource limits. This file is located on your server in the /public_html folder.