How to change PHP settings on Ubuntu 14.04

Introduction

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.

prerequisites

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.

View PHP configuration

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.

Modify PHP configuration

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.

in conclusion

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

How to change PHP settings on Ubuntu 14.04
How to upgrade to PHP 7 on Ubuntu 14.04
How to change root user password on Ubuntu
How to install Ruby on Ubuntu 20.04
How to install Memcached on Ubuntu 20.04
How to install Java on Ubuntu 20.04
How to install MySQL on Ubuntu 20.04
How to install Elasticsearch on Ubuntu 20.04
How to install Protobuf 3 on Ubuntu
How to install Nginx on Ubuntu 20.04
How to install Node.js on Ubuntu 16.04
How to install MySQL on Ubuntu 20.04
How to install Bacula-Web on Ubuntu 14.04
How to install PostgreSQL on Ubuntu 16.04
How to install Git on Ubuntu 20.04
How to install Anaconda3 on Ubuntu 18.04
How to install Jenkins on Ubuntu 16.04
How to install MemSQL on Ubuntu 14.04
How to install Go on Ubuntu 20.04
How to install MongoDB on Ubuntu 16.04
How to install PrestaShop on Ubuntu 16.04
How to install Python 3.8 on Ubuntu 18.04
How to install KVM on Ubuntu 18.04
How to install KVM on Ubuntu 20.04
How to install opencv3.0.0 on ubuntu14.04
How to install Anaconda on Ubuntu 20.04
How to install Prometheus on Ubuntu 16.04
How to install Jenkins on Ubuntu 18.04
How to deploy Django on Ubuntu 14.04
How to install Apache on Ubuntu 20.04
How to install R on Ubuntu 20.04
How to install Moodle on Ubuntu 16.04
How to install Solr 5.2.1 on Ubuntu 14.04
How to install Teamviewer on Ubuntu 16.04
How to secure Nginx on Ubuntu 14.04
How to install Nginx on Ubuntu 20.04
How to install Mono on Ubuntu 20.04
How to install Go on Ubuntu 20.04
How to install Zoom on Ubuntu 20.04
How to uninstall software on Ubuntu
How to install Nginx on Ubuntu 16.04
How to install OpenCV on Ubuntu 20.04
How to install Spotify on Ubuntu 20.04
How to install Postman on Ubuntu 18.04
How to install Go 1.6 on Ubuntu 16.04
How to install Go on Ubuntu 18.04
How to install MySQL on Ubuntu 14.04
How to install PHP on CentOS 8
How to install PostgreSQL on Ubuntu 20.04
How to install VLC on Ubuntu 18.04
How to install TeamViewer on Ubuntu 20.04
How to install Webmin on Ubuntu 20.04
How to add swap space on Ubuntu 20.04
How to secure Redis installation on Ubuntu 14.04
How to build nfs service on ubuntu16.04
How to install Bacula Server on Ubuntu 14.04
How to optimize Tomcat installation on Ubuntu 14.04
How to replace apt-get source on Ubuntu 18.04
How to query Prometheus on Ubuntu 14.04 part 2
How to use Samba server on Ubuntu 16.04
How to install Ubuntu 19.10 on Raspberry Pi 4