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

@tms57
Copy link

tms57 commented Jun 4, 2022 via email

@Ninjaphil24
Copy link

Sorry, it doesn't let me properly write the closing tags for some reason.
##
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost

<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/laragigs/public"
ServerName laragigs.test
ServerAlias laragigs.test
ErrorLog "logs/laragigs.log"
CustomLog "logs/custom.laragigs.log" combined
<Directory "C:/xampp/htdocs/laragigs/public">
AllowOverride All
Order Allow,Deny
Allow from all
Require all granted
</ Directory>
</ VirtualHost>

But, without the space between / and Directory or / and VirtualHost.

@medAmineRg
Copy link

127.0.0.1 LARAVEL_PROJECT.test
127.0.0.1 laravel.test
127.0.0.1 localhost

##<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
##

<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/LARAVEL_PROJECT/public"
ServerName LARAVEL_PROJECT.test

@medAmineRg
Copy link

127.0.0.1 LARAVEL_PROJECT.test 127.0.0.1 laravel.test 127.0.0.1 localhost

##<VirtualHost *:80> DocumentRoot "C:/xampp/htdocs" ServerName localhost ##

<VirtualHost *:80> DocumentRoot "C:/xampp/htdocs/LARAVEL_PROJECT/public" ServerName LARAVEL_PROJECT.test

try that config guys

@AlexHJC
Copy link

AlexHJC commented Jul 6, 2022

using artisan like tms57 did worked for me. editing system32 files to configure a project seems unnecessary. using artisan completely bypasses all this setup. for just learning laravel this seems like the better path.

[edit] found a minor issue with using hyperlinks in 43:07 from the video. since the url is different using xampp you will likely need to add /laragigs/public/... to your a tag url.

also salehWeb's method below works well, should be the default method rather than the method written by brad.

@waltzacasio
Copy link

in editing the hosts file you can do this on windows 10:

You can edit and save the host file (C:\Windows\System32\drivers\etc\hosts) in a few simple steps: Copy or drag the host file to your machine's desktop. Edit the file with notepad or any word processor of your choice. Copy or drag the file back to the /system32/drivers/etc folder.

@sharmilatmn
Copy link

For macOS:

After installing XAMPP follow the instructions in this video to set up the vhost:
https://www.youtube.com/watch?v=wRq7dxvCR7U

When editing the httpd.conf file of the second time however do not change 'Group' from 'daemon', only 'User' as shown:
Screenshot 2022-08-11 at 13 15 02

This is what worked for me anyway (after way too much googling) :)

@nastanford
Copy link

One other minor change is instead of

#Include etc/extra/httpd-vhosts.conf

Use this one

#Include conf/extra/httpd-vhosts.conf

@francis-codex
Copy link

pls none of this, shit is working, any idea

@roddhenrick
Copy link

If you follow up closely the tutorial, at the end it's project_name.test instead of laravel.test

@Brosius-DT
Copy link

This works fine on Windows 10 with Xampp.
When you open Notepad, or the Editor of your choice, you have to open it with Administration Rights. Without this you can't save and your PC doesn't know where to look for your testing URL.

@phanuelmutuma
Copy link

phanuelmutuma commented Sep 23, 2022

If you follow up closely the tutorial, at the end it's project_name.test instead of laravel.test

Thanks, Should update the link to http://PROJECT_NAME.test

@PhilippeMallari
Copy link

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 for me too

@mpmphee
Copy link

mpmphee commented Oct 22, 2022

@bradtraversy Thanks for the tutorials. Well have encountered an error "The requested URL was not found on this server" but i was following the way you did.. Where did i go wrong? I am Using Laravel -V8

36:42 - Creating a Basic Model

@PhilippeMallari
Copy link

@bradtraversy Thanks for the tutorials. Well have encountered an error "The requested URL was not found on this server" but i was following the way you did.. Where did i go wrong? I am Using Laravel -V8

36:42 - Creating a Basic Model

Check the URL again if you are accessing the right URL from your end.

@mpmphee
Copy link

mpmphee commented Oct 22, 2022

@PhilippeMallari & @bradtraversy i have attached my screen short kindly assist..
listing blade
Listing Model
listings blade

