Config a Slim site in Apache but can't find .htaccess

46 views Asked by At

I have built a PHP Slim app under /home/tr/api. All is well, if I start the server by symfony server:start and access it via localhost:8000.

I created a virtual host file:

<VirtualHost *:80>
        ServerName api
        ServerAdmin [email protected]

        DocumentRoot /home/tr/api/public
        <Directory />
                AllowOverride all
        </Directory>

        <Directory /home/tr/api/public>
                Options FollowSymLinks MultiViews
                AllowOverride all
                Order allow,deny
                Allow from all
                Require all granted
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/api.error.log
        CustomLog ${APACHE_LOG_DIR}/api.access.log combined
</VirtualHost>

And created a .htaccess file under /home/tr/api/public as below:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]

Of course, I mapped api to 127.0.0.1 in the hosts file.

Then I tried to access the site in my browser but it gives me "Forbidden: You don't have permission to access this resource.Server unable to read htaccess file, denying access to be safe".

I looked at the log file and found the following line confusing:

[Sun Dec 24 19:30:34.753938 2023] [core:crit] [pid 681] (13)Permission denied: [client 127.0.0.1:54368] AH00529: /home/tr/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable and that '/home/tr/' is executable

It is very confusing because it seems the server is trying to find a .htaccess file in /home/tr, instead of /home/tr/api/public as specified in my vhost config file.

Am I missing anything here?

1

There are 1 answers

0
TaylorR On

It is the permission issue related to my virtual box. After setting 755 to my /home/tr/ it works fine now.