💻 Setting a Local Development Environment for Laravel on Windows | 🚀 Install Laravel on Windows

3 weeks ago 14
ARTICLE AD BOX

Introduction

Many developers choose Windows as their primary environment for PHP projects. In this article, we'll walk you through setting up XAMPP for a Laravel project on Windows. By following these straightforward steps, you'll be able to run your PHP projects and install Laravel in just a few minutes.

Installing XAMPP for Laravel

  1. Download XAMPP

    Download XAMPP for Windows from the official site: XAMPP Download.

    For this guide, we are using PHP 7.1 and XAMPP 32-bit.

  2. Run the Installer

    Install XAMPP and choose Apache, MySQL, and phpMyAdmin. It's recommended to install XAMPP on C:\ (or the drive where Windows is installed) to avoid permission issues.

  3. Do Not Start Services Yet

    After the installation is complete, don't start any services immediately.

Configuring PHP in Windows CMD

  1. Set PHP Path

    Go to System Properties -> Advanced -> Environment Variables. In the Path variable, click Edit and add the path to XAMPP's PHP directory:

    C:\xampp\php

  2. Add MySQL Path

    Similarly, add MySQL's path:

    C:\xampp\mysql\bin

Installing Composer

  1. Download Composer

    Run the installer from the directory added to your Path (C:\xampp\php).

  2. Install Laravel

    Now that you have Apache, PHP, MySQL, and Composer installed, you can proceed with installing Laravel.

Setting Up Laravel and a Virtual Host

  1. Create a Laravel Project

    Open CMD or PowerShell and navigate to the XAMPP htdocs directory:

    cd C:\xampp\htdocs

    Then install Laravel using Composer:

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

  2. Create MySQL Database for Laravel

    In CMD or PowerShell, access MySQL CLI:

    mysql -u root -p

    Then create a database:

    CREATE DATABASE laravel DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

  3. Configure Laravel’s .env File

    Navigate to C:\xampp\htdocs\example and open config/database.php to configure the MySQL connection:

    'mysql' => [

    'driver' => 'mysql',

    'database' => 'laravel',

    'username' => 'root',

    'password' => 'YOUR_PASSWORD',

    'charset' => 'utf8mb4',

    'collation' => 'utf8mb4_unicode_ci',

    ],

  4. Set Up a Virtual Host

    Go to C:\xampp\apache\conf\extra and open httpd-vhosts.conf. Add the following configuration:

    DocumentRoot "C:\xampp\htdocs\example\public"

    ServerName example.com

    ServerAlias www.example.com

    Require all granted

  5. Enable mod_rewrite

    In C:\xampp\apache\conf\httpd.conf, find the line:

    LoadModule rewrite_module modules/mod_rewrite.so

    Remove the semicolon (;) at the beginning to enable URL rewriting.

  6. Edit Hosts File

    Navigate to C:\Windows\System32\Drivers\etc and open the hosts file with administrator privileges. Add:

    127.0.0.1 example.com www.example.com

Start Apache and MySQL

Start the XAMPP services for Apache and MySQL, and open your Laravel project locally at example.com.

Deploying Your Laravel Project

When you're ready to deploy, contact us to host your Laravel project on WebHostFace’s servers. Our hosting provides fast, reliable SSD Laravel Hosting at a discounted price, perfect for growing your online presence without a large investment!


Stay updated with our latest offers and news. Sign up for our newsletter!

Read Entire Article