gpt4 book ai didi

apache - 设置 Symfony2 以使用 apache + php-fpm

转载 作者:搜寻专家 更新时间:2023-10-31 20:41:04 25 4
gpt4 key购买 nike

如何设置 Symfony2 以结合 php-fpm 在 Apache (Apache 2.4) 上工作?

目的是摆脱 .htaccess 文件并将所有内容移动到 apache 配置中。

不用担心 PHP-FPM,配置看起来像这样:

<VirtualHost *:80>
ServerName mysymfonyproject.com
ServerAlias www.mysymfonyproject.com
ErrorLog /path/to/logs/mysymfonyproject_error.log
CustomLog /path/to/logs/mysymfonyproject_access.log combined

DocumentRoot "/path/to/sites/mysymfonyproject/web"
<Directory "/path/to/sites/mysymfonyproject/web">
AllowOverride None
Require all granted

## Start directives copied from standard Sf .htaccess
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_URI} .*\.php

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]

RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>
## End directives copied from standard Sf .htaccess
</Directory>
</VirtualHost>

这个帖子是为了让我发布我自己的发现(如果我做错了,也许会得到纠正!)。

最佳答案

我更喜欢只使用 ProxyPassMatch 来完成这项工作。通过使用此方法,您在 .htaccess 中的重写规则无需更改。

这是我的 Apache2 虚拟主机文件:

<VirtualHost 192.168.100.51:80>                                                     
ServerName grae.labs.brainglove.com
ServerAlias www.grae.labs.brainglove.com

DocumentRoot /srv/symfony2/2.4.4/grae/web
DirectoryIndex app_dev.php

ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9001/srv/symfony2/2.4.4/grae/web/$1

<Directory /srv/symfony2/2.4.4/grae/web>
AllowOverride All
Options FollowSymLinks
Require all granted
</Directory>

ErrorLog /var/log/httpd/grae.labs.brainglove.com_error.log
CustomLog /var/log/httpd/grae.labs.brainglove.com_access.log combined

您唯一需要添加的行是 ProxyPassMatch。其他一切都保持不变。

不要忘记更改您的 symfony2 网络目录的 IP 地址和路径。

关于apache - 设置 Symfony2 以使用 apache + php-fpm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21513185/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com