Deploying Laravel Project on Apache and MySQL on Windows

Ahmed Alhajri
3 min readJan 26, 2021

Laravel is a great PHP framework that contains dozens of useful features. Most of us started working on Laravel using “php artisan serve” command. The built in server is useful, but not fast enough. Thus, I decided to install Apache and MySQL rather than using XAMPP, and deployed my Laravel project in it. In this tutorial I’ll show you how you can deploy a Laravel project using native Apache and MySQL on Windows.

Requirements:

Before we start make sure you have installed:

  1. Apache server
  2. MySQL
  3. Laravel
  4. PHP

Step 1

Once you have installed Apache, put your Laravel project in “htdocs” directory. The path would look something like:

C:\Apache24\htdocs\myLaravelProject

The directory where you put your projects

Then, you need to make some changes in Apache configuration files:

  1. httpd-vhosts.conf

Path: C:\Apache24\conf\extra\httpd-vhosts.conf

Add a “VirtualHost” as following:

<VirtualHost 127.0.0.2:8082>

ServerAdmin webmaster@laravel

DocumentRoot “c:\Apache24\htdocs\myLaravelProject\public”

DirectoryIndex index.php

ServerName laravel

ErrorLog “logs/laravel-error.log”

CustomLog “logs/laravel-access.log” common

<Directory “c:\Apache24\htdocs\myLaravelProject”>

Options Indexes FollowSymLinks MultiViews

AllowOverride all

Require all granted

</Directory>

</VirtualHost>

Should look like this:

VirtualHost

I used 127.0.0.2, but you can use different IP like 127.0.0.3, or 4. Whichever IP you use, add it to hosts file in the following section.

2. httpd.conf:

Path: C:\Apache24\conf\httpd.conf

Make sure to uncomment this line:

3. hosts:

Path: C:\Windows\System32\drivers\etc\hosts

Add a localhost name resolution as following:

127.0.0.2 Laravel

By adding the resolution name, you will be able to access your local site through browser by “http://laravel:8082"

Step 2

After installing MySQL, make sure to create a database for your project and modify your database configuration in Laravel project as following:

Go to your project root directory and modify the .env file

Database settings

Note:

You might encounter an error with the database. in that case, make sure you have enabled pdo_mysql extension in php.ini

path: C:\php\php.ini

php.ini

Finally

To reflect these configuration changes in your Apache server restart it, either from services window or using a command.

Services Window:

Services window

If the server dose not restart or stop working, then check your configuration files you might have a syntax mistake in your code.

To restart by command, make sure your are in the right directory:

C:\Apache24\bin> httpd.exe -k restart

That’s it, if you encountered any errors, contact me I’ll try to help you.

Good luck!

--

--