How to Install WordPress Plugins on EC2 Without FTP Credentials?

I’ve set up WordPress 3.5.2 on an Amazon Linux AMI EC2 micro instance. But when I try to add new plugins, it asks for FTP details. I’m not sure how to handle this.

I looked into setting up vsftpd, but that seems complicated. Then I found some FTP constants for wp-config.php in the WordPress Codex. Are these the right way to go? Here’s what I found:

define('FS_METHOD', 'direct');
define('WP_CONTENT_DIR', '/path/to/wp-content');
define('WP_PLUGIN_DIR', '/path/to/wp-content/plugins');

Is this a good approach? I’m worried about security. What’s the best way to install plugins on EC2 without FTP? Any tips would be great!

I’ve encountered this issue on EC2 before and found that the ‘direct’ method is indeed the most practical solution. After establishing an SSH connection to your EC2 instance, the recommended approach is to navigate to your WordPress directory and edit the wp-config.php file with an editor like nano or vim. In the file, add the following lines just before the “That’s all, stop editing!” comment:

define(‘FS_METHOD’, ‘direct’);
define(‘FTP_BASE’, ‘/var/www/html/’);
define(‘FTP_CONTENT_DIR’, ‘/var/www/html/wp-content/’);
define(‘FTP_PLUGIN_DIR’, ‘/var/www/html/wp-content/plugins/’);

Make sure to adjust these paths to match your setup. This configuration enables direct filesystem access without the need for FTP credentials, and when combined with proper EC2 security group settings and file permissions, it has proven secure and effective in my experience.

hey, i had the same problem. what worked for me was adding those lines to wp-config.php like you mentioned. just make sure you get the paths right for your setup. it’s way easier than messing with ftp. just be careful with file permissions and you should be good to go!

I’ve dealt with this exact situation on EC2 instances before. While the ‘direct’ method works, there’s another approach that’s even more straightforward and secure. Instead of modifying wp-config.php, you can simply adjust the file permissions for your WordPress directory.

SSH into your EC2 instance and run:

sudo chown -R apache:apache /var/www/html

This changes the ownership of all WordPress files to the Apache user, allowing WordPress to manage plugins and updates without FTP credentials. It’s clean, simple, and avoids potential security risks from hardcoding paths in your config file.

Just remember to reapply these permissions if you manually update WordPress core files. This method has served me well across multiple EC2 setups without any hiccups.