I have a LAMP stack running yii2. Trying to enable pretty URLs and I think my php-fpm proxy rule in Apache vhost, or .htaccess is not catching it for some reason.
Any suggestions how to fix this so I can use pretty URLs? php-fpm is throwing an error. Regular urls work fine. This php-fpm configuration also works for other php url rewriting apps like wordpress.
RewriteEngine on
# If a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward it to index.php
RewriteRule . index.php
In case anyone else wants to do Apache, php-fpm sockets, and Yii2 pretty urls together, here is the configuration that I used to get everything working:
Substitute your own IP address, host names, and directories below in your apache virtual host config
<VirtualHost 127.0.0.1:80>
ServerAdmin example.com
DocumentRoot /var/www/html/vhost_root/web
ServerName example.com
ErrorLog logs/example.com-error_log
CustomLog logs/example.com-access_log common
# redirect everything to https if you want, otherwise copy the config from below to here
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com$1 [R,L]
</VirtualHost>
<VirtualHost *:443>
DocumentRoot "/var/www/html/vhost_root/web"
ServerName glyphbio.local:443
ErrorLog logs/example.com-error_log
TransferLog logs/example.com-access_log
LogLevel debug
SSLEngine on
SSLProtocol all -SSLv2
SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5
# enter your own SSL certificates
SSLCertificateFile /etc/pki/httpd/example.com/server.crt
SSLCertificateKeyFile /etc/pki/httpd/example.com/server.key
CustomLog logs/example.com-access_log "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
Options -Indexes +FollowSymLinks +ExecCGI +MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
# allow direct loading of urls matching these, everythign else goes to php-fpm
RewriteCond %{REQUEST_URI} !^/(css|js|images|assets)/ [NC]
RewriteRule "^(.*)" "/index.php" [L,PT,QSA]
ProxyPassMatch ^/(.*\.php(/.*)?)$ unix:/var/run/php-fpm/example.com.sock|fcgi://localhost/var/www/html/vhost_root/web
</VirtualHost>
be sure to restart apache service
Comment the following lines out of your web/.htaccess file, if you have them.
### this will be ignored by php-fpm ###
#RewriteEngine on
# If a directory or a file exists, use it directly
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward it to index.php
#RewriteRule . index.php
Using this method, you can run Yii2 pretty urls on Apache with php-fpm on a shared server with unix sockets, securely. Took me a while to piece these together so hopefully this helps someone else