Installing/configurate Vhost Ubuntu 子域文件夹上的 Symfony3.2 --> 错误 403 禁止访问和错误 500

Installing/configurate Symfony3.2 on a Vhost Ubuntu subdomain folder --> Error 403 Forbidden and Error 500

我尝试在我的 vhost 运行ning Plesk ubuntu 上安装 Symfony3.2。 我的目标是创建一个生产服务器状态来在线测试我的 Symfony 项目。 我想使用 URL subexample.example.tldsubexample.example.tld/matchGen.

进入这个项目

在我穿越泪水和永恒的自我怀疑的洞穴的旅程中,我看到了很多不同的错误,甚至成功地破坏了整个虚拟主机,包括我的电子邮件系统……干得好。

嗯..现在我收到错误 403 Forbidden。 好消息(至少对我而言):我看到了 symfony 的图标,如果我尝试打开 app_dev.php (subexample.example.tld/matchGen/web/app_dev.php),它会显示 You are not allowed to access this file. Check app_dev.php for more information.。 使用 subexample.example.tld/matchGen/web/app.php 打开 app.php 会导致重定向到 subexample.example.tld/matchGen/web/The server returned a "500 Internal Server Error".subexample.example.tld 运行 也进入了 Forbidden。

我已经 tried/did 以下内容:

现在 error.logs:

/var/www/vhosts/system/subexample.example.tld/logs/error_logs

[Mon Apr 10 20:41:45.361150 2017] [autoindex:error] [pid 15012] [client 87.147.219.10:5188] AH01276: Cannot serve directory /var/www/vhosts/example.tld/subexample.example.tld/: No matching DirectoryIndex (index.html,index.php) found, and server-generated directory index forbidden by Options directive
[Mon Apr 10 20:41:47.707623 2017] [autoindex:error] [pid 15012] [client 87.147.219.10:5188] AH01276: Cannot serve directory /var/www/vhosts/example.tld/subexample.example.tld/matchGen/: No matching DirectoryIndex (index.html,index.php) found, and server-generated directory index forbidden by Options directive

/var/log/apache2/matchGen_error.log/var/log/apache2/matchGen_access.log 为空。

我的配置文件:

/etc/apache2/sites-available/subexample.example.tld.conf

<VirtualHost *:80>
    ServerName subexample.example.tld
    ServerAlias www.subexample.example.tld

    DocumentRoot /var/www/vhosts/example.tld/subexample.example.tld/matchGen/web
    <Directory  /var/www/vhosts/example.tld/subexample.example.tld/matchGen/web>
        AllowOverride None
        Require all granted
        Allow from All

        <IfModule mod_rewrite.c>
            Options -MultiViews
            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^(.*)$ app.php [QSA,L]
            RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
        </IfModule>
    </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>

    # optionally disable the RewriteEngine for the asset directories
    # which will allow apache to simply reply with a 404 when files are
    # not found instead of passing the request into the full symfony stack
    <Directory  /var/www/vhosts/example.tld/subexample.example.tld/matchGen/web/bundles>
        <IfModule mod_rewrite.c>
            RewriteEngine Off
        </IfModule>
    </Directory>
    ErrorLog /var/log/apache2/matchGen_error.log
    CustomLog /var/log/apache2/matchGen_access.log combined
</VirtualHost>

/var/www/vhosts/system/subexample.example.tld/conf/httpd.conf

