0
votes

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.

1
755 to dir and sub dir and 644 to filesPrince Singh
@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.user2826345
What linux OS is your VPS?elclanrs
@elclanrs Gosh, I forget to add that. I only mentioned Unix. CentOS. However, I faced similar issue on Ubuntu Server. Thank you.user2826345
I can give you a solution for Ubuntu, check below.elclanrs

1 Answers

2
votes

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 * [email protected]:$(pwd)