Search code examples
phpapache.htaccessfile-permissionshttp-status-code-403

Why I'm not able to run the working PHP website from remote linux server on my local linux machine?


I've on working website installed on Remote Linux Server.

All the files of a website are present inside a directory '/var/www/' on that remote linux server.

I connected to that remote server using Filezilla and downloaded all the file that are present in '/var/www/'

I'm also using Ubuntu Linux, Apache web server on my local machine.

I put all the downloaded files into the folder called 'new_website' which is present at location '/var/www/new_website'

After that I hit the URL 'http://localhost/new_website' in a browser and I got following error message.

**Forbidden**

You don't have permission to access /new_website on this server.
Server unable to read htaccess file, denying access to be safe

Then I googled for the solution and come to know that i've to give 755 permission to the file '.htaccess' which is present into a folder '/var/www/new_website'. Even after doing that I got the same error. Can someone please let me know what could be the solution for this issue. For your reference I'm putting below the code of file '/var/www/new_website/.htaccess'

Note : For security concerns I've used the duplicate URL of my working website in following code of .htaccess as 'www.mywebsite.com'

######################################
## [PHPFOX_HEADER]
##
## @copyright       [PHPFOX_COPYRIGHT]
## @author          Raymond Benc
## @package         PhpFox
## @version         $Id: htaccess.txt 5866 2013-05-10 09:06:38Z Raymond_Benc $
######################################

# Options -Indexes
# Options -Multiviews

# Header unset Pragma
# FileETag None
# Header unset ETag

# URL Rewrite
<IfModule mod_rewrite.c>
    RewriteEngine On

    #
    #  Full path to your site
    #
    RewriteBase /

    # Rename Photo Names
    # RewriteRule ^file/pic/photo/([0-9]+)/([0-9]+)/([A-Za-z0-9]{32}+)\-(.*?)_([0-9]*?)\.(.*)$ file/pic/photo/$1/$2/$3_$5.$6
    # RewriteRule ^file/pic/photo/([0-9]+)/([0-9]+)/([A-Za-z0-9]{32}+)\-(.*?)\.(.*)$ file/pic/photo/$1/$2/$3.$5 

    # 301 redirect if missing www.
    #RewriteCond %{HTTP_HOST} !^www\.
    #RewriteRule ^(.*)$ http://www.% {HTTP_HOST}/$1 [R=301,L]

    # 301 redirect if missing trailing slash
    #RewriteCond %{REQUEST_FILENAME} !-f
    #RewriteCond %{REQUEST_FILENAME} !-d
    #RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

    #
    #  Rules
    #
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*) index.php?do=/$1

    RewriteCond %{HTTP_HOST} ^mywebsite.com [NC]
RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [L,R=301]

    # Image Access Protection
    # RewriteRule ^file/pic/photo/(.*)\.(.*)$ static/image.php?file=$1&ext=$2
</IfModule>

# Modify Headers
<IfModule mod_expires.c>
    ExpiresActive ON

    # Cache files
    <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4)$">
        Header set Cache-Control "public"
        ExpiresDefault "access plus 2 months"
        Header unset Last-Modified
    </FilesMatch>

    # Cache JavaScript & CSS
    <FilesMatch "\.(js|css)$">
        Header set Cache-Control "public"
        ExpiresDefault "access plus 2 months"
        Header unset Last-Modified
    </FilesMatch>
</IfModule>

# Compress JavaScript & CSS
<IfModule mod_deflate.c>
    <FilesMatch "\.(js|css|php)$">
        SetOutputFilter DEFLATE
    </FilesMatch>
</IfModule>

order allow,deny
deny from 77.99.11.22
allow from all 

Let me know if you need any further information from me to solve this issue. Thanks.


Solution

  • You have to change the permission of the files/folders in that director.

    In terminal, go to that directory and type in,

    sudo chmod 777 . -R
    

    to change the permission of all the files recursively