You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让Ubuntu 16.04主机与Homestead VM实现文件实时同步?

Fixing Real-Time File Sync Issues Between Host and Homestead for Drupal

Hey there! Let's work through this problem where your Drupal site on Homestead isn't showing changes you make on your Ubuntu host—this is a super common hiccup for new Homestead users, so we'll get it sorted out step by step.

1. First, Clear Drupal's Cache (Most Likely Culprit!)

Drupal loves caching everything—pages, templates, config, you name it. Even if your files are syncing perfectly, old cache will make the site show stale content. Here are a few ways to clear it:

  • Via the Drupal UI: Visit your site's admin page at your-site-url/admin/config/development/performance and click the Clear all caches button.
  • Via Drush (faster!): SSH into your Homestead box with vagrant ssh, navigate to your Drupal root directory, then run:
    drush cr
    
  • No Drush? Use Drupal's rebuild script: Still in the Drupal root on the VM, run:
    php core/scripts/rebuild.php
    

2. Verify Vagrant Folder Sync Configuration

Even if you moved files to the Vagrantfile directory, we need to double-check Homestead's sync settings:

  1. Open your Homestead.yaml file (usually in ~/.homestead/ or your project's root).
  2. Look for the folders section—it should map your host directory to the VM's /home/vagrant/code (or a subfolder). Example:
    folders:
        - map: ~/your-project-directory  # This is your host folder with Drupal
          to: /home/vagrant/code          # This is where it lives on the VM
    
  3. Also confirm your Drupal site's Nginx configuration in Homestead.yaml points to the synced directory. For example:
    sites:
        - map: your-site.test
          to: /home/vagrant/code/your-drupal-root/web  # Match this to your synced Drupal web root
    
  4. If you made changes to Homestead.yaml, reload the VM with provisioning to apply them:
    vagrant reload --provision
    

3. Check File Permissions on the VM

Sometimes when files sync from the host to the VM, permissions get messed up, and Drupal can't read the updated files. SSH into the VM and run these commands (replace /home/vagrant/code/your-drupal-root with your actual path):

# Set correct owner for web server
sudo chown -R www-data:www-data /home/vagrant/code/your-drupal-root
# Set general read/write/execute permissions
sudo chmod -R 755 /home/vagrant/code/your-drupal-root
# Give write access to Drupal's files directory (critical for uploads and cache)
sudo chmod -R 777 /home/vagrant/code/your-drupal-root/sites/default/files

4. Ensure Real-Time Sync is Enabled

Homestead uses different sync mechanisms—if you're using rsync, it might not sync changes in real-time by default. Switching to NFS (faster and real-time) often fixes this:

  1. Edit your Homestead.yaml folders section to add the type: nfs option:
    folders:
        - map: ~/your-project-directory
          to: /home/vagrant/code
          type: "nfs"
          options:
              mount_options: ["rw", "vers=3", "tcp", "nolock"]
    
  2. On your Ubuntu host, install NFS server if you haven't already:
    sudo apt update && sudo apt install nfs-kernel-server
    
  3. Reload the VM with provisioning:
    vagrant reload --provision
    

5. Test if Files Are Actually Syncing

To rule out sync issues entirely, do a quick test:

  1. On your host, edit a simple file (like a template in your Drupal theme: sites/default/themes/your-theme/templates/page.html.twig) and add a comment like <!-- TEST SYNC -->.
  2. SSH into the VM and cat the same file:
    cat /home/vagrant/code/your-drupal-root/sites/default/themes/your-theme/templates/page.html.twig
    
  3. If you don't see the comment, your sync is broken—double-check your Homestead.yaml folders map, or try restarting the VM entirely:
    vagrant halt && vagrant up
    

Start with clearing the cache first—it's the most common fix. If that doesn't work, work through the other steps one by one, and you'll get your real-time updates working in no time!

内容的提问来源于stack exchange,提问作者B-zaro

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:12:46