How To Setup Many Web Folders in XAMPP – Cross OS, Apache, MySQL, PHP, Perl (XAMPP) Stack for Web Development

The topic of this article is how to set up many web folders in XAMPP.

We assume you are an upper beginner at least a web developer in PHP/MySQL.


For complete beginners read here:
What is XAMPP & How To download:

https://www.apachefriends.org/download.html

https://www.javatpoint.com/xampp-vs-wamp-vs-mamp-vs-lamp


Using XAMPP you must know that: if installed to the default directory:

c:/xampp/

or

D:/xampp/

your web folder is:

c:/xampp/htdocs/

or

D:/xampp/htdocs/

respectively … and access as http://localhost/

What if your web projects as a PHP/MySQL Web Developer or/and JavaScript Web Developer are for example at:

D:/Documents/Web Projects/

or

C:/Documents/Web Projects/

and you do NOT want to move them to another directory…


Here you will learn how to – leave folders as are and add the directories as aliases to XAMPP setup/configuration:

D:/Documents/Web Projects/ alias e.g. /repo2, accessed as http://localhost/repo2/

or

C:/Documents/Web Projects/ alias e.g. /repo3, accessed as http://localhost/repo3/


For users who want to follow a SlideShare Presentation, go to -1- below;

For those who want to follow a YouTube video, go to -2- below…;

If you want a Fast How-To continue reading this Article below -3- …


-1-


-2-


-3-

For the example at the top of this article: let’s say we have a Development Windows 10 or 11 PC/Laptop & XAMPP installed at c:/xampp/ … :

Development folder-1:

D:/Documents/Web Projects/
alias e.g.
/repo2
accessed as http://localhost/repo2/

or

Development folder-2:

C:/Documents/Web Projects/
alias e.g.
/repo3
accessed as http://localhost/repo3/

repo2 or repo3 aliases names should be strings without space, avoid special chars, and must be anything string convenient to you.

You have to find the configuration file:
httpd-xampp.conf
and add the code at the bottom above the last line of

</IfModule>

FINAL RESULT:

Alias /repos2 "D:/Documents/Web Projects/"
<Directory "D:/Documents/Web Projects">
   AllowOverride AuthConfig
   Require local
</Directory>

Alias /repos3 "C:/Documents/Web Projects/"
<Directory "C:/Documents/Web Projects">
   AllowOverride AuthConfig
   Require local
</Directory>


</IfModule>

Usually, the httpd-xampp.conf is at:

C:\xampp\apache\conf\extra\httpd-xampp.conf

Alternatively, there is a shortcut to access XAMPP conf files, etc. files… see:




This article was a step-by-step ASAP Configuration/Setup.

For more details see the SlideShare Presentation and/or the YouTube Video.



Setup Laravel 10.x Homestead in Windows 10/11

Section – 1 [Install Software]

https://laravel.com/docs/10.x/homestead#installation-and-setup

vagrant_2.3.7_windows_amd64.msi – https://developer.hashicorp.com/vagrant/downloads

VirtualBox-6.1.46-158378-Win.exe – https://www.virtualbox.org/wiki/Download_Old_Builds_6_1

VirtualBox 6.1.46 (released July 18 2023) << This and Not the >> VirtualBox 7.0.10 platform packages – ​Windows hosts

According to: https://laravel.com/docs/10.x/homestead#installation-and-setup

Code Editor/IDE: PhpStorm-2023.1.4.exe or VSCodeSetup-x64-1.80.1.exe

Lastly install: Git-2.41.0.3-64-bit.exe – https://git-scm.com/downloads

Section – 2 [ENABLE VT-x in Hardware/BIOS/UEFI if disabled]

http://leonidassavvides.com/blog/2023/07/23/enable-vt-x-in-hp-z640-workstation/

Section – 3 [Installing Homestead]

https://laravel.com/docs/10.x/homestead#installing-homestead

Go To CLI Terminal in IDE/Editor or Windows Terminal or Git Bash Terminal and execute:

git clone https://github.com/laravel/homestead.git D:\htdocs_xampp\Homestead

where D:\htdocs_xampp\Homestead the Homestead directory, after entering this directory:

