I'm having a problem with one website after moving it to another server. Old one wasn't using php-fpm, new one does, and so far I didn't have any problems related to that when migrating other websites.
The thing with this one is that it uses weird way to achieve symlinks. See what's happening in the .htaccess:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
index.php explodes PATH_INFO to get needed parameters:
$url_elements = explode('/', $_SERVER['PATH_INFO']);
Home page works fine. What doesn't work is all of the subpages. I get File not found. on front, and AH01071: Got error 'Primary script unknown\n' from php-fpm in the logs.
My idea is that it happens because the php-fpm gets a filename with forward slashes and treats it as a path.
This is the config that Apache uses to process PHP files via php-fpm:
# Redirect to local php-fpm if mod_php is not available
<IfModule !mod_php7.c>
<IfModule proxy_fcgi_module>
# Enable http authorization headers
<IfModule setenvif_module>
SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1
</IfModule>
<FilesMatch ".+\.ph(ar|p|tml)$">
SetHandler "proxy:unix:/run/php/php7.2-fpm.sock|fcgi://localhost"
</FilesMatch>
<FilesMatch ".+\.phps$">
# Deny access to raw php sources by default
# To re-enable it's recommended to enable access to the files
# only in specific virtual host or directory
Require all denied
</FilesMatch>
# Deny access to files without filename (e.g. '.php')
<FilesMatch "^\.ph(ar|p|ps|tml)$">
Require all denied
</FilesMatch>
</IfModule>
</IfModule>
I can't afford to rewrite code of this website to do friendly URLs in a better way, because this website is just a small page used for SEO purposes and company won't allow to waste time on that right now.
I'd be more than happy if someone would provide me with a simple fix for those errors.
Thank you in advance!
Please try enabling FollowSymLinks
and AllowOverride All
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Once done, restart apache2 service with command sudo systemctl stop apache2
& sudo systemctl start apache2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With