How to Set Up Laravel on Windows Using XAMPP: A Step-by-Step Guide for Developers
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 XAMPPDownload XAMPP for Windows from the official site: XAMPP Download.For this guide, we are using PHP 7.1 and XAMPP 32-bit.
- Run the InstallerInstall 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 YetAfter the installation is complete, don't start any services immediately.
Configuring PHP in Windows CMD
- Set PHP PathGo 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 PathSimilarly, add MySQL's path:C:\xampp\mysql\bin
Installing Composer
- Download ComposerDownload Composer's Windows installer: Composer Download.Run the installer from the directory added to your Path (C:\xampp\php).
- Install LaravelNow 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 ProjectOpen CMD or PowerShell and navigate to the XAMPP htdocs directory:cd C:\xampp\htdocsThen install Laravel using Composer:composer create-project --prefer-dist laravel/laravel example
- Create MySQL Database for LaravelIn CMD or PowerShell, access MySQL CLI:mysql -u root -pThen create a database:CREATE DATABASE laravel DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
- Configure Laravel’s .env FileNavigate 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 HostGo to C:\xampp\apache\conf\extra and open httpd-vhosts.conf. Add the following configuration:DocumentRoot "C:\xampp\htdocs\example\public"ServerName example.comServerAlias www.example.comRequire all granted
- Enable mod_rewriteIn C:\xampp\apache\conf\httpd.conf, find the line:LoadModule rewrite_module modules/mod_rewrite.soRemove the semicolon (;) at the beginning to enable URL rewriting.
- Edit Hosts FileNavigate 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!
Post a Comment
0Comments