duanlun4411
duanlun4411
2015-05-20 14:33
浏览 1.1k
已采纳

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

I've set up a Virtual host using PuPHPet (Vagrant-Puppet-PHP) Apparently PuPHPet creates a default site for me with this configuration 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>

And I've created this site config 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>

The default config is 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/*"

I've already disabled the 10-default_vhost_80 and reloaded apache however my DocumentRoot still points to /var/www/html/ am I missing something?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • drux41001
    drux41001 2015-05-20 15:07
    已采纳

    So what I did was made the /var/www/html into a symbolic link and point to /var/www/web. This solved my problem for the mean time.

    UPDATE
    I found another problem using the solution above, it affects the xdebug configuration I have and the process cannot find the files in /var/www/web because it is looking for the files in the symbolic link /var/www/html. So another work around is modify the 10-default_vhost_80.conf file and change /var/www/html to /var/www/web manually and restart the server. So far so good.

    UPDATE 2
    So the proper fix is that you need to make sure that the Directory Block is filled up in the puphpet configurator and it would produce the directories section you see in the yaml file below. I think this is due to that update to apache 2.4 why this needs to be done.

    So I ended up with this 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
    

    Also if you see that your PHP files aren't parsing make sure to include that files_match section. It's not added by the puphpet configurator automatically so you need to add that in via hard code.

    点赞 评论
  • doujiang5211
    doujiang5211 2015-06-08 13:39

    I changed the docroot path and the directories paths to /var/www/www, as below. This still creates the html folder, but serves from the www folder which is what I want.

    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
    
    点赞 评论
  • du1843
    du1843 2015-09-01 17:27

    I was also having this issue.

    For me, it was caused by the servername property in my puphpet/config.yaml file not matching the domain listed in my hosts file.

    I ensured the ip address and domain specified in my puphpet/config.yaml file:

    vm:
        network:
            private_network: 192.168.56.199
                      .
                      .
                      .
    
    vhosts:
        av_9kfiq4m95oac:
            servername: mysite.dev
            serveraliases:
                - www.mysite.dev
    

    matched what I specified in my hosts file:

    192.168.56.199 mysite.dev www.mysite.dev
    

    Oh, and don't forget to run vagrant provision after making changes to the puphpet/config.yaml file (that's caught me out a few times).

    点赞 评论

相关推荐