← Other topics

Migrating Laravel site from XAMPP to Herd and DBngin

Video Notes

Laravel Herd is a fast PHP development environment for macOS. It includes everything you need to start Laravel development, including PHP, Composer, and Nginx.

If you’ve previously been developing Laravel applications with XAMPP, I recommend switching to Herd for these reasons:

  1. It’s faster
  2. It has a nicer interface with conveniences like easy PHP version switching and automatic site detection
  3. It’s built with Laravel in mind

The only downside of Herd is it’s not an “all in one” solution like XAMPP because it does not include a database server. For that, they suggest incorporating DBngin.

In this guide I’ll show how to migrate an existing site and MySQL database from XAMPP to Herd and DBngin.

Step 1) Export database from XAMPP MySQL

Step one of our migration is to export our site’s existing database from XAMPP’s MySQL so that we can later import it into our new setup with DBngin.

This can be accomplished with the following command, which will create a .sql dump of the given database_name to your desktop:

> /Applications/XAMPP/xamppfiles/bin/mysqldump -u root database_name > ~/Desktop/database_name.sql

Once the export is complete, make sure all services in XAMPP are stopped to avoid any port conflicts with Herd in the following steps.

Step 2) Install software

Next, download and install Herd and DBngin:

Step 3) Site paths

Open Herd and go to Settings → General and note the Herd paths that are listed. Any application directories you put in these paths will automatically be configured as sites.

Herd paths

As an example, I will be migrating my local codewithsusan.com site from XAMPP to Herd, so I will start by moving it’s directory from /Applications/XAMPP/xamppfiles/codewithsusan.com to /Users/Susan/Herd/codewithsusan.com:

> mv /Applications/XAMPP/xamppfiles/htdocs/codewithsusan.com /Users/Susan/Herd

Alternatively, instead of moving my sites into the Herd directory, I could add my existing /Applications/XAMPP/xamppfiles/ directory as one of my new Herd paths.

With the paths set, switch to the Sites tab and you should see it automatically recognize your new site folder and configures a URL following the pattern of http://directoryname.test. In my case, that’s http://codewithsusan.com.test

Herd sites

Step 4) Test the site URL

Load the site URL in your browser. On my initial load, I received a Laravel error indicating a TypeError within the code of one of my dependencies.

I suspected this was caused by an incompatibility with a PHP version jump between what I was running in XAMPP and what was now running in Herd. To address this, I ran composer update within my project to grab the latest updates to my dependencies and that did the trick to resolve the TypeError.

My next error though, was about my MySQL connection because I still have to set up DBngin and my database:

Step 5) Set up DBngin

In DBngin, click the plus sign to add a new server. Change the Service to MySQL, and enter MySQL for the name. Leave all the other options as the defaults and click Create.

Once created, make sure your new service is running:

Step 6) Import database

Next we want to create and import the database we backed up in the first step.

To do this, first enter the MySQL command line mode with this command:

> /Users/Shared/DBngin/mysql/8.0.33/bin/mysql -u root -h

Within the MySQL command line, use the CREATE DATABASE SQL command to create your new database:

mysql> create database database_name;

You can confirm the database was created with the show databases command:

mysql> show databases;

Next, to import our backup we’ll first select our database with the use command:

mysql> use database_name;

And then import the database backup with source command:

mysql> source ~/Desktop/database_name.sql

When the import is complete you can confirm it worked by outputting a list of tables:

mysql> show tables;

You can use the exit command to exit the MySQL command prompt.

mysql> exit;

Step 7) Final test

With your database set up, you should now be able to refresh your site without any receiving any SQL errors:

Repeat for other sites

When setting up other sites, here are the steps you would need to repeat:

  1. Move the site folder into your Herd directory
  2. Export database
    • Stop DBngin’s MySQL and start XAMPP’s MySQL
    • Export database with the command /Applications/XAMPP/xamppfiles/bin/mysqldump -u root database_name > ~/Desktop/database_name.sql
    • Stop XAMPP’s MySQL and restart DBngin’s MySQL
  3. Test it

If this info helped you out you can say thanks and support future content by clicking my Amazon affiliate link: https://amzn.to/3UtgnYk. If you make a purchase on Amazon within 24 hours of clicking the link I may receive a micro-commission and it costs you nothing extra. Any income from these sales goes directly to supporting me in making new videos and guides. Thank you for your support!

← Other topics