Virtual Host Xampp Laravel

Posted on by admin

Creating the Virtual Host in Apache. The virtual hosts in Apache can be found in the C: xampp apache conf extra httpd-vhosts.conf file. Open the file and insert an entry according to the following pattern (an answer from stackoverflow.com was very helpful – the related question also, it brought me to the article on SSL certificate setup).

Note: To start with, the only difference for this guideline, between XAMPP and WAMP or other Apache packages for Windows, is question where those packages are installed on your computer.

Introduction: vhost (virtual host) is a great solution if you intend to develop many independent project in php and keep them isolated from each others, like:

XAMPP Virtual Hosts. 17th November 2020 laravel, localhost, php, virtualhost, xampp. I am using virtual hosts for my laravel web development but now I wanted to 'refresh' my knowledge of PHP. But I have an issue when I type localhost I get one of my virtual hosts and then I cant for example type localhost/php-projects/index.php because there. Configure virtual host and system host on Laravel. Browse to, XAAMP/etc/extra/httpd-vhosts.conf open in any text editor and append at the end of file as below.

  • Project 1 is based on php and has local url address php.localhost
  • Project 2 is a Laravel project with url laravel.localhost
  • Project 3 is a Codeigniter with url codeigniter.locathost
  • Project 4 is a WordPress with url wordpress.locathost

You are expected to have installed the latest version of XAMPP/WAMP. Btw, in my case, I have only installed Apache and MySQL.

Set virtual host in xampp laravel

*Note: By default, most web servers will uses port 80 as default port, in some situation if you have another web server installed like (Microsoft IIS), it uses port 80 as well OR in other cases SKYPE does also some times use port 80 like it is the case for some in Windows 8/10 for some users, in that case you can do two thing’s

Laravel
  • Change your Apache port to port 8080, 8081 etc. or some other free ports (note: 8080 can some times also give some problems)
  • OR Change your others software/IIS port and keep Apache to default port 80 in case of Skype, just kill the Skype app and restart it after installing Apache on port 80, Skype will automatically get new port.

I have chosen to change my Apache to port 8080.

Note:
– For next section, we need to use text editor like notepad or regular IDE. I used sublime text editor.
– If you keep Apache to default port 80, skip this part and move on to Virtual hosts

Change XAMPP/WAMP port (only if necessary)
if left default, then jump to Setting virtual host

Step 1. Edit httpd.conf

Click on Config -> Apache (httpd.conf)
Or you find the file here C:XAMPPapacheconfhttpd.conf, C:XAMPPapache2confhttpd.conf, C:Bitnamiwampstackapacheconfhttpd.conf or C:Bitnamiwampstackapache2confhttpd.conf or similar location.

Change the line with

To 8080 or other, free ports.

While we have httpd.conf file open we need to ensure that httpd-vhosts.conf is included:
Include conf/extra/httpd-vhosts.conf

Virtual hosts

Xampp Vhost

Note: By default server documents are locate on C:XAMPPhtdocs or C:Bitnamiwampstackapache2htdocs that’s fine if you have only one project or many small test files. However, if you need to develop many projects then it suggested separating them by virtual host, as mentioned earlier.

Step 2. Setting Virtual host

  1. Create a folder for your projects; I have create one in c:vhost you can call it projects etc.
  2. In c:vhost folder we create a sub-folder domain1 or project1 or any other, it is up to you (c:vhostproject1)
  3. Open httpd-vhosts.conf file C:XAMPPapacheconfextrahttpd-vhosts.conf Add following code in line depending on how many vhost you want to create:

etc

Note: If you work on Laravel projects you can create unlimited Laravel projects as well as other frameworks like codeigniter, Yii, etc., the point is to
have your Laravel project/s on c:vhostlaravel1,
c:vhostlaravel2 etc and make c:vhostlaravel1public as
DocumentRoot etc as showed before. Each Laravel project will have own
VirtualHost URL.

Save and close the file

