Moment For Technology

Virtualbox directly constructs the pits that the Laravel development environment may encounter

Posted on May 28, 2023, 1:36 a.m. by 成雅慧
Category: The back-end Tag: npm laravel The back-end virtualbox

The previous project used VirtualBox+Vagrant to build the environment, without NFS enabled, the speed is really moving, so this environment did not use Vagrant, directly VirtualBox, who knows the pit things constantly

VirtualBox creates a laravel development environment

1. Mount and access shared directories

To enable directory sharing in VirtualBox, you need to install an enhanced plug-in.

Once you have installed this enhancement plug-in, you can manage mounting through mount. Assuming VirtualBox automount is enabled, it will automatically mount directories under Media /

2, the shared directory PHP modification permission

It is recommended not to try to manually mount the directory, after manual mount, the user and user group are root, and cannot be changed, PHP will not be able to modify the file because of permissions (no matter how you try, this problem costs 4H+ advise).

The auto-mounted directory user and group is root:vboxsf, at this point we will change the PHP startup user and user group

vim /usr/local/server/php/etc/php-fpm.d/www.conf
Copy the code
# the default
user = nginx
group = nginx
# modified to
user = nginx
group = vboxsf
Copy the code

I've also added nginx users to the vboxsf group here, which I don't know if it's decisive, but I suggest you do

usermod -a -G vboxsf nginx
Copy the code

Note: The modification of user and user group configurations takes effect after restart

Laravel Cache configuration

Clearing the cache often solves many problems

php artisan config:clear
php artisan cache:clear
php artisan config:cache
Copy the code
Four, NPM I

If you need to use Node.js, NPM I may encounter an error such as a soft connection unavailable when installing the module

VirtualBox's shared folders do not support soft connections, so either

npm install --no-bin-links
Copy the code

Tell NPM I can't use the soft link, you give me a different play, or

Install the module in NPM I (install node locally)

About (Moment For Technology) is a global community with thousands techies from across the global hang out!Passionate technologists, be it gadget freaks, tech enthusiasts, coders, technopreneurs, or CIOs, you would find them all here.