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
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.
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.
Do Not Start Services Yet
After the installation is complete, don't start any services immediately.
Configuring PHP in Windows CMD
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
Add MySQL Path
Similarly, add MySQL's path:
C:\xampp\mysql\bin
Installing Composer
Download Composer
Run the installer from the directory added to your Path (C:\xampp\php).
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
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
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;
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',
],
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
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.
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!