Using Raspberry Pi for Laravel developing

Ronie Meque
Nov 19, 2017 · 9 min read
Image for post

This article can be viewed in portuguese here.

If you are a Laravel developer and can’t afford a Mac or can’t migrate definitely for Linux distro because it lacks an app (Photoshop in my case), chances are high that you already got a bit frustatred in doing so in a Windows. If you also use Laravel Mix for some assets managing, like babel and sass, you have probabably got really frustrated at a point. It doesn’t matter how powerfull your Windows rig is, it’s going to be slow — mainly doing Composer install or handling Node.js.

There are a few options out there though:

  • Git Bash. It is possible to run everything you would do in a Linux distro inside the Git Bash shell that comes with Git for Windows, and it works really nice! Until then, this was my favorite method.
  • Homestead. Homestead is a nice little Ubuntu Vagrant box packed with everything you might need to do some Laravel developing, but according to personal experience and community feedback, it kinda sucks in Windows, in matters of speed mainly.
  • A dedicated Linux for the job. This is the case we will cover here, more specifically using a Raspberry Pi (It’s very cheap). If you have an old computer lying around it is probably worth a try either!

Anyway, what we want:

A Raspberry Pi device running a Laravel 5.5 application with PHP’s built-in server, automatically compiling frontend assets with Laravel Mix and serving all through the local network. We also want the project’s folder to be easily accessible through our local network, making it feel like we are editing the files from Windows inside our Raspberry Pi.


  • Local network
  • Lastest Raspbian (currently Stretch)
  • A decent command line in Windows. What I recommend: Git Bash alongside the Cmder or Hyper emulators. If you can’t or don’t want to use Git Bash, Cmder includes Clink which provides a few usefull Unix commands in Window’s command line.

Basic Raspberry Pi setup (OPTIONAL)

Remote access

  1. Entersudo raspi-config in the CLI.
  2. ChooseInterfacing Options and afterSSH
  3. Pickyes and close the menu

Now execute hostname -Ito find out what is your Pi’s local IP. Back to the computer, we can now access the Pi withssh pi@YOUR-PI-IP Example: ssh pi@

The default password is “raspberry”. It’s likelly that in the first connection you will have to type yes to confirm you trust the host.

Let’s configure a key so we won’t need to type the password again. If you don’t have a key on your PC, generate one using ssh-keygen -t rsa and confirm all the questions with an enter. The key will be stored in a .ssh folder in your home folder inside two files: id_rsa and

Back to your PC now execute ssh-copy-id -i path/to/ pi@YOUR-PI-IP Example: ssh-copy-id -i ~/.ssh/ pi@ Type the password for the last time and it’s done! 😮

Disabling the GUI and expanding the filesystem

In your remote CLI type sudo raspi-config

  • Navigate to Boot options , then Desktop / CLI and selectConsole
  • Back to the main menu, go toAdvanced Options and thenExpand Filesystem. When requested, reboot your Pi.

Sharing the Raspberry files across your local network

In your Pi, do the following:

  • sudo apt install samba samba-common-bin -y
  • sudo vim /etc/samba/smb.conf (Replace vim with any CLI editor you like or simply install vim with sudo apt install vim -y)
  • Find the following lines and edit them like follows: (The workgroup name can be anything alphanumeric)
workgroup = nicetidygroupy
wins support = yes
  • Add this at the end of the file (In this case we are sharing the whole home folder from the Pi user):
comment= Pi Home
only guest=no
create mask=0777
directory mask=0777
  • Save smb.conf file and do configure the sharing login with smbpasswd -a pi (Since this a local development server, I recommend using the same password from the Pi user — by default “raspberry”)
  • Restart samba so we can be sure everything will be ok: sudo /etc/init.d/samba restart

If everything went well, it’s likelly your Pi will now appear in your Windows network tab. When asked for a password, use the login “pi” alongside the password you defined in the last step.

Image for post
Image for post
Sharing Pi’s home to Windows

If your devices are connected through cable, the experience here will be just perfect, but it works really well in Wi-Fi too.

Installing PHP 7.0 and Composer on Raspberry Pi

