Ordinary Apache Reload turns working site into a Forbidden 403
Original question on StackOverflow.
- Windows 10 Pro (20H2 19042.685)
- Laragon Full 4.0.15 190704
- Apache httpd-2.4.35-win64-VC15 (port 80)
- MariaDB mariadb-10.5.8-winx64 (port 3306)
- PHP 8 php-8.0.0-Win32-vs16-x64 [TS]
A previously working local website
403 Forbiddenafter changing
php.iniand reloading Apache with Laragon.
How the error was produced
After failing to retrieve environment variables from
.envfile, I went to
php.inifile and changed
"EGPCS". After saving it I reloaded Apache with Laragon > Menu > Apache > Reload. Previously working URL
site.testnow results in 403.
error.logshows the following:
[Tue Jan 12 17:49:37.115215 2021] [access_compat:error] [pid 7160:tid 1152] [client 127.0.0.1:3122] AH01797: client denied by server configuration: C:/laragon/www/site/public/index.html [Tue Jan 12 17:49:37.115215 2021] [access_compat:error] [pid 7160:tid 1152] [client 127.0.0.1:3122] AH01797: client denied by server configuration: C:/laragon/www/site/public/index.php
Hack that solves the problem
- In Laragon choose Menu > Quick app > Blank and name the new project
C:\Laragon\www\tmp\, select all files and copy (cut).
What causes this behaviour and is there a better way of solving it?
@mathmul did you change PHP8 to PHP7 and back again? If so you need to see [Tutorial] How to add another PHP version (PHP 7.4 - PHP 8.0) - Updated, in particular post #74 regarding Apache and post #82 regarding enabling the extensions.
Each time you switch PHP 7 to 8 you need to change the php8_module to php_module, possibly changing the php.ini has triggered this module to re-create as php8_module.
Of course I did. I can't even phatom how there are no solutions (or problems) about it out there.
Whether I add or remove a semi-colon in php.ini, or change httpd-conf, or simply change PHP to v7 and v8 back again (and fixing the php8_module to php_module), or whatever other server change I make, it doesn't matter. I results in 403 forbidden as is, on Apache reload, and/or on Windows restart.
The only thing that works is to rename myProject in www to something, create a new myProject, and then copy all from something in myProject. That even keeps the database so it all works perfectly after that workaround.
I finally figured out where the problem lies in, but hopefully you can tell me a solution.
On Apache reload, as stated, my site goes to 403 forbidden.
Checking error.log, I see the following:
[Tue Mar 16 14:15:08.488240 2021] [access_compat:error] [pid 3304:tid 1192] [client 127.0.0.1:7057] AH01797: client denied by server configuration: C:/laragon/www/my-site/public/index.php
The problem is, that my-site is not a Laravel app or something that has it's "first" file inside /public/, but directly on root of this project ie. C:/laragon/www/my-site/index.php
As presented in my StackOverflow question you can see that the problem is that
ROOTis defined with
public/in the end in the auto.my-site.test.conf configuration file.
Sadly just removing it and saving the file doesn't work, and Apache reload brings it back in.
I also noticed that sites that do not have the
publicfolder in root don't have that problem, so there is some automagical method somewhere that checks if public folder exists in root and writes configuration accordingly.
Currently my best workaround is therefore to rename this public folder to let's say public_files, but that calls for a lot of refactoring.
Where do I have control over these auto-magical settings?