web

@mpmphee
Copy link

mpmphee commented Oct 22, 2022

Well i managed..

    <h2>
        <a href="/listings/{{$listing['id']}}">
            {{$listing['title']}}
        </a>
    </h2>

I removed the first slash '/ ' before listings on the href then it worked

@aminatashin
Copy link

I still have problem to connect my windows to URL !!

@JurisBaltacs
Copy link

JurisBaltacs commented Jan 27, 2023

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

This is the only solution that worked for me. Thanks a lot!

@AbdoAitrais
Copy link

i have followed this video and it worked for me :
https://www.youtube.com/watch?v=d90VoXEgEV8&ab_channel=CodeForYou

make sure to change the hosts "C:\Windows\System32\drivers\etc\hosts" file with the correct path that you have put in the "C:\xampp\apache\conf\httpd.conf\httpd-vhosts.conf" file

AKA
LARAGIGS_PROJECT.test

@yournightmare01
Copy link

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: @.***>

Well played, this worked like a charm ;)

@x62
Copy link

x62 commented Jul 7, 2023

This gist worked fine for me. But I did have to restart the computer after installing Composer and again after editing the virtual hosts file. Then I could see laragigs.test.

@francis-codex
Copy link

good to know

@KayMohh
Copy link

KayMohh commented Aug 25, 2023

Well This was exactly how i did it too, using the conventional "php artisan serve ". Although the method brad used is cool, so you can have a customized name for your domain.
The most important thing is to get your site up and running

@KayMohh
Copy link

KayMohh commented Aug 25, 2023

if you are unable to edit your hosts file, open your cmd with admin priviledges and then navigate to the etc folder.
then type in
"notepad hosts"
make sure you save the changes after you have made your edits

@imannms000
Copy link

imannms000 commented Sep 21, 2023

Change server name from PROJECT_NAME.test to localhost. It's works!

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs"
    ServerName xampp.test
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/PROJECT_NAME/public"
    ServerName localhost
 </VirtualHost>

@HoussemMhiri
Copy link

https://youtu.be/ABxWF4WjLLE this worked for me

@Ango1415
Copy link

https://youtu.be/ABxWF4WjLLE this worked for me

For me too, just follow the original instructions of this post and change some names as in the example of the youtube video, works fine!
Thanks HoussemMhiri

@NathanMysolution
Copy link

I also struggled with the instructions on this page. I've documented the steps I took, and will paste them below.

This worked for me:

Software to Install

Install Xampp
Install Composer

Configure PHP.ini

Open Xampp and click on the Config button to the right of the Apache server. Choose PHP (php.ini) to edit the PHP configuration file.

Setup PHP Ini

Find the line that says ;extension=zip and remove the ; comment symbol to activate the ZIP extension.
Save the php.ini file.

Activate ZIP Extension

Setup a New Laravel Project

Open a new Command Prompt (tap Windows key and search for cmd).
Type cd \xampp\htdocs (or another path if you installed Xampp anywhere else)

Go to htdocs folder

Create a new Laravel Project (laragigs in the below example), by typing the following:

composer create-project --prefer-dist laravel/laravel laragigs

Create a Virtual Host

To setup a virtual http://laragigs.test host for testing purposes, do the following:

Open a File Explorer and go to C:/Windows/System32/drivers/etc.
Open the file called hosts in a text editor with Admin Privileges.

Add these two lines to the bottom of the hosts file:

127.0.0.1	localhost
127.0.0.1	laragigs.test

Save the file.

Then go to C:/xampp/apache/conf/extra and open the file called httpd-vhosts.conf.

Add these lines to the bottom:

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs"
    ServerName localhost
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/laragigs/public"
    ServerName laragigs.test
 </VirtualHost>

Save the document and restart the Apache Server in Xampp.

Restart Apache from XAMPP

Then surf to http://laragigs.test and you should see the default Laravel startpage.

Open Laravel Project Folder in Visual Studio Code

Open a Command Prompt if you haven't done so already and cd into the \xampp\htdocs\laragigs folder.

Now, type in code . to open the current folder in Visual Studio Code.

Open Laragigs in VS Code

Et voilá!

@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