php.ini How to Find, Open & Edit php.ini in Ubuntu
In Ubuntu, the php.ini
file is the configuration file for PHP. This file controls various PHP settings and options. Here’s how to find, open, and edit the php.ini
file in Ubuntu:
Finding the php.ini File
1.Using Terminal:
You can locate the php.ini
file by running the following command in your terminal:
php -i | grep "php.ini"
- This command will display the path to the
php.ini
file on your system. - Using File Explorer:If you prefer a graphical interface, you can search for the
php.ini
file using Ubuntu’s file explorer.- Open the file explorer (Nautilus).
- In the top-right corner, you’ll see a search bar. Enter “php.ini” in the search bar.
php.ini
files found on your system.
Opening and Editing the php.ini File
Once you’ve located the php.ini
file, you can open and edit it using a text editor like Nano or Gedit. Here are two common methods:
Using Nano (Terminal Text Editor):
Open a terminal and run the following command to edit the php.ini
file with Nano:
sudo nano /path/to/php.ini
- Replace
/path/to/php.ini
with the actual path to yourphp.ini
file, which you obtained in the previous step. You’ll need superuser (sudo) privileges to edit this file.Make your changes, and then save the file by pressingCtrl + O
, followed byEnter
. Exit Nano by pressingCtrl + X
. - Using Gedit (Graphical Text Editor):If you prefer a graphical text editor, you can open the
php.ini
file with Gedit:
sudo gedit /path/to/php.ini
- Replace
/path/to/php.ini
with the actual path to yourphp.ini
file.Thesudo
command is necessary to open and edit system configuration files. Gedit will open, allowing you to make changes.After making your edits, save the file using Gedit’s regular save options.
Important Notes:
- Be cautious when editing the
php.ini
file, as changes to PHP settings can affect the behavior of your PHP applications. - Always make a backup of the
php.ini
file before making changes so that you can easily revert if necessary. - After editing the
php.ini
file, you may need to restart your web server (e.g., Apache or Nginx) and PHP for the changes to take effect. Use the following commands:
sudo systemctl restart apache2 # For Apache
sudo systemctl restart nginx # For Nginx
sudo systemctl restart php7.4-fpm # Replace with your PHP version
That’s it! You now know how to find, open, and edit the php.ini
file in Ubuntu.