apachepermissionscentoshttpd.confhttpforbiddenhandler

Forbidden: You don't have permission to access / on this server (centos 7)


I installed httpd on the host and changed the httpd.conf file as follows

ServerRoot "/etc/httpd"

Listen 80


Include conf.modules.d/*.conf


User apache
Group apache

ServerAdmin root@localhost

<Directory />
    AllowOverride none
    Require all granted
</Directory>
DocumentRoot "/home/admin/domains/morabi.app/public_html"

<Directory "/var/www">
    AllowOverride None
    Require all granted
</Directory>

<Directory "/var/www/html">
    Options Indexes FollowSymLinks

    AllowOverride None

    Require all granted
</Directory>

<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

<Files ".ht*">
    Require all denied
</Files>

when i loaded my ip address in browser it has "Forbidden You don't have permission to access / on this server." error. and /home/admin/domains/morabi.app permission is 755 also files are loaded but my ip http://x.x.x.x/ has forbidden error


Solution

  • You will need to add the following to it:

    <Directory "/home/admin/domains/morabi.app/public_html">
    # Learn more about this at https://httpd.apache.org/docs/2.4/mod/core.html#options
    Options Indexes FollowSymLinks
    
    # Learn more about this at https://httpd.apache.org/docs/2.4/mod/core.html#allowoverride
    AllowOverride All
    
    # The solution for your error, allows your files to be served, learn more about this at https://httpd.apache.org/docs/2.4/howto/access.html
    Require all granted
    </Directory>
    

    And restart Apache.

    This is something that many people forget, and some don't know about. Please be aware of this.

    Edit

    Tip: Take a backup before running these commands, I am not responsible if anything bad happens to the files.

    Try checking the owner of the folder public_html by running ls -la inside morabi.app inside the terminal, if it is not your user or apache try running this command in the directory morabi.app:

    Make sure you are running this as your primary user which you use, I suggest you not to change it to root.

    chown $USER:$USER public_html -R
    

    This above command is going to change the owner of the folder and the files inside it. Change $USER to apache if changing the owner to the user running the commands doesn't work, but always take a backup before as I said above.