首页 > 解决方案 > 在 OVH 上部署 Symfony 4 项目

问题描述

我正在尝试在 OVH 上部署使用 Symfony 4 创建的站点。我有两个 .htaccess 文件(一个位于我的代码所在的 www 文件夹的根目录中,另一个位于我的公共文件夹中):

RewriteEngine on
RewriteBase /

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]

RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L] `

在我的公共文件夹中:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]

但是当我尝试访问我的网站时出现 404 错误。

有谁知道问题可能来自哪里?

标签: symfony4ovh

解决方案


OVH 是您的托管服务,它不会向我们提供有关您的服务器配置和安装的任何信息。你使用 Nginx 还是 Apache?PHP FPM 还是 PHP CGI?

由于您使用的是.htaccess文件,我假设您已经安装了 Apache。

Symfony 有一个安装正确的重写规则以在 Apache 上运行的方法。您可以通过执行以下命令来运行它: composer require symfony/apache-pack

根据您的 PHP 安装(CGI 或 FPM),在 Apache 上运行 Symfony 有不同的配置。对于 PHP-CGI:

<VirtualHost *:80>
    ServerName domain.tld
    ServerAlias www.domain.tld

    DocumentRoot /var/www/project/public
    <Directory /var/www/project/public>
        AllowOverride All
        Order Allow,Deny
        Allow from All
    </Directory>

    # uncomment the following lines if you install assets as symlinks
    # or run into problems when compiling LESS/Sass/CoffeeScript assets
    # <Directory /var/www/project>
    #     Options FollowSymlinks
    # </Directory>

    ErrorLog /var/log/apache2/project_error.log
    CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>

所有这些信息都可以在官方文档中找到:Symfony Web Server Configuration


推荐阅读