Laravel 11.x + Backpack on MacOS using XAMPP

Lyubomir Filipov
6 min readDec 9, 2024

--

To proceed you need to have XAMPP installed on your computer.

Everything is as easy as it seems, well, no, especially if you have decided to use XAMPP on MacOS. By default, MacOS has more security rules than other OSs. One thing that would save you time is making sure that the running user for your Apache server is your current server.

Note: This is only for teaching purposes and not for serving on PRD. When planning to use a computer and serve the website from it, it is a good practice to have a specific user and a group for it.

Note: In MacOS PHP has been removed from Apache and it requires to be signed so the extension could be used.

#STEP 1: Check who is the current user on your computer

whoami

#STEP 2: Update httpd.conf and set the User and Group

Locate httpd.conf for XAMPP — it should be `/Applications/XAMPP/etc/httpd.conf` or where you have installed it. Open the file with your favorite editor and locate “User” and “Group”.

It should be something similar to

<IfModule unixd_module>
#
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.
#
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User daemon
Group daemon
</IfModule>

please update it to

<IfModule unixd_module>
#
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.
#
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User {your_username}
Group staff
</IfModule>

If you have permission issues with the folder please check.

#STEP 3: Install Composer if you are missing it

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'dac665fdc30fdd8ec78b38b9800061b4150413ff2e3b6f88543c636f7cd84f6db9189d43a81e5503cda447da73c7e5b6') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

Follow this link for more details.

#STEP 4: Download Laravel using composer

composer create-project laravel/laravel example-app

! Run this in the htdocs folder! In my case it is `/Applications/XAMPP/xamppfiles/htdocs`

The result should be something similar to the screenshot above. It is downloading all the required packages and then installing the app. It is not finding a DB connection so it is directly using SQLite database and it is running the migrations, but don’t worry we will adjust that.

#STEP 5: Check whether it works

php artisan serve

Execute the above inside the newly created example-app folder.

If you open any browser and navigate to the pointed URL you should see Laravel up and running

#STEP 6: Setup DB and user

Open your PHPAdmin that is served with XAMPP. It should be available for you if try to navigate to “http://localhost/phpmyadmin/” in your browser.

Click on SQL and paste the following

CREATE DATABASE `laravel-ninja`;

If executed without errors this will create a new database called laravel-ninja. You need to open your .env file inside the laravel folder example-app and adjust the following.

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel-ninja
DB_USERNAME=root
DB_PASSWORD=

#STEP 7: Setup Virtual host

Open `/Applications/XAMPP/etc/extra/httpd-vhosts.conf` and add the following

<VirtualHost *:80>
ServerName my-laravel.com
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/laravel-2024/public"
<Directory "/Applications/XAMPP/xamppfiles/htdocs/laravel-2024/public">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

# Add these lines
php_flag display_errors on
php_value error_reporting E_ALL
</VirtualHost>

Note: The DocumentRoot and the Directory might be different if you have used a different folder name when setting up Laravel. Keep in mind that the actual location of the folder also depend on where did you execute composer create-project.

Once you save the file, you need to restart Apache so the latest changes take effect. If it does not restart, there is an error in your syntax.

#STEP 8: Adjust hosts file

Adding a virtual host to apache is not enough, we need to adjust our hosts file as well. It is located in etc/hosts , open the file with your favorite editor and add

127.0.0.1 my-example.com

Save the file and then try to open `http://my-example.com/` in your browser. When doing that you should see

This is expected because in the DB we have not run php artisan migrate . Open the example-app folder and run the command.

Once this is done if you open your browser or just hit refresh

you will see Laravel served by your Virtual Host with apache from your XAMPP.

#STEP 9: Install Backpack

Backpack for Laravel is an admin panel that we are using in our exercises. We are using the Open-Source free version.

In order for us to install backpack we need to run

composer require backpack/crud

If the packages are downloaded the next step is to call install.

php artisan backpack:install

In the first question, we are going with the default option

We are not creating an admin user

and we are not installing premium addons

This is the result.

#STEP 10: Check installation

Open your browser and navigate to `http://my-example.com/admin`, this is what you should see

Create a user

and login

Note: Edit your .env file and adjust the domain, so it is not localhost.

Voila! You have Laravel 11.x with Backpack!

--

--

Lyubomir Filipov
Lyubomir Filipov

Written by Lyubomir Filipov

Group Architect at FFW, believer, developer, enthusiast

No responses yet