Skip to content

Instantly share code, notes, and snippets.

@bradtraversy
Created April 22, 2022 01:16
Show Gist options
  • Save bradtraversy/7485f928e3e8f08ee6bccbe0a681a821 to your computer and use it in GitHub Desktop.
Save bradtraversy/7485f928e3e8f08ee6bccbe0a681a821 to your computer and use it in GitHub Desktop.
Laravel Xampp setup on Mac and Windows

Laravel Xampp Setup (Windows & Mac)

Install Xampp

Install Xampp from https://www.apachefriends.org/index.html

  • Run the Xampp installer and open the Xampp control panel
  • Make sure that you enable the Apache and MySQL services
  • On mac you need to click "Start" on the Home tab, "Enable" on the Network tab and "Mount" on the Location Tab. Click "Explore" on the location tab to open your Xampp/Lampp folder

Install Composer

Go to https://getcomposer.org/download

  • On Windows, download and run the installer
  • On Mac, copy the php commands and run in the terminal. Then copy the mv command and run in terminal. You can also install composer with Homebrew

Create a New Laravel Project With Composer

Open a terminal in the htdocs folder. htdocs is where all of your local projects go.

htdocs folder location:

  • Windows - C:\Xampp\htdocs
  • Mac - /opt/lampp/htdocs
composer create-project --prefer-dist laravel/laravel PROJECT_NAME

Virtual Host Setup

We now need to create a virtual host for our project

Edit Hosts File

  • Windows - C:/Windows/System32/drivers/etc/hosts
  • Mac - /etc/hosts

Add these lines

127.0.0.1	localhost
127.0.0.1	PROJECT_NAME.test

Edit Virtual Hosts File

  • Windows - C:/xampp/apache/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs"
    ServerName localhost
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/PROJECT_NAME/public"
    ServerName PROJECT_NAME.test
 </VirtualHost>
  • Mac - /opt/lampp/etc/extra/httpd-vhosts.conf
<VirtualHost *:80>
    DocumentRoot /opt/lampp/htdocs
    ServerName localhost
    ServerAlias www.localhost
</VirtualHost>


<VirtualHost *:80>
    DocumentRoot /opt/lampp/htdocs/PROJECT_NAME/public
    ServerName PROJECT_NAME.test
    ServerAlias www.PROJECT_NAME.test
</VirtualHost>

Restart Apache with the Xampp panel

Now visit http://laravel.test ot htttp://laravel.test:8080 on Mac

If it does not work, make sure virtual hosts file is enabled in httpd.conf

  • Windows - C:/xampp/apache/conf/httpd.conf
  • Mac - /opt/lampp/etc/httpd.conf

Remove the # from the beginning of this line

#Include etc/extra/httpd-vhosts.conf

Save the file

@gi-tm
Copy link

gi-tm commented Aug 14, 2024

I couldn't get this to work either. I think what was meant was: http://laragigs.test/ rather than http://laravel.test/ but that also didn't work for me. What I did instead was use the artisan server: First I opened up a terminal (I didn't use VS Code for this - just cmd as I'm in Windows) Then I navigated to c:\xampp\htdocs\laragigs in that terminal (cd c:\xampp\htdocs\laragigs) Finally I entered: php artisan serve (and Enter) You should see a message: Starting Laravel development server: http://127.0.0.1:8000 (at least for me the port was 8000) In your browser type http://127.0.0.1:8000 (or whatever your port was other than 8000) as the url and you should be on your way. Using this method the root is c:\xampp\htdocs\laragigs and you should be able to follow along with Brad's tutorial, as I was, without having to change any config files etc. Hope this works for you! Ted

On Sat, Jun 4, 2022 at 5:10 PM rishisriv @.> wrote: @.* commented on this gist. ------------------------------ any update? I am also having issue using this gist to setup Laravel. After I do everything it says when I execute: Restart Apache with the Xampp panel Now visit http://laravel.test/ ot htttp://laravel.test:8080 on Mac I get server not found error. Please help. — Reply to this email directly, view it on GitHub https://gist.github.com/7485f928e3e8f08ee6bccbe0a681a821#gistcomment-4189526, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIPWFBP55S4ARJVREX7N2KDVNPH4TANCNFSM5UZMZOHA . You are receiving this because you commented.Message ID: @.***>

This worked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment