Introduction
PHP is a widely-used server-side scripting language primarily designed for web development, though it also serves as a versatile general-purpose programming language. Updating PHP configuration settings is a routine task when setting up or optimizing a PHP-based website.
This guide walks you through viewing and modifying PHP configuration settings, focusing on Ubuntu. While the process is similar across different systems, file locations may vary.
Requirements
A common setup for PHP is the LAMP stack (Linux, Apache, MySQL, PHP). If your server doesn't have LAMP installed, you can follow a tutorial to set it up here.
Reviewing PHP Configuration
To review your current PHP configuration, create a file with the phpinfo
function. Start by navigating to your website’s root directory, typically _/var/www/html/_
for Apache on Ubuntu:
cd /var/www/html
Next, create a file named info.php
:
sudo nano /var/www/html/info.php
Add the following code to this file and save it:
<?php
phpinfo();
?>
You can then access this page through your web browser at http://your_domain.tld/info.php
, which will display all PHP configurations. Look for the "Loaded Configuration File" line to identify the correct php.ini
file for editing.
Modifying PHP Configuration
To change PHP settings, edit the _php.ini_
file specified in the phpinfo
output. Use the following command, adjusting the path if necessary:
sudo nano /usr/local/lib/php70.ini
Common PHP Configurations
Here are some commonly adjusted settings in the php.ini
file:
After making your changes, save the file and restart Apache to apply them:
service apache2 restart
Conclusion
Many PHP-based applications require specific PHP configuration adjustments. By using the phpinfo
function, you can easily locate and modify the relevant settings. Follow the steps in this guide to tailor PHP configurations to your needs.