0

Recently, I have migrated to a self managed VPS and run a few WordPress websites. But what really confuses me how WordPress won't upload, modify files and folders without 777 permissions. I know a few things about Unix and I do know that giving any file/folder 777 is very, very dangerous but I can't help it since it just doesn't work without that permissions.

Other than giving 777 permissions to wp-content/ and all its sub directories and files, I also did chown apache:apache -R wp-content/ which gives the ownership to the user and group apache. Only then everything "works".

So, how do I make it work with the right permissions and user/group on a VPS? I have seen somewhere from a Google search that I need to add a few user into the same group. I do not understand how that works. I have also seen that I need to add FTP info in the wp-config.php file.

  • I have created a ftp user with the username ftpuser and have vsftpd running. Why? Well, WordPress requires a FTP connection, it keeps prompting me for one.
  • All the files and folders of wp-content/ are set to usergroup apache:apache with perms 777
  • I have tried permissions 755, 775 for folders/directories and 664, 644 for files. It won't work
  • OS I am running: Ubuntu Server, CentOS

That's all I can think of now, will update later on.

Thank you so much for you help.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • 755 to dir and sub dir and 644 to files – Prince Singh Nov 10 '13 at 07:41
  • @pr1nc3 thank you for the prompt reply, I tried that before and it didn't work. Perhaps I should add to the first post. But then I did state that I had to give 777 as permission. –  Nov 10 '13 at 07:44
  • What linux OS is your VPS? – elclanrs Nov 10 '13 at 07:46
  • @elclanrs Gosh, I forget to add that. I only mentioned Unix. CentOS. However, I faced similar issue on Ubuntu Server. Thank you. –  Nov 10 '13 at 07:48
  • I can give you a solution for Ubuntu, check below. – elclanrs Nov 10 '13 at 07:59
  • Kindly refer the Perfect answer at -> https://stackoverflow.com/questions/18352682/correct-file-permissions-for-wordpress/23755604#23755604 – Logesh K Feb 20 '18 at 19:58

1 Answers1

2

Not familiar with CentOS but if you have Ubuntu available, with default LAMP stack it's just a few steps.

Install LAMP (if you start from scratch):

apt-get install lamp-server^

First set the right permissions:

adduser youruser www-data
chown -R www-data:www-data /var/www
chmod -R g+rw /var/www

Then you have to activate modrewrite for permalinks to work:

a2enmod rewrite

Finally edit /etc/apache2/sites-enabled/000-default.conf to enable .htaccess (apache:

# Apache 2.4
<Directory /var/www>
  Options Indexes FollowSymLinks
  AllowOverride All
  Require all granted
</Directory>

You may create a link to /var/www in your home directory:

ln -s /var/www ~/www

Next install WordPress in a folder of your choice inside /var/www. If you copy/paste your previous project make sure to set permissions:

chmod -R 775 /var/www/wordpress

Restart Apache:

service apache2 restart

Go to WordPress panel and refresh permalinks and everything should work.

WordPress doesn't require FTP, the error you see is because you didn't have the proper permissions on the folders. Since you're on a VPS I would recommend using SSH instead of FTP, If you mirror your environments (same file structure), then all you need to is run scp to deploy from your project folder.

scp -r * user@domain.com:$(pwd)
elclanrs
  • 92,861
  • 21
  • 134
  • 171
  • Since apache is www-date in CentOS. I will try adding ftpuser to the group apache. Or am I missing something here? Should I add root or my ftp user (ftpuser) to the group? Thank you. –  Nov 10 '13 at 08:21
  • Add your regular user to the `apache` group but I would simply forget about the FTP. If you set up SSH it'll be easier to manage. – elclanrs Nov 10 '13 at 08:26
  • I've done that by `usermod -g apache ftpuser` OR to make it better to understand and as reference to other members, `usermod -g group user` –  Nov 10 '13 at 08:28
  • TBH, I prefer to use Ubuntu compared to CentOS. I have more experience on Ubuntu. I just started out CentOS yesterday because of my inability to get SSL working on Ubuntu. I have changed all of and its sub-dir /var/www/html (equivalent to /var/html in Ubuntu) to apache:apache and also did `chmod -R g+rw /var/www/html` However, for some reason my wp-content/ folder is still 777. I thought the recursive command of chmod will change all and its sub-dir to g+rw? On if it's working or not, I am uncertain, haven't try. Still trying to understand why and what happened. –  Nov 10 '13 at 08:41
  • One question, above you said to set /var/www/wordpress/ to 775? Does that include the files as well? And a2enmod rewrite is different on CentOS. I am still looking on how to enable mod_rewrite on CentOS, will update if I get it to work. –  Nov 10 '13 at 09:21
  • WOOOTS! Finally got it to work. Thanks to your answer that is! First I try to understand the similarity of the 2 OSes then I just follow your guide. Thanks a bunch, mate! You're lifesaver! Been trying to understand this for 2 days! –  Nov 10 '13 at 10:19