#ATTENTION!
#
#DO NOT MODIFY THIS FILE BECAUSE IT WAS GENERATED AUTOMATICALLY,
#SO ALL YOUR CHANGES WILL BE LOST THE NEXT TIME THE FILE IS GENERATED.
#IF YOU REQUIRE TO APPLY CUSTOM MODIFICATIONS, PERFORM THEM IN THE FOLLOWING FILES:
#/var/www/vhosts/system/subexample.example.tld/conf/vhost.conf
#/var/www/vhosts/system/subexample.example.tld/conf/vhost_ssl.conf
<IfModule mod_ssl.c>

        <VirtualHost xx.xx.xxx.xxx:443 >
                ServerName "subexample.example.tld:443"
                ServerAlias "www.subexample.example.tld"
                ServerAlias "ipv4.subexample.example.tld"
                ServerAdmin "root@example.tld"
                UseCanonicalName Off

                DocumentRoot "/var/www/vhosts/example.tld/subexample.example.tld"
                CustomLog /var/www/vhosts/system/subexample.example.tld/logs/access_ssl_log plesklog
                ErrorLog "/var/www/vhosts/system/subexample.example.tld/logs/error_log"

                <IfModule mod_suexec.c>
                        SuexecUserGroup "xxxx" "xxxx"
                </IfModule>

                <IfModule mod_userdir.c>
                        UserDir "/var/www/vhosts/example.tld/web_users"
                </IfModule>

                <IfModule mod_sysenv.c>
                        SetSysEnv PP_VHOST_ID "6a66d04f-d22f-4a30-bb80-ca47f117886a"
                </IfModule>

                ScriptAlias "/cgi-bin/" "/var/www/vhosts/example.tld/subexample.example.tld/cgi-bin/"

                Alias "/plesk-stat" "/var/www/vhosts/system/subexample.example.tld/statistics"
                <Location  /plesk-stat/>
                        Options +Indexes
                </Location>
                <Location  /plesk-stat/logs/>
                        Require valid-user
                </Location>
                Alias /webstat /var/www/vhosts/system/subexample.example.tld/statistics/webstat
                Alias /webstat-ssl /var/www/vhosts/system/subexample.example.tld/statistics/webstat-ssl
                Alias /ftpstat /var/www/vhosts/system/subexample.example.tld/statistics/ftpstat
                Alias /anon_ftpstat /var/www/vhosts/system/subexample.example.tld/statistics/anon_ftpstat
                Alias /awstats-icon /usr/share/awstats/icon

                SSLEngine on
                SSLVerifyClient none
                SSLCertificateFile /opt/psa/var/certificates/certyKQzXqX

                SetEnv PP_CUSTOM_PHP_INI /var/www/vhosts/system/subexample.example.tld/etc/php.ini
                SetEnv PP_CUSTOM_PHP_CGI_INDEX fastcgi

                <IfModule mod_fcgid.c>
                        FcgidInitialEnv PP_CUSTOM_PHP_INI /var/www/vhosts/system/subexample.example.tld/etc/php.ini
                        FcgidInitialEnv PP_CUSTOM_PHP_CGI_INDEX fastcgi
                        FcgidMaxRequestLen 134217728
                        FcgidIOTimeout 600
                </IfModule>

                TimeOut 600
                <Directory /var/www/vhosts/example.tld/subexample.example.tld>

                        <IfModule mod_fcgid.c>
                                <Files ~ (\.fcgi$)>
                                        SetHandler fcgid-script
                                        Options +ExecCGI
                                </Files>
                        </IfModule>
                        <IfModule mod_fcgid.c>
                                <Files ~ (\.php$)>
                                        SetHandler fcgid-script
                                        FCGIWrapper /var/www/cgi-bin/cgi_wrapper/cgi_wrapper .php
                                        Options +ExecCGI
                                </Files>
                        </IfModule>

                        SSLRequireSSL

                        Options -Includes +ExecCGI

                </Directory>

                <Directory /var/www/vhosts/example.tld/web_users>

                        <IfModule mod_php4.c>
                                php_admin_flag engine off
                        </IfModule>

                        <IfModule mod_php5.c>
                                php_admin_flag engine off
                        </IfModule>

                </Directory>

                <Directory /var/www/vhosts/subexample.example.tld>
                        Options +FollowSymLinks
                </Directory>

                <Directory "/var/www/vhosts/system/subexample.example.tld/statistics">
                        AuthType Basic
                        AuthName "Domainstatistiken"
                        AuthUserFile "/var/www/vhosts/system/subexample.example.tld/pd/d..httpdocs@plesk-stat"
                        require valid-user
                </Directory>

                <IfModule mod_security2.c>
                </IfModule>

        </VirtualHost>

</IfModule>

