I am running laravel project on ubuntu
with apache2
server and getting the below error when anyone download any invoice/shippment lebel.
The url I am accessing is https://staging.myweb.com
Forbidden
You don't have permission to access this resource. Apache/2.4.52(Ubuntu) Server at staging.myweb.com Port 443
error I found in my apache error.log file is
[Sat Feb 03 11:41:30.589613 2024] [autoindex:error] [pid 895124]AH01276: Cannot serve directory /var/www/html/public/: No matchingDirectoryIndex (index.php,index.html) found, and server-generateddirectory index forbidden by Options directive
Here is my virtual host file
000-default.conf
<VirtualHost *:80> # The ServerName directive sets the request scheme, hostname and port that # the server uses to identify itself. This is used when creating # redirection URLs. In the context of virtual hosts, the ServerName # specifies what hostname must appear in the request's Host: header to # match this virtual host. For the default virtual host (this file) this # value is not decisive as it is used as a last resort host regardless. # However, you must set it for any further virtual host explicitly. #ServerName www.example.com ServerAdmin webmaster@localhost DocumentRoot /var/www/html DirectoryIndex index.php index.html # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular # modules, e.g. #LogLevel info ssl:warn DirectoryIndex index.php index.html<Directory /var/www/html/> Options Indexes FollowSymLinks MultiViews AllowOverride All Require all granted DirectoryIndex index.php index.html</Directory><Directory /var/www/html/public/> Options Indexes FollowSymLinks MultiViews AllowOverride All Require all granted DirectoryIndex index.php index.html</Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined # For most configuration files from conf-available/, which are # enabled or disabled at a global level, it is possible to # include a line for only one particular virtual host. For example the # following line enables the CGI configuration for this host only # after it has been globally disabled with "a2disconf". #Include conf-available/serve-cgi-bin.confRewriteEngine onRewriteCond %{SERVER_NAME} =staging.myweb.comRewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]</VirtualHost>
<IfModule mod_ssl.c><VirtualHost *:443> ServerAdmin webmaster@localhost ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined DocumentRoot /var/www/html/public DirectoryIndex index.php index.html<Directory /var/www/html/> Options Indexes FollowSymLinks MultiViews AllowOverride All Require all granted DirectoryIndex index.php index.html</Directory><Directory /var/www/html/public/> Options Indexes FollowSymLinks MultiViews AllowOverride All Require all granted DirectoryIndex index.php index.html</Directory>CacheQuickHandler onCacheLock onCacheLockPath /tmp/mod_cache-lockCacheLockMaxAge 5CacheIgnoreHeaders Set-Cookie CacheEnable disk / CacheHeader on CacheDefaultExpire 800 CacheMaxExpire 64000 CacheIgnoreNoLastMod On ExpiresActive on ExpiresDefault A300Include /etc/letsencrypt/options-ssl-apache.confSSLCertificateFile /etc/letsencrypt/live/staging.myweb.com/fullchain.pemSSLCertificateKeyFile /etc/letsencrypt/live/staging.myweb.com/privkey.pem</VirtualHost></IfModule>
I have added below code for testing in these VH files
<Directory /var/www/html/public/> Options Indexes FollowSymLinks MultiViews AllowOverride All Require all grantedDirectoryIndex index.php index.html</Directory>
and htaccess files are
root
<IfModule mod_rewrite.c> Options +FollowSymLinks RewriteEngine On RewriteBase / # Rewrite to public folder RewriteCond %{REQUEST_URI} !^/public/ RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ /public/$1 [L] # Rewrite to index.php RewriteCond %{REQUEST_URI} !^/public/index\.php RewriteRule ^(/)?$ /public/index.php [L]</IfModule>
public folder
<IfModule mod_rewrite.c><IfModule mod_negotiation.c> Options -MultiViews -Indexes</IfModule> RewriteEngine On # Handle Authorization Header RewriteCond %{HTTP:Authorization} . RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] # Redirect Trailing Slashes If Not A Folder... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} (.+)/$ RewriteRule ^ %1 [L,R=301] # Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L]</IfModule>
Here are the permission and ownership of html
Even I have tried with the ownership change to www-data
but no luck.
EDITif I open browser and click on disable cache then website started working fine