sudo apt install php7.0 php7.0-curl php7.0-gd php7.0-imap php7.0-json php7.0-mcrypt php7.0-mysql php7.0-opcache php7.0-xmlrpc php7.0-xml php7.0-fpm php7.0-zip -y

Check if everything is ok by doingphp -v . The output should be something like:

Image for post
Image for post
It works!

Installing Composer

$ curl -sS | php$ sudo mv composer.phar /usr/local/bin/composer

Check if went well withcomposer --version

Image for post
Image for post

Installing MariaDB (mysql) on Raspberry Pi

In order to install it, execute: sudo apt install mariadb-server mariadb-client -y

Once again check if everything worked withmysql --version :

Image for post
Image for post

After installed you can access it withsudo mysql -u root -p .

Considering we are setting up a development only environment here, let’s make things easier by creating a new user and giving it full access to MariaDB. This will discard the need to sudoin MariaDB.

Execute sudo mysql -u root -p to access MariaDB and then do the following queries, replacing what is in bold with what you prefer.

CREATE USER 'user'@'localhost' IDENTIFIED BY 'pass';GRANT ALL PRIVILEGES ON * . * TO 'user'@'localhost';FLUSH PRIVILEGES;

After that you can access MariaDB by simply doing mysql -u usuario -p . You can also use these credentials in your application.

Installing Node.js on Raspberry Pi (OPTIONAL)

$ curl -sL | sudo -E bash -$ sudo apt install nodejs

Check if everything is ok with node -v

Image for post
Image for post

Creating a new Laravel app on Raspberry Pi

  • Create a new folder to hold our projects withmkdir ~/projectsand access it withcd ~/projects
  • Execute the following to create a new project based on Laravel’s default skeleton: composer create-project --prefer-dist laravel/laravel the-coolest-project-name

Everything should run fine and the project will be created! If composer complains that something is missing, try searching the package’s name and installing it with sudo apt install .

In this step Composer already installed all of Laravel’s backend dependencies.

Cloning an existing project

  • Clone your project using git. Example: git clone
  • acess the created folder with cd nice-little-app and install all of Laravel’s backend dependencies with composer install
  • configure your .env file, generate the app’s key, run your migrations and the usual Laravel setup.

Installing the dependencies for assets manipulation with NPM

Important detail: the output of npm’s installs in Raspbian is a lot more verbose and slower than the usual, but don’t worry because after everything is installed it will work like it should, depending on your project depencies, of course. Laravel Mix’s dependencies run perfectly in here so far!

Now that everything is working, let’s head to the final steps:

Running Laravel on Raspberry Pi with PHP’s built-in server

Execute the following: php artisan serve --host=YOUR-PI-IP (If you can’t remember the IP of your Pi, use hostname -I to see it).

Get ready now, it’s coming! In your PC, browse to http://YOUR-PI-IP:8000 and see the result. Example:

Automatically manipulating frontend assets with Laravel Mix on Raspberry Pi

Access your Pi in a new console tab without closing the one running the server and execute npm run dev inside your project’s folder. If all of your Sass, Less, Coffe, Typescript and etcetera compiled correctly, let’s set the compiling to happen automatically everytime a file is saved with npm run watch .

Note on Browsersync

If you would like to disable Browsersync at all everytime you use your Pi for developing but you don’t want to keep changing the webpack.mix.js settings and discarding it everytime, Laravel provides a nice way to solve this:

In your .env file, add something like this:


Now change your Browsersync call inside you webpack.mix.js file so it is surrounded by the following condition:

mix.browserSync({your options go here});

With that you can tell Laravel Mix that you don’t want Browsersync in this environment. Don’t forget to set it to true in the environments you want it enabled.

And that’s it

It’s likelly there are tons of ways to accomplish this procedure and it’s possible by the time you read this some things will be outdated. It’s very important to always pay attention to the names of the packages you are installing and the output of the commands you run. If you are doing this it’s quite probable you are used to being frustrated with broken packages or doing a lot of Google to fix tiny hidden errors that will only happen in your system.

I really hope this post will help anyone that tries to accomplish a similar result in using the Raspberry Pi as a development server, regardless of your PHP framework, versions and project requirements.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store