Fix Linux LAMP server permission issues (Ultimate Fix !, 2020)

Introduction

Hello, Guys !. Today, we are going to discuss the apache LAMP server permission issues fix on Linux. Windows people won’t necessarily need this tutorial because permission issues won’t arise on Windows.

This Problem can happen on the LAMP servers installed on Linux Distros such as ubuntu 18.

In this tutorial, I will show how you can get into fixing the file or folder access permissions on Apache LAMP servers. This issue will be a total issue for WordPress users and it is because WordPress needs its plugins which are necessary for the stability of WordPress.

The Problems if we don’t fix LAMP server permissions

If we don’t fix the file permission issues, we will face these problems:

  • Won’t be able to write files to our document root and it’s folders.
  • WordPress would require FTP credentials for managing plugins and themes.
  • WordPress cannot create the wp_config.php file to its root directory.
  • File won’t be uploaded to the directory.

The Fix for LAMP server permission issues on Linux

1. Direct Method (Will work for most users)

In apache servers, most probably, when you are using Digital Ocean’s Droplet, you would find that the files that you upload will be assigned to the user root. For us to fix that problem, I have a simple fix for this.

Change the Group of the owner of files

So, Basically, the document root should be owned by a group called “www-data”

usermod -a -G www-data root

This would be a permanent fix for most of the users who are reading this

2. Three Simple Commands

sudo chown -R ubuntu:www-data /var/www
sudo find /var/www -type d -exec chmod 2750 {} \+
sudo find /var/www -type f -exec chmod 640 {} \+

3. Method two

First, use :

sudo cp -r /home/andre/www/moodle/ /var/www/html/

This code can copy your files to /var/www/html.

We’ll now reset the permissions so a person as well as the webserver can access everything in that document root, and then you should give your user full read and write permissions to all the files and directories.

Do this :

  1. Give your Apache webserver full access to the folders and files, so it can serve the site without 403 errors.
  2. Give your user ‘owner’ the permission for files and folders, and then we can give ourselves the permission to read and write on all of the files and folders in our Apache Directory.
  3. (Optional. But, I recommended it) Set the permissions up in such a way that any files or folders created from now on, in the directory structure has the group set to be www-data.

1. Allow Apache access to the folders and the files.

sudo chgrp -R www-data /var/www/html
sudo find /var/www/html -type d -exec chmod g+rx {} +
sudo find /var/www/html -type f -exec chmod g+r {} +

2. Give your owner read and write privileges to the folders and the files.

sudo chown -R USER /var/www/html/
sudo find /var/www/html -type d -exec chmod u+rwx {} +
sudo find /var/www/html -type f -exec chmod u+rw {} +

3. Make sure every new file after this is created with www-data as the ‘access’ user.

sudo find /var/www/html -type d -exec chmod g+s {} +

Other posts to you should check out to fix permission issues on LAMP server

https://askubuntu.com/questions/767504/permissions-problems-with-var-www-html-and-my-own-home-directory-for-a-website

https://serverfault.com/questions/357108/what-permissions-should-my-website-files-folders-have-on-a-linux-webserver

Leave a Reply

Your email address will not be published. Required fields are marked *