8) Configure apache on guest/vm to point to the shared folder. There are a couple of ways to do this. Easiest would probably be to edit the default apache conf file to just point to /var/www/my-project/public, but for some reason I've chosen to add a vhost file on my guest/vm machine that points to the shared source.
edit the new hosts file
sneakyimp@guest-vm$ sudo nano /etc/apache2/sites-available/my-project.conf
put this in it:
<VirtualHost *:80>
#### THIS IS my-project.conf ON THE GUEST/VM MACHINE ####
ServerName myproj.com # I will add an entry on the host machine to point this domain to 192.168.1.5
ServerAlias www.myproj.com # same goes for this one
DocumentRoot /var/www/my-project/public # path to public directory in the shared folder
ServerAdmin sneakyimp@example.com
UseCanonicalName Off
# this is for .htaccess or something like that
<Directory /var/www/my-project/public>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
# optional custom logs...make sure this subdir exists or you'll have trouble
CustomLog /var/log/apache2/my-project/access.log combined
ErrorLog /var/log/apache2/my-project/error.log
</VirtualHost>
enable the site using the apache command on the guest machine
sneakyimp@guest-vm$ sudo a2ensite my-project
restart apache on the guest machine
sneakyimp@guest-vm$ sudo service apache2 restart
check the apache log file at /var/log/apache2/error.log for problems
9) Make an entry on the host machine to point a domain at the vm. This is not strictly required but I do it in order to avoid typing in numbers all the time. On my workstation/host machine, I make two entries in the hosts file to map some domain onto the guest/vm machine. NOTE: the domain must match the one in the apache conf above and should not be any real domain that you ever plan to visit because you'll just be looking at your guest/vm machine instead.
sneakyimp@host$ sudo nano /etc/hosts
enter this:
# these MUST match the IP and apache conf ServerName and ServerAlias values above
192.168.1.5 myproj.com
192.168.1.5 www.myproj.com
you should now be able to access the guest/vm machine via http://myproj.com. You may still have an issue, however, because apache on the guest/vm needs write access to the files. If it does not, then you'll get a blank white screen or a "whoops" message from laravel.
10) Check permissions on the host machine's source files. The mount command we used above results in all the contents of the shared folder being owned as root:root when viewed from the guest/vm machine. To make these files writable by apache running on the guest/vm machine we have two options:
EDIT: the following permissions approaches 10a and 10b will not work in my case because once a file gets written to these directories (e.g., storage/logs/laravel.log), that file cannot be written again due to the default apache umask. More precisely, the file is 644 and so www-data, even though it is part of the vboxsf group, cannot write it. Solution? Change apache umask?
10a) Just set perms to 777/666 in the necessary directories. On the host machine, you should be able to run these commands to make sure all the necessary files are writable by anyone. It's not secure really, but it's simple. On the HOST machine:
cd /path/to/my-project
sudo find storage -type d -exec chmod 777 {} \;
sudo find storage -type d -exec chmod g+rws {} \;
sudo find storage -type f -exec chmod 666 {} \;
sudo find bootstrap/cache -type d -exec chmod 777 {} \;
sudo find bootstrap/cache -type d -exec chmod g+rws {} \;
sudo find bootstrap/cache -type f -exec chmod 666 {} \;
10b) Unmount the shared folder, remount it with different options,and set permissions on host machine. This is a bit more complicated but also a bit more secure.
On the GUEST machine, unmount the shared folder:
sudo umount /var/www/my-project
On the GUEST machine, add your user (sneakyimp, in my case) and apache (www-data) to the group vboxsf:
sudo usermod -a -G vboxsf sneakyimp
sudo usermod -a -G vboxsf www-data
On the GUEST machine, find the group id of the group vboxsf:
sneakyimp@guest-vm$ grep vboxsf /etc/group
vboxsf:x:999:sneakyimp,www-data
In this case, it's 999. Put that 999 into this mount command on the GUEST machine:
sudo mount -t vboxsf -o uid=$UID,gid=999 my-project-share /var/www/my-project
This has the effect of mounting the shared folder such that files are owned by the current user and have group vboxsf.
Then, on the HOST machine, make sure permissions are set correctly on the storage and bootstrap/cache folders. Note how these permissions are slightly tighter:
cd /path/to/my-project
sudo find storage -type d -exec chmod 775 {} \;
sudo find storage -type f -exec chmod 664 {} \;
sudo find bootstrap/cache -type d -exec chmod 775 {} \;
sudo find bootstrap/cache -type f -exec chmod 664 {} \;
11) And lastly (hopefully??) you may encounter a "whoops" type message from Laravel when viewing the page in your browser. If that's the case, make sure you have a .env file in the project root. If not, copy .env.example to .env -- do this on the GUEST machine:
cd /var/www/my-project
cp .env.example .env
then try this on the GUEST machine (because in my case these commands won't run on host machine):
cd /var/www/my-project
php artisan key:generate
php artisan config:clear
For some additional (but confused & unfocused) information, see:
https://github.com/laravel/framework/issues/9080