How To Change PHP Settings
PHP is a server-side scripting language designed for web development but also used as a general-purpose programming language. Updating the PHP configuration settings is a common task when setting up a PHP-based website.
In this guide we will learn how to view the current PHP configuration settings and how to change them.
Note: In this tutorial we are working with Ubuntu. Editing the php.ini file should be the same on other systems, however file locations might be different.
There are many web server configurations with PHP, the most popular is LAMP. If you don't have the Linux, Apache, MySQL, PHP (LAMP) stack on your server, you can find the tutorial for setting it up here.
You can review current PHP configuration by pacing a page with a 'phpinfo' function in your server. To create a file with this command, first change into the directory that contains your website files. For example, the default directory for webpage files for Apache on Ubuntu is /var/www/html/:
Then, create the info.php file:
sudo nano /var/www/html/info.php
Paste the following lines into this file and save it:
Now you can visit page we created in your web browser and find all PHP configurations:
You should see something like this:
The file to the right of the Loaded Configuration File line shows the proper file to edit in order to update your PHP settings.
The php.ini file can be edited to change the settings and configuration of how PHP functions. Edit the php.ini file with the following command:
sudo nano /usr/local/lib/php70.ini
Note: Your path is shown right of the Loaded Configuration File line in your info.php page.
Most Common Needed configurations
The default lines that control the file size upload are:
The default values to maximum file upload size:
post_max_size = 8M
upload_max_filesize = 2M
The amount of memory PHP can use:
post_max_size = 8M
upload_max_filesize = 8M
memory_limit = 128M
How many seconds a PHP process can run for:
max_execution_time = 30
When you have the php.ini file configured for your needs, save the changes, and exit the text editor. Restart the web server to enable the changes:
service apache2 restart
Many PHP-based applications require slight changes to the PHP configuration. By using the phpinfo function, the exact PHP configuration file and settings are easy to find. Use the method described in this article to make these changes.