Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.8k views
in Technique[技术] by (71.8m points)

localhost - Why does changing php.ini and reloading Apache in Laragon result in 403 Forbidden?

Setup

Local development:

  • 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]

Issue

A previously working local website site.test results in 403 Forbidden after changing php.ini and reloading Apache with Laragon.

How the error was produced

After failing to retrieve environment variables from .env file, I went to php.ini file and changed variables_order from "GPCS" to "EGPCS". After saving it I reloaded Apache with Laragon > Menu > Apache > Reload. Previously working URL site.test now results in 403.

error.log shows 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

  1. Open C:Laragonwww and rename site to tmp.
  2. In Laragon choose Menu > Quick app > Blank and name the new project site.
  3. Open C:Laragonwwwmp, select all files and copy (cut).
  4. Open C:Laragonwwwsite and paste.

Question

What causes this behaviour and is there a better way of solving it?

Edit

I am not very familiar with .htaccess but this seems very cluttered. The same file is being copied over and over again since the oldest legacy projects while being added on every now and then. Someone is bound to point out mistakes in it:

RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*?)$ index.php/$1
#RewriteRule ^([a-zA-Z0-9-/]+)$ index.php/$1
RewriteRule ^ index.php [QSA,L]
Options -Indexes

# from: https://gist.github.com/Zodiac1978/3145830
#
# Sources:
# http://stackoverflow.com/questions/7704624/how-can-i-use-gzip-compression-for-css-and-js-files-on-my-websites
# http://codex.wordpress.org/Output_Compression
# http://www.perun.net/2009/06/06/wordpress-websites-beschleuinigen-4-ein-zwischenergebnis/#comment-61086
# http://www.smashingmagazine.com/smashing-book-1/performance-optimization-for-websites-part-2-of-2/
# http://gtmetrix.com/configure-entity-tags-etags.html
# http://de.slideshare.net/walterebert/die-htaccessrichtignutzenwchh2014
# http://de.slideshare.net/walterebert/mehr-performance-fr-wordpress
# https://andreashecht-blog.de/4183/
#

<IfModule mod_deflate.c>
  # Insert filters / compress text, html, javascript, css, xml:
  # mod_deflate can be used for Apache v2 and later and is the recommended GZip mechanism to use
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/xml
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/vtt
  AddOutputFilterByType DEFLATE text/x-component
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/js
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/x-httpd-php
  AddOutputFilterByType DEFLATE application/x-httpd-fastphp
  AddOutputFilterByType DEFLATE application/atom+xml
  AddOutputFilterByType DEFLATE application/json
  AddOutputFilterByType DEFLATE application/ld+json
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/x-web-app-manifest+json
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/opentype
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE image/x-icon

  # Exception: Images
  SetEnvIfNoCase REQUEST_URI .(?:gif|jpg|jpeg|png)$ no-gzip dont-vary

  # Drop problematic browsers
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4.0[678] no-gzip
  BrowserMatch MSIE !no-gzip !gzip-only-text/html
  BrowserMatch MSI[E] !no-gzip !gzip-only-text/html

  # Make sure proxies don't deliver the wrong content
  <IfModule mod_headers.c>
    Header append Vary User-Agent env=!dont-vary
  </IfModule>

</IfModule>

# mod_gzip is an external extension and last updated 2015, so
# if available please use mod_deflate instead
# If you are stuck on Apache v1.3 you can use mod_zip to enable Gzip
# as mod_deflate is available for Apache v2 or later only.
<IfModule mod_gzip.c>
  mod_gzip_on Yes
  mod_gzip_dechunk Yes
  mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
  mod_gzip_item_include handler ^cgi-script$
  mod_gzip_item_include mime ^text/.*
  mod_gzip_item_include mime ^application/x-javascript.*
  mod_gzip_item_exclude mime ^image/.*
  mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>


