在Vhost Ubuntu子域文件夹上安装/配置Symfony3.2 - >错误403禁止和错误500

时间:2017-04-10 19:20:47

标签: apache ubuntu subdomain vhosts symfony-3.2

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

在我穿越泪水洞穴和永恒的自我怀疑的过程中,我看到了许多不同的错误,甚至实现了打破整个虚拟主义,包括我的电子邮件系统......很棒的工作。

嗯..现在我收到错误403 Forbidden。 好消息(至少对我而言):我看到了symfony的favicon,如果我尝试打开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。

我已经尝试过/做了以下事情:

现在为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。 所以...再看一下看起来后 - &gt; 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 - &gt; 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. 结束

    ...最后

1 个答案:

答案 0 :(得分:0)

如果您遇到同样的问题,请列出以下内容:

  • 在项目文件夹中运行php bin/symfony_requirements。您可能需要在php.ini
  • 中设置时区
  • /etc/apache2/site-available中为您的子域创建并激活配置/网站,然后使用a2ensite subexample.example.tld.conf。创建文件时,请务必使用.conf结束名称。
  • 在创建/更改权限之前,使用项目文件夹中的php bin/console cache:clear --env=prod,然后使用chmod -R 777 var为var文件夹设置它们。使用composer dump-autoload在项目文件夹中完成它。