d:
cd d:\htdocs_xampp\Homestead

Next, execute the bash init.bat command from the Homestead directory to create the Homestead.yaml configuration file. The Homestead.yaml file is where you will configure all of the settings for your Homestead installation. This file will be placed in the Homestead directory: if there is a problem with the

init.bat 

use

./init.bat

Section – 4 [Configuring Homestead]

Follow the instructions at:

https://laravel.com/docs/10.x/homestead#configuring-homestead

For configuring the file: Homestead.yaml

Section – 5 [Launching The Vagrant Box]

After all, the steps above, it is time to:

Launching The Vagrant Box

You must have in mind the 4 most used CLI commands FROM CLI/Terminal at d:\htdocs_xampp\Homestead\:

vagrant up # if error on this - please Section 6 below
vagrant status
vagrant suspend
vagrant ssh

Section – 6 [Configuring SSH Keys]

In case the first attempt of running:

vagrant up

you getting

Please give the command to generate ssh keys in Windows:

ssh-keygen -t rsa -C "username@email.com"

This will create the:

C:\Users\lwdls\.ssh\id_rsa.pub
C:\Users\lwdls\.ssh\id_rsa

Then you have to go to Homestead.yaml and edit the SSH Keys with the correct Keys you have just created:

authorize: C:\Users\lwdls.ssh\id_rsa.pub
keys:
     - C:\Users\lwdls.ssh\id_rsa

Then you return to Section – 5 and give the command: vagrant up

The first time you have to await some time to download the Vagrant VM – Ubuntu Server from the repositories…

After the VM OK is launched go to: http://homestead.test/phpinfo.php to see the webpage of phpinfo():

phpinfo.php

<?php
phpinfo();
?>

if any problem put the phpinfo.php

in

public/phpinfo.php

to stop the VM – shutdown the PC – give

vagrant suspend

To add additional sites:

Adding Additional Sites

https://laravel.com/docs/10.x/homestead#adding-additional-sites

To create a Laravel Site – start with download Laravel files with the:

https://laravel.com/docs/10.x/installation#your-first-laravel-project

At Terminal d:\htdocs_xampp\

composer create-project laravel/laravel example-laravel-app

Composer can be installed from:

https://getcomposer.org/download/

Also, the composer comes preinstalled in Homestead/Vagrant/VM

And, a second way is:

After:

vagrant up 

Give:

vagrant ssh

and from Terminal at /home/vagrant/ give the command:

 composer create-project laravel/laravel example-laravel-app

Any way you choose, be sure to edit the Homestead.yaml and every new website added to run:

vagrant reload --provision

And lastly

To run a new URL locally modify the host file at:

On macOS and Linux, this file is located at /etc/hosts. On Windows, it is located at C:\Windows\System32\drivers\etc\hosts:

192.168.56.56 homestead.test
192.168.56.56 another1.test
192.168.56.56 another2.test

Again, according to

Homestead.yaml

After, download the Laravel 10.x bootstrap code base, view the Laravel homepage accordingly by going to http://another1.test.

Happy Laravel Web Development & Coding…!

Enable CORS for multiple domains in PHP

In this article, we’ll explain to you how to permit CORS requests for multiple origins in PHP.

To get the response from a simple cross-origin POST request, we need to include the header Access-Control-Allow-Origin. The specification of Access-Control-Allow-Origin allows for multiple origins, or the value null, or the wildcard *.

Access-Control-Allow-Origin: *
Access-Control-Allow-Origin: https://domainXYZ.com
Access-Control-Allow-Origin: null

The above is a simple implementation.

For multiple domains permissions of CORS, we can use a PHP snippet like below:

<?php
$allowedOrigins = [
   'https://domainXYZ.com',
   'https://z1.domainXYZ.com',
   'https://z2.domainXYZ.com',
   'https://z3.domainXYZ.com',
   'http://z4.domainXYZ4.com',
];

if(in_array($_SERVER['HTTP_ORIGIN'], $allowedOrigins))
{
	$http_origin = $_SERVER['HTTP_ORIGIN'];
} else {
	$http_origin = "https://example.com";
}
header("Access-Control-Allow-Origin: $http_origin");
?>