## BEGIN EXPIRES CACHING ##
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 1 year"

  AddType application/vnd.ms-fontobject .eot
  AddType application/x-font-ttf .ttf
  AddType application/x-font-opentype .otf
  AddType application/x-font-woff .woff
  AddType image/svg+xml .svg

  ExpiresByType text/css "access plus 2 months"

  ExpiresByType application/atom+xml "access plus 1 hour"
  ExpiresByType application/rdf+xml "access plus 1 hour"
  ExpiresByType application/rss+xml "access plus 1 hour"

  ExpiresByType application/json "access plus 0 seconds"
  ExpiresByType application/ld+json "access plus 0 seconds"
  ExpiresByType application/schema+json "access plus 0 seconds"
  ExpiresByType application/vnd.geo+json "access plus 0 seconds"
  ExpiresByType application/xml "access plus 0 seconds"
  ExpiresByType text/xml "access plus 0 seconds"

  # S3C - This here doesn't matter because it's being overridden below under "Alternative caching"
  ExpiresByType image/x-icon "access plus 1 month"
  ExpiresByType image/vnd.microsoft.icon "access plus 1 month"

  ExpiresByType text/html "access plus 1 minute"

  ExpiresByType text/javascript "access plus 2 months"
  ExpiresByType text/x-javascript "access plus 2 months"
  ExpiresByType application/javascript "access plus 2 months"
  ExpiresByType application/x-javascript "access plus 2 months"

  # S3C - This here doesn't matter because it's being overridden below under "Alternative caching"
  ExpiresByType image/jpg "access plus 1 year"
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/gif "access plus 1 year"
  ExpiresByType image/svg+xml "access plus 1 year"
  ExpiresByType image/bmp "access plus 1 year"
  ExpiresByType image/webp "access plus 1 year"

  ExpiresByType audio/ogg "access plus 1 month"

  ExpiresByType video/mp4 "access plus 1 month"
  ExpiresByType video/ogg "access plus 1 month"
  ExpiresByType video/webm "access plus 1 month"

  ExpiresByType text/plain "access plus 1 month"
  ExpiresByType text/x-component "access plus 1 month"

  ExpiresByType application/manifest+json "access plus 1 week"
  ExpiresByType application/x-web-app-manifest+json "access plus 0 seconds"
  ExpiresByType text/cache-manifest "access plus 0 seconds"

  # S3C - This here doesn't matter because it's being overridden below under "Alternative caching"
  ExpiresByType application/pdf "access plus 1 year"

  ExpiresByType application/x-shockwave-flash "access plus 1 month"

  ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
  ExpiresByType font/eot "access plus 1 year"
  ExpiresByType font/opentype "access plus 1 year"
  ExpiresByType font/woff "access plus 1 year"
  ExpiresByType application/x-font-ttf "access plus 1 year"
  ExpiresByType application/x-font-opentype "access 1 year"
  ExpiresByType application/font-woff "access plus 1 year"
  ExpiresByType application/font-woff2 "access plus 1 year"
  ExpiresByType application/x-font-woff "access plus 1 year"
</IfModule>
## END EXPIRES CACHING ##


#Alternative caching using Apache's "mod_headers", if it's installed.
#Caching of common files - ENABLED
<IfModule mod_headers.c>

  # 1 YEAR (originally: 1 month | S3C nov.2019: 1 year)
  <FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|svg|bmp|webp|js|css|swf)$">
  Header set Cache-Control "max-age=31104000, public"
  </FilesMatch>

  # 2 DAYS
  <FilesMatch ".(xml|txt)$">
  Header set Cache-Control "max-age=172800, public, must-revalidate"
  </FilesMatch>

  # 2 HOURS
  <FilesMatch ".(html|htm)$">
  Header set Cache-Control "max-age=7200, must-revalidate"
  </FilesMatch>

</IfModule>


<IfModule mod_headers.c>
  <FilesMatch ".(js|css|xml|gz|html|ttf)$">
    Header append Vary: Accept-Encoding
  </FilesMatch>
</IfModule>

# Set Keep Alive Header
# This *just* sets the header - maybe your hoster is not allowing this feature
# Please check if it is working with tools like http://www.webpagetest.org
<IfModule mod_headers.c>
    Header set Connection keep-alive
</IfModule>

# If your server don't support ETags deactivate with "None" (and remove header)
<IfModule mod_expires.c>
  <IfModule mod_headers.c>
    Header unset ETag
  </IfModule>
  FileETag None
</IfModule>

Edit 2

Same happens after restarting windows, so apparently the problem occurs whenever Apache is restarted, regardless of php.ini changes.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...