DocumentRoot始终默认为/ var / www / html,无法更改

时间:2015-05-20 14:33:10

标签: php apache vagrant document-root puphpet

我已经使用PuPHPet设置了虚拟主机(Vagrant-Puppet-PHP)显然PuPHPet使用此配置为我创建了一个默认网站10-default_vhost_80.conf

 <VirtualHost *:80>
   ServerName default

   ## Vhost docroot
   DocumentRoot "/var/www/html"

   ## Directories, there should at least be a declaration for /var/www/html

   <Directory "/var/www/html">
     Options Indexes FollowSymlinks MultiViews
     AllowOverride All
     Require all granted

     <FilesMatch "\.php$">
       Require all granted
       SetHandler proxy:fcgi://127.0.0.1:9000
     </FilesMatch>

   </Directory>

   ## Logging
   ErrorLog "/var/log/apache2/default_vhost_80_error.log"
   ServerSignature Off
   CustomLog "/var/log/apache2/default_vhost_80_access.log" combined
 </VirtualHost>

我已创建此网站配置site_dev.conf

<VirtualHost *:80>
 ServerName site.dev

 ## Vhost docroot
 DocumentRoot "/var/www/web"

 ## Directories, there should at least be a declaration for /var/www/web

 <Directory "/var/www/web">
   Options Indexes FollowSymlinks MultiViews
   AllowOverride All
   Require all granted

   <FilesMatch "\.php$">
     Require all granted
     SetHandler proxy:fcgi://127.0.0.1:9000

   </FilesMatch>

 </Directory>

 ## Logging
 ErrorLog "/var/log/apache2/av_0rjxvm6sfxhm_error.log"
 ServerSignature Off
 CustomLog "/var/log/apache2/av_0rjxvm6sfxhm_access.log" combined

 ## Server aliases
 ServerAlias www.site.dev

 ## SetEnv/SetEnvIf for environment variables
 SetEnv APP_ENV dev
</VirtualHost>

默认配置为apache2.conf

 ServerName "local.puphpet"
 ServerRoot "/etc/apache2"
 PidFile ${APACHE_PID_FILE}
 Timeout 120
 KeepAlive Off
 MaxKeepAliveRequests 100
 KeepAliveTimeout 15

 User www-data
 Group www-data

 AccessFileName .htaccess
 <FilesMatch "^\.ht">
     Require all denied
 </FilesMatch>

 <Directory />
   Options FollowSymLinks
   AllowOverride None
 </Directory>


 HostnameLookups Off
 ErrorLog "/var/log/apache2/error.log"
 LogLevel warn
 EnableSendfile Off

 #Listen 80


 Include "/etc/apache2/mods-enabled/*.load"
 Include "/etc/apache2/mods-enabled/*.conf"
 Include "/etc/apache2/ports.conf"

 LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
 LogFormat "%h %l %u %t \"%r\" %>s %b" common
 LogFormat "%{Referer}i -> %U" referer
 LogFormat "%{User-agent}i" agent

 IncludeOptional "/etc/apache2/conf.d/*.conf"
 IncludeOptional "/etc/apache2/sites-enabled/*"

我已经停用了10-default_vhost_80并重新加载了apache但是我的DocumentRoot仍然指向/var/www/html/我错过了什么?

3 个答案:

答案 0 :(得分:1)

所以我所做的是将/var/www/html变为符号链接并指向/var/www/web。这解决了我平时的问题。

<强>更新
我发现使用上述解决方案时出现了另一个问题,它会影响我的xdebug配置,并且该进程无法找到/var/www/web中的文件,因为它正在查找符号链接/var/www/html中的文件。所以 另一种解决方法是修改10-default_vhost_80.conf文件并手动将/var/www/html更改为/var/www/web并重新启动服务器。到目前为止一切都很好。

更新2
因此,正确的解决方法是您需要确保Directory Block配置器中填充了puphpet,并且它会生成您在directories文件中看到的yaml部分下面。我认为这是由于apache 2.4更新为什么需要这样做。

所以我最终得到了这个config.yaml

    av_s4zfpb2muecx:
        servername: sandbox.dev
        serveraliases:
            - www.sandbox.dev
        docroot: /var/www/web
        port: '80'
        setenv:
            - 'APP_ENV dev'
        custom_fragment: ''
        ssl: '0'
        ssl_cert: ''
        ssl_key: ''
        ssl_chain: ''
        ssl_certs_dir: ''
        ssl_protocol: ''
        ssl_cipher: ''
        directories:
            avd_e84h116m6dg3:
                path: /var/www/web
                options:
                    - Indexes
                    - FollowSymlinks
                    - MultiViews
                allow_override:
                    - All
                require:
                    - 'all granted'
                custom_fragment: ''
                files_match:
                    avdfm_e84h116m6dg3:
                        path: \.php$
                        sethandler: 'proxy:fcgi://127.0.0.1:9000'
                        custom_fragment: ''
                        provider: filesmatch
                provider: directory

此外,如果您发现PHP文件未解析,请确保包含files_match部分。它不是由puphpet配置程序自动添加的,因此您需要通过硬编码添加它。

答案 1 :(得分:0)

我将docroot路径和目录路径更改为/ var / www / www,如下所示。这仍然会创建html文件夹,但是从我想要的www文件夹中提供。

vhosts:
    av_dpp1xawpupht:
        servername: mysite.local
        serveraliases:
            - www.mysite.local
        docroot: /var/www/www
        port: '80'
        setenv:
            - 'APPLICATION_ENV development'
        custom_fragment: ''
        ssl: '0'
        ssl_cert: ''
        ssl_key: ''
        ssl_chain: ''
        ssl_certs_dir: ''
        ssl_protocol: ''
        ssl_cipher: ''
        directories:
            avd_rtgzo3tlwbux:
                path: /var/www/www
                options:
                    - Indexes
                    - FollowSymlinks
                    - MultiViews
                allow_override:
                    - All
                require:
                    - 'all granted'
                custom_fragment: ''
                files_match:
                    avdfm_q9dzltiv10d5:
                        path: \.php$
                        sethandler: 'proxy:fcgi://127.0.0.1:9000'
                        custom_fragment: ''
                        provider: filesmatch
                provider: directory

答案 2 :(得分:0)

我也有这个问题。

对我来说,这是由我servername文件中的puphpet/config.yaml属性与我hosts文件中列出的域不匹配引起的。

我确保了puphpet/config.yaml文件中指定的IP地址和域名:

vm:
    network:
        private_network: 192.168.56.199
                  .
                  .
                  .

vhosts:
    av_9kfiq4m95oac:
        servername: mysite.dev
        serveraliases:
            - www.mysite.dev

匹配我在hosts文件中指定的内容:

192.168.56.199 mysite.dev www.mysite.dev

哦,并且在对vagrant provision文件进行更改后,不要忘记运行puphpet/config.yaml(这已经让我抓了几次)。