My blog

posts

Effortless Laravel Setup on Windows: Unleash Custom Domains for Your Projects

In this tutorial, I will guide you through the process of setting up Laravel on your Windows machine and configuring it to run using a custom domain name. This tutorial is designed to be beginner-friendly, helping those new to Laravel quickly and easily get started. However, even if you're an experienced programmer, you may discover new ways to streamline the process of configuring Laravel projects. So, let's get started!


Setting Up Laravel on Windows with a Custom Domain: A Step-by-Step Guide


1. Installing and Starting XAMPP

XAMPP is a powerful open-source tool that lets you run an Apache server, MySQL database, and other development tools from a single interface.

Begin by downloading and installing XAMPP from the following link: XAMPP Download

After installation, launch the XAMPP Control Panel and start both the Apache and MySQL servers.


2. Setting Up Laravel

In your XAMPP installation, you'll find a folder called "htdocs." This is where you'll set up your Laravel application.

If you already have a Laravel application, you can clone it into the "htdocs" folder. Alternatively, you can create a new Laravel application by running the following command in your terminal:

composer create-project laravel/laravel example-app

Replace "example-app" with your desired project name.


3. Configuring Your Laravel Project

Open your preferred code editor and navigate to the "htdocs" folder. For this example, we'll use Visual Studio Code (VSCode).

In your Laravel project, locate the `.env` file. Here, find the `APP_URL` setting and replace its value with your desired custom domain name:

APP_URL=https://project.test

Replace "project.test" with your preferred domain name.


4. Modifying Your Hosts File

Access your Windows file explorer and navigate to `C:\Windows\System32\drivers\etc\hosts`. Open this file using an editor like VSCode (ensure you're running it with admin privileges).

Add the following line to the "hosts" file:

127.0.0.1 project.test

This maps the hostname "project.test" to your local IP address.


5. Configuring Apache Root Directory

Using your file explorer, go to `C:\xampp\apache\conf` and open the `httpd.conf` file, which contains Apache's configuration.

Under the section labeled `# Virtual hosts`, add the following configuration:

<VirtualHost *:80>
  ServerName project.test
  DocumentRoot "C:/xampp/htdocs/project/public"
  <Directory "C:/xampp/htdocs/project/public">
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Require all granted
  </Directory>
</VirtualHost>

Make sure to replace "project.test" with your custom domain name and the path to the public folder as appropriate.


6. Testing Your Configuration

Stop and restart the Apache server from the XAMPP interface. Now, when you visit "http://project.test" in your browser, you should see your Laravel project's homepage.


7. Conclusion

By following these steps, you've successfully set up Laravel on your Windows machine with a custom domain name. Remember that you can replicate this process for multiple projects, each with its own custom domain, by creating separate directories within the "htdocs" folder and configuring their individual Apache settings. This approach makes it easier to manage and test multiple Laravel projects simultaneously. Happy coding!


/

640 Laravel September 25, 2023 0 comments

0 Comments

Add a comment