4

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!

1
  • got your old .conf there? Commented Dec 11, 2019 at 15:05

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

I had the same problem, and finally after investing many hours I found the problem in my case.

It was solved with this php.ini variable:

cgi.fix_pathinfo=1

I hope that at least it helps so that another person does not waste so much time.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.