<VirtualHost xx.xx.xxx.xxx:80 >
        ServerName "subexample.example.tld:80"
        ServerAlias "www.subexample.example.tld"
        ServerAlias "ipv4.subexample.example.tld"
        ServerAdmin "root@example.tld"
        UseCanonicalName Off

        DocumentRoot "/var/www/vhosts/example.tld/subexample.example.tld"
        CustomLog /var/www/vhosts/system/subexample.example.tld/logs/access_log plesklog
        ErrorLog "/var/www/vhosts/system/subexample.example.tld/logs/error_log"

        <IfModule mod_suexec.c>
                SuexecUserGroup "xxxx" "xxxx"
        </IfModule>

        <IfModule mod_userdir.c>
                UserDir "/var/www/vhosts/example.tld/web_users"
        </IfModule>

        <IfModule mod_sysenv.c>
                SetSysEnv PP_VHOST_ID "6a66d04f-d22f-4a30-bb80-ca47f117886a"
        </IfModule>

        ScriptAlias "/cgi-bin/" "/var/www/vhosts/example.tld/subexample.example.tld/cgi-bin/"

        Redirect permanent /plesk-stat https://subexample.example.tld/plesk-stat
        Redirect permanent /webstat https://subexample.example.tld/webstat
        Redirect permanent /webstat-ssl https://subexample.example.tld/webstat-ssl
        Redirect permanent /ftpstat https://subexample.example.tld/ftpstat
        Redirect permanent /anon_ftpstat https://subexample.example.tld/anon_ftpstat
        Redirect permanent /awstats-icon https://subexample.example.tld/awstats-icon

        <IfModule mod_ssl.c>
                SSLEngine off
        </IfModule>

        SetEnv PP_CUSTOM_PHP_INI /var/www/vhosts/system/subexample.example.tld/etc/php.ini
        SetEnv PP_CUSTOM_PHP_CGI_INDEX fastcgi

        <IfModule mod_fcgid.c>
                FcgidInitialEnv PP_CUSTOM_PHP_INI /var/www/vhosts/system/subexample.example.tld/etc/php.ini
                FcgidInitialEnv PP_CUSTOM_PHP_CGI_INDEX fastcgi
                FcgidMaxRequestLen 134217728
                FcgidIOTimeout 600
        </IfModule>

        TimeOut 600
        <Directory /var/www/vhosts/example.tld/subexample.example.tld>

                <IfModule mod_fcgid.c>
                        <Files ~ (\.fcgi$)>
                                SetHandler fcgid-script
                                Options +ExecCGI
                        </Files>
                </IfModule>
                <IfModule mod_fcgid.c>
                        <Files ~ (\.php$)>
                                SetHandler fcgid-script
                                FCGIWrapper /var/www/cgi-bin/cgi_wrapper/cgi_wrapper .php
                                Options +ExecCGI
                        </Files>
                </IfModule>

                Options -Includes +ExecCGI

        </Directory>

        <Directory /var/www/vhosts/example.tld/web_users>

                <IfModule mod_php4.c>
                        php_admin_flag engine off
                </IfModule>

                <IfModule mod_php5.c>
                        php_admin_flag engine off
                </IfModule>

        </Directory>

        <Directory /var/www/vhosts/subexample.example.tld>
                Options +FollowSymLinks
        </Directory>

        <Directory "/var/www/vhosts/system/subexample.example.tld/statistics">
                AuthType Basic
                AuthName "Domainstatistiken"
                AuthUserFile "/var/www/vhosts/system/subexample.example.tld/pd/d..httpdocs@plesk-stat"
                require valid-user
        </Directory>

        <IfModule mod_security2.c>
        </IfModule>
</VirtualHost>

好吧,我认为这应该让您了解我的问题。 先感谢您! 啊...请傻瓜解释一下...我知道一些...但显然还不够

编辑 1:

我再次尝试更改权限... 这次我创建了一个新组,将我的 matchGen 文件夹放入其中并尝试允许该组中的所有内容。

sudo addgroup Symfony --force-badname
Allowing use of questionable username.
Adding group `Symfony' (GID 1009) ...
Done.
sudo chown root.Symfony /var/www/vhosts/example.tld/subexample.example.tld/matchGen -R
chmod g+rwx /var/www/vhosts/example.tld/subexample.example.tld/matchGen

没有变化。

哦..我将用户 www-data 添加到组 Symfony。

编辑 2:

我尝试使用 http://symfony.com/doc/current/setup/web_server_configuration.html#web-server-apache-fpm,但没有任何改变。 重置后,我再次尝试打开 subexample.example.tld/matchGen/web/。 好吧,它没有用,但是这次错误似乎有所不同HTTP ERROR 500。 所以...再次查看 Looks 之后 --> mod_fcgid: stderr: PHP Fatal error: Uncaught exception 'UnexpectedValueException' with message 'The stream or file "/var/www/vhosts/example.tld/subexample.example.tld/matchGen/var/logs/prod.log" could not be opened: failed to open stream: Permission denied' in /var/www/vhosts/example.tld/subexample.example.tld/matchGen/var/cache/prod/classes.php:8203

肯定是权限问题。但为什么它不起作用? ... 我尝试使用本指南使用 acl 设置 www-data-user --> http://symfony.com/doc/current/setup/file_permissions.html#using-acl-on-a-system-that-supports-setfacl-linux-bsd

我没有在 setfacl 命令的末尾使用 var 或 /var,而是使用 matchGen 作为文件夹。

没有变化。

编辑 3:

我做到了! 在我到达编辑 2 之后的那个点后,这在这里帮助了我。 'Failed to open stream: Permission denied' error - Laravel

  1. 进入你的项目文件夹并使用php bin/console cache:clear --env=prod
  2. 跟进chmod -R 777 var
  3. composer dump-autoload
  4. 结束

终于...

如果您遇到同样的问题,以下是您应该检查的事项列表:

  • 运行 php bin/symfony_requirements 在您的项目文件夹中。您可能需要在 php.ini
  • 中设置时区
  • /etc/apache2/site-available 中为您的子域创建并激活一个 config/site 并使用 a2ensite subexample.example.tld.conf。创建文件时确保名称以.conf结尾。
  • 在你 create/change 权限使用你的项目文件夹中的 php bin/console cache:clear --env=prod 之前,然后使用 chmod -R 777 var 为你的 var 文件夹设置它们。使用 composer dump-autoload.
  • 在您的项目文件夹中完成它