When working with a PHP application, you might need to make some changes to the php.ini file. This file contains configuration settings that determine how the PHP interpreter behaves. But after making changes to the php.ini file, you may find that your modifications aren’t taking effect immediately. In this blog post, we’ll explain how to make your changes to the php.ini file take effect.
1. Locate Your PHP.INI File
Before making any changes to the php.ini file, you need to locate it on your server. The location of this file may vary depending on your server configuration and operating system.
To find the location of the php.ini file, create a new PHP file called phpinfo.php with the following code:
<?php phpinfo(); ?>
Upload this file to your server and access it through a web browser. The resulting page will display information about your PHP configuration. Look for the “Loaded Configuration File” row, which will show the path to the active php.ini file.
2. Make the Necessary Changes to the PHP.INI File
Open the php.ini file with a text editor and make the necessary changes. For example, you may want to increase the maximum file upload size. To do this, locate the following directives and modify their values as needed:
- upload_max_filesize – Sets the maximum size of an uploaded file.
- post_max_size – Sets the maximum size of a POST request, which should be larger than the upload_max_filesize.
Save your changes to the php.ini file.
3. Restart Your Web Server
After making changes to the php.ini file, you’ll need to restart your web server for the changes to take effect. The process for restarting your web server depends on your server environment and operating system. Here are some examples of how to restart common web servers:
Apache on Linux:
Run one of the following commands, depending on your system:
sudo service apache2 restart sudo /etc/init.d/apache2 restart sudo systemctl restart apache2
Apache on Windows:
Open the “Services” management console, locate the “Apache” service, and click “Restart”.
NGINX on Linux:
Run one of the following commands, depending on your system:
sudo service nginx restart sudo /etc/init.d/nginx restart sudo systemctl restart nginx
4. Verify the Changes
To verify that your changes have taken effect, open the phpinfo.php file in your web browser again. Check the values of the modified directives to ensure they match your changes in the php.ini file.
That’s it! You’ve now made changes to your php.ini file and restarted your web server to apply them. Remember to remove the phpinfo.php file from your server once you’re done, as it can reveal sensitive information about your server configuration.