laravel+mac+xampp

We noticed that Laravel installation for XAMPP users in Mac is a little problematic. New XAMPP release is using VM to run, however it’s quite limited so here is how to quickly get it up and running. Notice that this was tested on MacOS Catalina 10.15.6. First download the version you want to install of XAMPP from https://www.apachefriends.org/download.html :

You will get a VM in dmg format that you can drag and drop into your applications folder.

Now after running XAMPP server, make sure to mount the volume of the VM so you can access it directly from your mac. So this was the first issue faced as the XAMPP seems to not being able to mount the disk locally, but if you hit the explore button it will open the files in the VM. So what’s missing ?

As you can see in the screenshot, the /opt/lampp folder is opened from nfs://192.168.64.2/opt/lampp thing what can finder do without having to mount the folder locally. So let’s mount the folder locally so we can access it as a local folder :

hatem@Mac:/opt$ sudo mkdir lampp
hatem@Mac:/opt$ sudo mount -t nfs -o resvport,rw 192.168.64.2:/opt/lampp /opt/lampp

ls from your local directory /opt/lampp and you will see the VM content. Now we have a new XAMPP installed, let’s start by updating and installing the necessary packages. From XAMPP general tab hit the “Open Terminal” button :

You will find yourself in a terminal like this one, and as you can see it’s a Debian 4.19.0.9 VM

First thing to do is to update apt, upgrade necessary packages then install few additional packages to install Laravel : unzip, composer and probably a text editor like vi or nano. So simply run the commands below :

root@debian:/opt/lampp/htdocs# apt update 
root@debian:/opt/lampp/htdocs# apt upgrade
root@debian:/opt/lampp/htdocs# apt install unzip nano
root@debian:/opt/lampp/htdocs# curl -s https://getcomposer.org/installer | php
root@debian:/opt/lampp/htdocs# mv composer.phar /bin/composer
root@debian:/opt/lampp/htdocs# composer create-project --prefer-dist laravel/laravel test

Once we started creating the Laravel project we hit the second issue ! Can’t allocate memory.

The issue is that the VM is running with only 1GB ram and no swap, so let’s add 1GB swap file

root@debian:/opt/lampp/htdocs# free -m
              total        used        free      shared  buff/cache   available
Mem:            985         194         740           5          50         693
root@debian:/opt/lampp/htdocs# fallocate -l 1G /swapfile
root@debian:/opt/lampp/htdocs# chmod 600 /swapfile 
root@debian:/opt/lampp/htdocs# swapon /swapfile 
root@debian:/opt/lampp/htdocs# free -m
              total        used        free      shared  buff/cache   available
Mem:            985         194         737           5          54         692
Swap:          1023           0        1023
root@debian:/opt/lampp/htdocs# composer create-project --prefer-dist laravel/laravel test

Now we have some swap, and the commands are self explanatory so you understand if you want to add 2GB or more how to do it. Let’s run composer again and this time the command will work correctly and install Laravel. Make sure to enable the necessary chmod for Laravel storage :

root@debian:/opt/lampp/htdocs# cd test/storage
root@debian:/opt/lampp/htdocs# chmod 777 -R .

Now you can access Laravel from your browser for example http://192.168.64.2/test/public and you should see something like this :

Of course don’t forget to make the swap permanent in the VM by updating the /etc/fstab file and adding this line “/swapfile swap swap defaults 0 0” without quotes :

root@debian:/opt/lampp/htdocs# nano /etc/fstab 

That’s all, just don’t get lost ! When you see root@debian you are in the VM, and when you see hatem@Mac you are in the Mac. So now you can open from your editor /opt/lampp/htodcs/test/ and starting editing your project. Happy coding !

LEAVE A REPLY

Please enter your comment!
Please enter your name here