问题
I cannot seem to allow permissions in vagrant. I am attempting to run importbuddy.php in order to migrate a WordPress instance. I get the following error.
file_put_contents(/path/): failed to open stream: Permission denied
I have setup permissions to 777 on the www
directory, but that changes nothing. Any idea on how to fix this?
回答1:
While recursively setting folder and file permissions to 777 should fix your problem (instructions for doing so here), the root of this is probably an issue with the ownership of the files and folders.
The owner of shared folders is usually 'vagrant' but the server itself (if you're using Ubuntu) runs as user and group 'www-data'. You can view the user/group of your files by sshing into your VM (vagrant ssh
), navigating to the directory in question and entering ls -l
in your console.
If you're running apache, then you can update the user to 'vagrant' by editing the following file (/etc/apache2/envvars
) like below:
Find this section
export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data
And change it to
export APACHE_RUN_USER=vagrant
export APACHE_RUN_GROUP=vagrant
Afterward just be sure to restart apache (with this command sudo service apache2 restart
) and the file permission errors should be fixed
来源:https://stackoverflow.com/questions/30854013/vagrant-file-put-contents-permission-denied