Symfony 2 Apache 2.4 php7 升级 Vhost 文件
Posted
技术标签:
【中文标题】Symfony 2 Apache 2.4 php7 升级 Vhost 文件【英文标题】:Symfony 2 Apache 2.4 php7 ugrade Vhost file 【发布时间】:2018-01-18 14:07:35 【问题描述】:我的服务器被黑了我别无选择,只能创建一个新服务器,所以我现在升级到最新的 Apache 2.4 和 php 7 不幸的是我发现我的 Symofony 2 应用程序无法运行我在使用 Vhost 时遇到问题配置。
如果有人可以帮助更新 vhost 文件并指定是否需要安装任何 php mods 来替换原始 vhost 文件上的旧 php 5 mods,我将不胜感激。
这是原始虚拟主机。
<VirtualHost *:80>
ServerAdmin contact@example.net
ServerName apps.example.com ServerAlias www.apps.example.com
DocumentRoot /home/example.com.v2.0/Symfony2/web/
DirectoryIndex app.php
ErrorLog /var/log/apache2/example-apps-live-error_log
CustomLog /var/log/apache2/example-apps-live-access_log combined
HostnameLookups Off
UseCanonicalName Off
ServerSignature On
<Directory "/home/example.com.v2.0/Symfony2/web/">
#Require all granted
Options -Indexes +FollowSymLinks -MultiViews -Includes +ExecCGI
AllowOverride All
AddHandler fcgid-script .php
FCGIWrapper /home/php-fcgi-starter .php
AcceptPathInfo On
Order allow,deny
allow from all
</Directory>
</VirtualHost>
【问题讨论】:
【参考方案1】:我推荐了这个配置
<VirtualHost *:80>
ServerName mi-sitio.com
ServerAlias www.mi-sitio.com
SetEnv SYMFONY__DATABASE__USER "..."
SetEnv SYMFONY__DATABASE__PASSWORD "..."
DocumentRoot "/Proyectos/Symfony2/mi-sitio.com/web"
DirectoryIndex app.php
<Directory "/Proyectos/Symfony2/mi-sitio.com/web">
AllowOverride None
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %REQUEST_FILENAME !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
</Directory>
CustomLog /var/log/httpd/mi-sitio.com-access.log combined
KeepAlive On
MaxKeepAliveRequests 200
KeepAliveTimeout 5
<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE "application/atom+xml" \
"application/javascript" \
"application/json" \
"application/rss+xml" \
"application/x-javascript" \
"application/xhtml+xml" \
"application/xml" \
"image/svg+xml" \
"text/css" \
"text/html" \
"text/javascript" \
"text/plain" \
"text/xml"
</IfModule>
<IfModule mod_headers.c>
Header append Vary User-Agent env=!dont-vary
ExpiresActive On
ExpiresDefault "now plus 1 week"
ExpiresByType image/x-icon "now plus 1 month"
ExpiresByType image/gif "now plus 1 month"
ExpiresByType image/png "now plus 1 month"
ExpiresByType image/jpeg "now plus 1 month"
</IfModule>
您可以在http://symfony.es/documentacion/como-configurar-bien-apache-para-las-aplicaciones-symfony2/ 阅读文档并生成您的配置
【讨论】:
【参考方案2】:命令允许,拒绝
这已经不存在了。
Using mod_php/PHP-CGI with Apache 2.4¶
In Apache 2.4, Order Allow,Deny has been replaced by Require all
granted. Hence, you need to modify your Directory permission settings
as follows:
<Directory /var/www/project/public>
Require all granted
# ... </Directory>
查看symfony官方文档:https://symfony.com/doc/current/setup/web_server_configuration.html
【讨论】:
以上是关于Symfony 2 Apache 2.4 php7 升级 Vhost 文件的主要内容,如果未能解决你的问题,请参考以下文章
Centos 6.9 编译安装 apache 2.4+php7.2.3 + Fast-cgi
Centos 6.9 编译安装 apache 2.4+php7.2.3 + Fast-cgi
在 Win10 / Apache 2.4 / PHP 7.0.10 x64 下未加载 cURL
在 Amazon EC2 中从 php 5.3 和 apache 2.2 升级到 php 7 和 apache 2.4