To set up a Laravel project on your Windows machine using XAMPP

Share:

Prerequisites

  1. XAMPP Installed: Ensure XAMPP is installed and running on your system. Download it from Apache Friends.
  2. Composer Installed: Install Composer, the dependency manager for PHP. Download it from getcomposer.org.
  3. PHP Installed: XAMPP usually comes with PHP. Verify the PHP version is compatible with the Laravel version you intend to install.

Step-by-Step Guide

1. Start XAMPP Services

  1. Open the XAMPP Control Panel.
  2. Start Apache and MySQL.

2. Set Up a Database

  1. Open phpMyAdmin in your browser by visiting: http://localhost/phpmyadmin.
  2. Create a new database:
    • Click on New in the sidebar.
    • Name the database (e.g., laravel_db) and click Create.

3. Install Laravel Using Composer

  1. Open Command Prompt or PowerShell.
  2. Navigate to your XAMPP’s htdocs directory:bashCopycd C:\xampp\htdocs
  3. Create a new Laravel project:bashCopycomposer create-project --prefer-dist laravel/laravel laravel-app Replace laravel-app with your desired project folder name.

4. Configure .env File

  1. Navigate to your Laravel project directory:bashCopycd laravel-app
  2. Open the .env file in a text editor.
  3. Update the database configuration:envCopyDB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=laravel_db DB_USERNAME=root DB_PASSWORD= # Leave blank if no password is set for MySQL.

5. Serve the Laravel Application

  1. Run the Laravel development server:bashCopyphp artisan serve
  2. Access the application in your browser:arduinoCopyhttp://127.0.0.1:8000

6. Configure Apache (Optional)

If you prefer to access the Laravel project via http://localhost/laravel-app:

  1. Open the XAMPP httpd-vhosts.conf file:makefileCopyC:\xampp\apache\conf\extra\httpd-vhosts.conf
  2. Add the following configuration:apacheCopy<VirtualHost *:80> DocumentRoot "C:/xampp/htdocs/laravel-app/public" ServerName laravel-app.test </VirtualHost>
  3. Add the domain to your hosts file:
    • Open C:\Windows\System32\drivers\etc\hosts as an administrator.
    • Add this line:Copy127.0.0.1 laravel-app.test
  4. Restart Apache in the XAMPP Control Panel.
  5. Access the application via http://laravel-app.test.

7. Run Database Migrations

  1. Run the following command to set up tables in your database:bashCopyphp artisan migrate

Troubleshooting

  • If Composer is not recognized, ensure it’s added to your system’s PATH.
  • If the development server doesn’t start, ensure PHP is correctly configured in XAMPP.

You’re now set up to develop your Laravel project using XAMPP!

LET’S KEEP IN TOUCH!

We’d love to keep you updated with our latest news and offers 😎

We don’t spam! Read our privacy policy for more info.