Server unable to read htaccess file, denying access to be safe

前端 未结 14 2830
情深已故
情深已故 2020-12-12 20:15

I have created a simple app using AngularJS. When I tried to host that project in my website http://demo.gaurabdahal.com/recipefinder it shows the following error:

相关标签:
14条回答
  • 2020-12-12 20:39

    This is a common problem with GoDaddy virtual server hosting when you bring up a new website.

    Assuming you have SSH access to the server (you have to enable it on cPanel), login to your account. Upon successful login, you will be placed in the home directory for your account. The DocumentRoot for your website is located in a subdirectory named public_html. GoDaddy defaults the permissions for this directory to 750, but those permissions are inadequate to allow Apache to read the files for website. You need to change the permissions for this directory to 755 (chmod 755 public_html).

    Copy the files for your website into the public_html directory (both scp and rsync work for copying files to a GoDaddy Linux server).

    Next, make sure all of the files under public_html are world readable. To do this, use this command:

    cd public_html
    chmod -R o+r *
    

    If you have other subdirectories (like css, js, and img), make sure they are world accessible by enabling both read and execute for world access:

    chmod o+rx css
    chmod o+rx img
    chmod o+rx js
    

    Last, you will need to have a .htaccess file in the public_html file. GoDaddy enforces a rule that prohibits the site for loading if you do not have a .htaccess file in your public_html directory. You can use vi to create this file ("vi .htaccess"). Enter the following lines in the file:

    Order allow,deny
    Allow from all
    Require all granted
    

    This config will work for both Apache 2.2 and Apache 2.4. Save the file (ZZ), and then make sure the file has permissions of 644:

    chmod 644 .htaccess
    

    Works like a charm.

    0 讨论(0)
  • 2020-12-12 20:40

    I had same problem on Fedora, and found that problem was selinux. to test that it is problem run command: sudo setenforce 0

    Otherwise or change in file /etc/sysconfig/selinux

    SELINUX=enforcing
    to
    SELINUX=disabled
    

    or add rules to selinux to allow http access

    0 讨论(0)
  • 2020-12-12 20:40

    Important points in my experience:

    • every resource accessed by the server must be in an executable and readable directory, hence the xx5 in every chmod in other answers.
    • most of the time the webserver (apache in my case) is running neither as the user nor in the group that owns the directory, so again xx5 or chmod o+rx is necessary.

    But the greater conclusion I reached is start from little to more.

    For example, if http://myserver.com/sites/all/resources/assets/css/bootstrap.css yields a 403 error, see if http://myserver.com/ works, then sites, then sites/all, then sites/all/resources, and so on.

    It will help if your server has directory indexes enable:

    • In Apache: Options +Indexes

    This instruction might also be in the .htaccess of your webserver public_html folder.

    0 讨论(0)
  • 2020-12-12 20:41

    You need to run these commands in /var/www/html/ or any other directory that your project is on:

    sudo chgrp -R GROUP ./
    sudo chown -R USER:GROUP ./
    find ./ -type d -exec chmod 755 -R {} \;
    find ./ -type f -exec chmod 644 {} \;
    

    In my case (apache web server) I use www-data for USER and GROUP

    0 讨论(0)
  • 2020-12-12 20:42

    I had this problem too. My advice is look in your server error log file. For me, it was that the top directory for the project was not readable. The error log clearly stated this. A simple

    sudo chmod 755 <site_top_folder>
    

    fixed it for me.

    0 讨论(0)
  • 2020-12-12 20:47

    GoDaddy shared server solution

    I had the same issue when trying to deploy separate Laravel project on a subdomain level.

    File structure

    - public_html (where the main web app resides)
        [works fine]
    
        - booking.mydomain.com (folder for separate Laravel project)
            [showing error 403 forbidden]
    

    Solution

    1. go to cPanel of your GoDaddy account

    2. open File Manager

    3. browse to the folder that shows 403 forbidden error

    4. in the File Manager, right-click on the folder (in my case booking.mydomain.com)

    5. select Change Permissions

    6. select following checkboxes

       a) user - read, write, execute
       b) group - read, execute
       c) world - read, execute
      
       Permission code must display as 755
      
    7. Click change permissions

    0 讨论(0)
提交回复
热议问题