You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在可通过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-user for 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:
    php -i | grep "Loaded Configuration File"
    
    You'll get output like Loaded Configuration File => /etc/php.ini or /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, change memory_limit = 128M to memory_limit = 256M.
  • Save and exit: In nano, press Ctrl+O to save, hit Enter to confirm the filename, then Ctrl+X to exit.
  • Restart your web server to apply the changes:
    • For Apache:
      sudo systemctl restart httpd
      
    • For Nginx:
      sudo systemctl restart nginx
      
  • Verify the changes: Run php -i | grep "memory_limit" (replace with your modified parameter) to check if the new value is active. Alternatively, create a phpinfo.php file 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:
    1. Open FileZilla, go to Edit > Settings > SFTP.
    2. Click Add key file and select your EC2 .pem key pair (FileZilla will convert it to the required format if needed).
    3. Go to the main FileZilla window: enter your EC2 instance's public IP/DNS as the Host, ec2-user as the Username, leave Password blank, and use port 22. Click Quickconnect.
  • 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.ini is 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:
    1. In FileZilla, navigate to the php.ini path you found.
    2. Right-click the file and select Download to save a copy to your local machine.
    3. Open the downloaded file with a proper text editor (avoid Windows Notepad—use Notepad++, Sublime Text, or VS Code to prevent newline/encoding issues).
    4. Make your desired configuration changes.
  • Upload the modified file: Right-click the local modified php.ini in FileZilla's local panel and select Upload to 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.bak to 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.ini won't take effect until you restart your web server.

内容的提问来源于stack exchange,提问作者Rajat Masih

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:17:38