frame

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Register

How To Change PHP Settings

LawrenceLawrence Member
edited May 2017 in Linux Applications


Introduction

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.


Requirements

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.


Reviewing

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

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 it:
<?php
phpinfo();
?>
Now you can visit page we created in your web browser and find all PHP configurations:

http://your_domain.tld/info.php

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.


Modifying

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:
post_max_size = 8M
upload_max_filesize = 2M
The default values to maximum file upload size:
post_max_size = 8M
upload_max_filesize = 8M
The amount of memory PHP can use:

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


Conclusion

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.
Tagged:
Sign In or Register to comment.

Time4VPS

Learn how to install a web and database server, email, FTP client or other applications. Discover and share information on server security or optimization recommendations.
Feel free to join our constantly expanding community, participate in discussions, strengthen your knowledge on Linux and Windows server management!
© 2013 - 2024 Time4VPS. All rights reserved.

Get In Touch