PHP is a server-side scripting language used by many popular CMS and blogging platforms such as WordPress and Drupal. It is also part of the popular LAMP and LEMP stacks. When setting up a PHP-based website, updating PHP configuration settings is a common task. Finding the exact PHP configuration file may not be easy. There are multiple PHP installations running normally on the server, and each installation has its own configuration file. Knowing which file to edit and what the current settings are can be a bit mysterious.
This guide will explain how to view the current PHP configuration settings of the web server and how to update the PHP settings.
For this guide, you need the following:
**Note: **This tutorial assumes that you are running Ubuntu 14.04. php.ini
should be the same to edit files on other systems, but the file location may be different.
All commands in this tutorial should be run as a non-root user. If the command requires root access, it will have sudo
in front.
You can view the real-time PHP configuration by placing pages and website files containing the phpinfo
function.
To create a file with this command, first switch to the directory containing the website files. For example, the default directory for Apache web files on Ubuntu 14.04 is /var/www/html/
:
cd /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:
info.php
<? php
phpinfo();?>
When accessing the file on the info.php
web server (http:// www.example.com /info.php), you will see a page that displays information about the PHP environment, operating system version, Details of the path and configuration setting values. The File on the right side of the "Configuration File Loaded" line shows the correct file to be edited in order to update the PHP settings.
This page can be used to display the current settings being used by the web server. For example, using the "Find" function of a web browser, you can search for settings named post_max_size and upload_max_filesize to view the current settings that limit the file upload size.
**Warning: **Because the info.php
file displays the operating system, web server and PHP version details, you should delete this file if you don't need to protect the server as secure as possible.
We can change the settings and configuration of PHP functions by editing the file php.ini
. This section provides some common examples.
Sometimes, PHP applications may need to allow larger upload files, such as uploading themes and plugins on a WordPress site. In order to upload a larger PHP application, use the following command to edit the file php.ini
(*Change the path and file to match your loaded configuration file. This example shows the path of Apache on Ubuntu 14.04. *):
sudo nano /etc/php5/apache2/php.ini
The default line to control file size upload is:
post_max_size = 8M
upload_max_filesize = 2M
Change these default values to the upload size of the largest file required. For example, if you need to upload a 30MB file, you can change these lines to:
post_max_size = 30M
upload_max_filesize = 30M
Other common resource settings including the amount of memory that PHP can use can be set to memory_limit
:
memory_limit = 128M
Or max_execution_time
, which defines the number of seconds the PHP process can run:
max_execution_time =30
After configuring the php.ini
file as needed, save the changes and exit the text editor.
Restart the web server to enable the changes. For Apache on Ubuntu 14.04, this command will restart the web server:
sudo service apache2 restart
Refresh the info.php
page and the updated settings should now be displayed. Remember to delete info.php
after finishing changing the PHP configuration.
Many PHP-based applications require minor changes to the PHP configuration. By using the phpinfo
function, you can easily find the exact PHP configuration files and settings. Use the methods described in this article to make these changes.
For more Ubuntu tutorials, please go to [Tencent Cloud + Community] (https://cloud.tencent.com/developer?from=10680) to learn more.
Reference: "How To Change Your PHP Settings on Ubuntu 14.04"
Recommended Posts