Some additional information and notes:

  • If port is remain default 80 then the URL address will be localhost
  • If port is remain default 80 then the the VirtualHost tag should be changed to <VirtualHost *:80>
  • If port is changed to 8080, the URL address will be localhost:8080
  • And the vhost URL address could look like this project1.localhost:8080 etc
  • You can add unlimited projects and virtual host like this way.

We are not ready yet, read more.

Step 3. Edit Windows Host file

  1. Stop Apache and MySQL services from XAMPP/WAMP.
  2. Open hosts file in C:windowssystem32driversetc
    you need Administrator privilege to edit the file.
    I suggest to edit the file directly with Sublime text editor.
  3. Add 127.0.0.1 project1.localhost at the end of the file, Save and close the file.

save the file

Final Step.
Start/Re-start your Apache and MySQL again.

Addition (Suggestion)

Note: You might need to delete your cache in your browser and also it
is good to disable php cache under development process.

Open file php.ini under php folder in your XAMPP or WAMP folder and
change opcache.enable to 0

Addition (Alternative solution)

It is possible to deploy temporary Virtual Server with out necessarily configuring XAMPP/WAMP Virtual Host, start CMD console and run following php command:

  • Port 8001 can be change to any available port number and be sure nor conflicting with other software ports.
  • c:vhostLaravel... path should be changed to what ever your project path.
  • It is possible to start multiple servers but should have different port numbers.

In your browser you need only to right

Note on 403 Access forbidden error

If you get a 403 Access forbidden error when you browse to your site, you may need to add this to your httpd.conf file:

  • Windows Installed System.

Laravel 5.7 requires PHP version 7.1.3 or more, and some other extensions. Since we are doing setup on XAMPP, it has all the required php extensions within it. Make sure to Install the XAMPP with version >=7.2.0

Install XAMPP

First of all we need to download and install XAMPP for Linux. Download it from the apache friends official website. Download the XAMPP version > 7.2.0 which contains PHP version 7.1.3

Follow the steps for XAMPP installation. For Windows, the default installation directory for XAMPP is C:xampp

Once the XAMPP is installed you should be able to access its manager console.

If your XAMPP is correctly installed and apache web server if turned on in the xampp control panel, You should see this page when you access http://locahost in your browser.

Once you are done with XAMPP, it’s now time to setup Composer.

Composer is a dependency management or package management tool which is integrated with Laravel Framework. Check by running composer command in your terminal if your system has composer already installed in it.

If not you can install it by following this tutorial How to Install Composer on Windows

The default directory of XAMPP for installing or keeping PHP project is htdocs. Navigate to following directory in your terminal C:xampphtdocs and run following composer command to create a fresh Laravel 5.7 version

After running this command composer should start downloading dependencies that are required to create the Laravel project.

When it finishes it will create a Laravel 5.7 project with following data structure.

Now, it’s time to run the Laravel project that we have installed. There are couple of ways you can do this.

#1 Artisan Command

Artisan command are built into the Laravel library, and one of it’s command it to serve the project on server. Navigate to the directory in which you have created your new laravel project and run following command.

And then, open the following link in the browser: http://localhost:8000

Laravel

#2 XAMPP Virtual Host.

If you are looking to assign a permanent domain to your project, you can do so by configuring the xampp virtual host.

We need to configure XAMPP Virtual Host to set the document root to correct directory of laravel project and to also assign a name to the project by which we will be accessing it in browser.

Navigate and open file C:xamppapacheconfextrahttpd-vhosts.conf and include following Virtual host entry in this file.

With this entry our apache is listening to laravel.local, but we also have to edit our hosts file to include an entry for the new domain.

Edit file C:WindowsSystem32driversetc and add following entry to that file.

Restart your apache and access laravel.local on your browser you should be able to see this screen.

Have Fun working with Laravel !

If you are looking for an updated tutorial that works with Laravel 5.8 and particularly gives details on setting up Laravel on Server checkout this tutorial -> Install Laravel.

Create Virtual Host Xampp

Xampp

Set Virtual Host In Xampp Laravel

Done with Laravel Setup, Go ahead and move to next step with the following tutorials.