如何在可通过Putty、FileZilla访问的Amazon EC2 AMI实例修改PHP7.1 php.ini配置
Hey there! Let's walk through exactly how to modify the default php.ini file for PHP 7.1 on your Amazon EC2 AMI instance using either PuTTY (command line) or FileZilla (GUI). I'll break down both methods step by step so you can pick what works best for you.
Modifying PHP 7.1 php.ini on Amazon EC2 AMI
Using PuTTY (Command Line Approach)
- First, fire up PuTTY and connect to your EC2 instance using your key pair (.ppk file) and the default AMI username (usually
ec2-userfor Amazon Linux AMIs). - Locate the exact php.ini path: PHP 7.1's config file can vary by setup, so run this command to find it for sure:
You'll get output likephp -i | grep "Loaded Configuration File"Loaded Configuration File => /etc/php.inior/etc/php/7.1/apache2/php.ini—note this full path. - Edit the php.ini file: Use a terminal editor like
nano(user-friendly for beginners) with sudo permissions (since system config files require root access):sudo nano /path/to/your/php.ini - Make your desired changes: Search for the config parameters you want to tweak (e.g.,
memory_limit,upload_max_filesize,post_max_size). For example, changememory_limit = 128Mtomemory_limit = 256M. - Save and exit: In nano, press
Ctrl+Oto save, hitEnterto confirm the filename, thenCtrl+Xto exit. - Restart your web server to apply the changes:
- For Apache:
sudo systemctl restart httpd - For Nginx:
sudo systemctl restart nginx
- For Apache:
- Verify the changes: Run
php -i | grep "memory_limit"(replace with your modified parameter) to check if the new value is active. Alternatively, create aphpinfo.phpfile in your web root with<?php phpinfo(); ?>and access it via your browser to confirm.
Using FileZilla (GUI Approach)
- Set up FileZilla for SFTP access:
- Open FileZilla, go to
Edit > Settings > SFTP. - Click
Add key fileand select your EC2.pemkey pair (FileZilla will convert it to the required format if needed). - Go to the main FileZilla window: enter your EC2 instance's public IP/DNS as the
Host,ec2-useras theUsername, leavePasswordblank, and use port22. ClickQuickconnect.
- Open FileZilla, go to
- Find the php.ini path: First, use PuTTY to run
php -i | grep "Loaded Configuration File"(same as the command line method) to get the exact file path. - Temporarily adjust file permissions: Since
php.iniis owned by root, you'll need to grant write access first via PuTTY:sudo chmod 664 /path/to/your/php.ini - Download and edit the file:
- In FileZilla, navigate to the
php.inipath you found. - Right-click the file and select
Downloadto save a copy to your local machine. - Open the downloaded file with a proper text editor (avoid Windows Notepad—use Notepad++, Sublime Text, or VS Code to prevent newline/encoding issues).
- Make your desired configuration changes.
- In FileZilla, navigate to the
- Upload the modified file: Right-click the local modified
php.iniin FileZilla's local panel and selectUploadto overwrite the remote file. - Restore file permissions: Go back to PuTTY and reset the permissions to secure the file:
sudo chmod 644 /path/to/your/php.ini - Restart your web server (same commands as the PuTTY method) and verify the changes as described earlier.
Important Notes
- Always back up the original file: Before making changes, run
sudo cp /path/to/php.ini /path/to/php.ini.bakto create a backup—this lets you restore quickly if something goes wrong. - Don't modify settings you don't understand: Stick to the parameters you need to change; incorrect configs can break your PHP applications or web server.
- Restart is mandatory: Changes to
php.iniwon't take effect until you restart your web server.
内容的提问来源于stack exchange,提问作者Rajat Masih
相关产品推荐
相关产品推荐

