63

I just installed WordPress 3.5.2 on an Amazon Linux AMI EC2 micro instance. When I tried to install the wp-db-backup plugin (Plugins -> Add New), I was prompted for a Hostname, FTP Username, FTP Password and Connection Type.

The answer to this question recommended that passwd be done at the command line. I'm not clear on exactly what I'm doing at the commandline based on this answer. So I Googled and found an article on configuring vsftpd. The article discusses the generation of a certificate on the server and I'm wondering whether I'm going off track here by following this article. I'm using CentOS 6.3 locally, and an Amazon Linux AMI on EC2).

Any assistance/guidance will be appreciated.


EDIT


I was reading the WordPress Codex which discussed ftp constants for the wp-config.php file. It recommended that I define as few of these constants as needed to correct my update issues. I'm I on the right track here (especially security-wise)? I've listed the constants below. Any guidance will be appreciated.

define('FS_METHOD', 'ftpext');
define('FTP_BASE', '/path/to/wordpress/');
define('FTP_CONTENT_DIR', '/path/to/wordpress/wp-content/');
define('FTP_PLUGIN_DIR ', '/path/to/wordpress/wp-content/plugins/');
define('FTP_PUBKEY', '/home/username/.ssh/id_rsa.pub');
define('FTP_PRIKEY', '/home/username/.ssh/id_rsa');
define('FTP_USER', 'username');
define('FTP_PASS', 'password');
define('FTP_HOST', 'ftp.example.org');
define('FTP_SSL', false);
starball
  • 20,030
  • 7
  • 43
  • 238
Anthony
  • 3,990
  • 23
  • 68
  • 94

9 Answers9

160

The main issue here is that apache does not have access to the folders. The default permission is given to the ec2-user in the AMI.

run this in your terminal and you should be good to go.

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

Once this is done you should be able to upload themes, plugins, updates etc.

Basil Abbas
  • 1,782
  • 1
  • 10
  • 9
  • 3
    This helped me, Rather than 100 workarounds and installing FTP, setting permission for Apache is the right way to do it. Thanks mate, this is the quickest solution ever. – Clain Dsilva Aug 31 '14 at 15:50
  • I'm voting for it too - best and easiest solution! – Yizhar Nov 16 '14 at 17:16
  • I wasn't even thinking about this type of solution, I was looking for how to install ftp on ec2 wordpress deployment, and this solution saved me so much time. Thank you. – eitama May 24 '15 at 10:51
  • 13
    Worked perfectly, though I had to replace "apache" with "www-data". – Wonko the Sane Jul 16 '15 at 13:52
  • 5
    The user that owns my apache2 processes was not "apache" so I looked to see what user was launching them and it was "www-data", then it worked perfectly! – Tyler White Sep 18 '15 at 16:41
  • 2
    A better way would be to create a 'www' group and allow group access to the files, and add the apache user to the 'www' group. Full instructions [here](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/install-LAMP.html) – Carlos P Feb 29 '16 at 11:04
  • For me, I had to give access to wp-admin folder, so the command was - `sudo chown -R apache:apache /var/www/html/wp-admin/` – Rohan Kandwal Jun 07 '16 at 07:50
  • One note on this: Because the FTP and SSH account I'm using to log in is ec2-user, when I chowned the directory to apache I lost the ability to edit, upload or delete files through FTP, and SSH starts requiring sudo for everything. To fix this you need to add ec2-user (or whatever user you're using to FTP and SSH) to the ACL for that directory, like so: sudo setfacl -R -m ec2-user:rwx /var/www/html – James Jul 25 '18 at 13:31
54

Try this code in your wp config file

define('FS_METHOD', 'direct');
Faizan Khan
  • 638
  • 6
  • 13
  • +1 Thanks for your reply. I resolved the problem by opening ports for FTP (see answer above). Thanks again – Anthony Sep 29 '13 at 02:07
  • This worked for me. Very simple. I already had the owner set like the answers from Saurabh and Basil say. – Acuariano Apr 26 '16 at 17:51
  • @sparkandshine and others who find that this does not work, combine this answer with the other answer, make the files owned by the correct user. `sudo chown -R apache:apache /var/www/html` – deweydb Sep 26 '16 at 01:48
  • Awesome. Worked. Thank you – tushonline May 27 '17 at 13:31
46

change owner of wordpress directory

sudo chown -R www-data:www-data /var/www/wordpress

OR try

define('FS_METHOD', 'direct');
Saurabh Chandra Patel
  • 12,712
  • 6
  • 88
  • 78
  • 1
    Doesn't the Amazon Linux AMI use `apache` user for httpd? This answer worked for me, but like the OP, I had the Amazon Linux AMI and had to use `apache` user. –  Feb 23 '16 at 15:57
7

This worked for me:

First follow what Faizan said to do and put the following line if your wp-config.php:

# you will want this as close to the bottom as possible
define('FS_METHOD', 'direct');

Then you need to TEMPORARILY swap your file permissions to a more open state. In the command line type the following:

sudo chmod 777 -R /your_whole_wp_project

Now run your updates and then change the permissions back to something sane like:

sudo chmod 664 -R /your_whole_wp_project

I'm aware this is a security issue and maybe not the best way to do this, but its the only thing I could try that got it to work for me.

usumoio
  • 3,500
  • 6
  • 31
  • 57
5

I found the answer to this question at Stephen White's blog post.

In a nutshell, I have to

  • create custom rules for Port Ranges 20-21 and some additional ports in my EC2 instance FW
  • install and configure the FTP server vsftpd
  • create and configure an FTP user
  • and put my FTP setting in the wp-config.php file

    This works very well for me now.

Anthony
  • 3,990
  • 23
  • 68
  • 94
3
sudo chown -R apache:apache /var/www/html

if this doesn't work, try replacing "apache" with "www-data" and you'll be good to go.

Heena Manglani
  • 356
  • 2
  • 11
2

The 'define('FS_METHOD', 'direct');' suggestion worked for me after editing my security group in EC2 to allow outbound access to the port 443 (HTTPS)

2

sudo chown -R www-data:www-data /var/www/html/wordpress

the above command did the trick for me.

LComingHome
  • 91
  • 2
  • 8
0

For me it was a selinux issue. This did it for me: chcon -Rv --type=httpd_sys_rw_content_t /var/www/html/

See: https://www.svnlabs.com/blogs/centos-7-selinux-apache-php-writeaccess-permission/

Kahitarich
  • 395
  • 2
  • 7