How to set up multiple WordPress sites using XAMPP

XAMPP is used by many WordPress administrators to set up WordPress environments. While there are many different uses for enclosures, some of the more common use cases are to set up a staging, development, or test environment. As a highly configurable environment, XAMPP offers many advantages, including the ability to configure multiple WordPress sites through virtual hosts.

What is XAMPP?

XAMPP is what is called a development environment. It includes all the packages that a PHP developer needs to develop PHP software. At the same time, it provides us with everything we need to set up a WordPress environment.

WordPress needs quite a few things to function. The server or hosting plan, where all the components are installed and running, and the domain name are two things we are all familiar with. However, the server also needs a number of software packages to run WordPress. These include:

Web server – The web server is what actually delivers the WordPress website. There are many different web servers available including Nginx, Apache, and IIS, along with XAMPP, including Apache.

SQL Database – WordPress uses an SQL database to store data. While most are familiar with the MySQL flavor of SQL, in many cases what you get is MariaDB. It is important to note that many people and organizations use the terms interchangeably.

Geek note: MySQL was acquired by Oracle in 2009. Due to problems related to this acquisition, several MySQL developers have entrusted the development to MariaDB. MariaDB has meanwhile become one of the most used RDBMS.

PHP – PHP is the language WordPress is written in and is required by WordPress to function. This is necessary because the WordPress code needs to be executed by the web server, which we can only do if PHP is installed.

XAMPP includes all of the above in one easy-to-install package. Instead of installing each item individually, we get an installer that provides everything, which makes it much easier to install all the components we need without worrying about dependencies and configurations.

By the way, XAMPP also includes Perl. While this is not necessary to run WordPress, more technical WordPress administrators can use it to write scripts.

Another thing that comes with XAMPP that you might appreciate is Bitnami for XAMPP. Bitnami is a software product of applications packaged by VMware that allows us to install modules such as WordPress as easily as we would install any other software. With XAMPP and Bitnami, we can have a full staging environment up and running in minutes.

Geek note: The X in XAMPP indicates that it is available for multiple operating systems. In this case, you can download XAMPP for Windows, Mac OS, and Linux.

Why use XAMPP?

XAMPP makes it easy to install everything we need to build a WordPress development environment in one convenient package. Of course, you can also download and install each package individually, and the end result will be the same – provided you’re comfortable getting your hands dirty with the configuration files.

Downloading XAMPP

As previously stated, XAMPP is available for all major operating systems including Windows, Linux, and Mac. As such, whatever your configuration, you can download XAMPP for your operating system directly from their website.

Installing XAMPP

Installing XAMPP is a fairly straightforward process with no special technical skills required. To get started, simply double-click on the downloaded file and follow the instructions provided on the screen.

You will need to choose where you want to install XAMPP, the language, and whether you want to install Bitnami for XAMPP. Depending on your machine configuration, you may need to create firewall exceptions for MariaDB and Apache.

Geek’s Note: If you plan to access the environment only locally, you won’t need to open the firewall ports.

WordPress installation

Once XAMPP is up and running, you can install WordPress by downloading the Bitnami WordPress module for XAMPP. Again, this is a fairly straightforward process. You will need to configure your user account and website name while the installer takes care of everything else, including creating the required databases.

Once this is complete, you will be able to access your new WordPress installation.

WordPress configuration

If you already have a website live and want to set up a development / development environment, you can backup and restore it in the development environment. This will help you make sure that you have the same environment on both systems. If you don’t have a live website yet, you can start setting up your website in the test environment.

Additional configuration options – run multiple WordPress sites on XAMPP

You can run multiple WordPress websites in your XAMPP staging environment through virtual hosts.

Virtual hosts allow us to use aliases to run multiple websites on the same IP address and the same web server. The good news is that the functionality is built in; all we have to do is turn it on and then create the virtual hosts we need. Although there is no hard limit on the number of virtual hosts you can create, if each of the virtual hosts has logging enabled, you might not be able to exceed 64 virtual hosts.

Adding multiple virtual hosts

Virtual hosts are added through the HTTPD virtual hosts configuration file. You will find this file in the following directory: C: xampp apache conf extra httpd-vhosts.conf

If you installed XAMPP in another directory, the configuration file will be there instead of the path given above.

Geek note: the httpd in the file name means http daemon. Daemons are Linux background processes with httpd being the Apache background process. In Windows, daemons are called services, but the Linux naming convention has remained. Now let’s go back to editing the file.

1. Activate virtual hosts in Apache configuration

The first thing to do is find and uncomment the following line:

NameVirtualHosts *:80

This tells Apache that we will be using virtual hosts on port 80. Then, at the end of the file, add the following 4 lines:

  DocumentRoot "C:XAMPPhtdocs" ServerName localhost  

2. Define virtual hosts

Once done, we can start adding virtual hosts. These must be added manually in the httpd-vhosts.conf file, which you can find in / xampp / apache / conf / extra. For each virtual host that we want to add, we need to add a set of directives that provide Apache with basic configuration details. These are defined as follows:


 DocumentRoot "C:XAMPPhtdocswppro"
 ServerName www.wpwhitesecurity.com
 
Options Indexes FollowSymLinks Includes ExecCGI
Order allow,deny
 Allow from all


Let’s see what each line does

  • Line 1 – Opens a new set of directives, informing Apache that we are going to declare a new virtual host
  • Line 2 – Specifies where the website files are located, each virtual host having its own directory
  • Line 3 – Provides the name the website should respond to
  • Line 4 – 8 – Specify who should have access to the contents of the directory. The directory listed here must match the directory specified in line 2
  • Line 9 – Close this set of directives for this virtual host

You will need to add a set of directives for each virtual host separately. Once you have configured all of the virtual hosts, save the file and close. To test and confirm that all the syntax of the Apache configuration is correct, run the httpd.exe process with the –t switch from the c: xampp apache bin directory as shown in the screenshot below .

3. Optional: modify the Windows hosts file

You can access the test environment through more friendly names by modifying the Windows hosts file. For example. You may want to access your website by typing stagingsite.com instead of localhost / stagingsite, which makes it easier to remember.

Geek note: The hosts file is a text file that maps IP addresses to host names. Windows checks this file before submitting DNS queries, overriding any real domain name. While host files have been the source of many pranks, they actually predate DNS. Originally, this was a file kept by the Stanford Research Institute and shared by those who wanted to access the first version of what is now the Internet, allowing them to visit websites. This means that in reality you had to periodically download the DNS server instead of just sending a query. Meh.

Once you are happy with the test environment, you can simply take a backup and restore it to the real environment.

The article How to set up multiple WordPress sites using XAMPP appeared first on WP White Security.

*** This is a syndicated Security Bloggers Network blog from WP White Security written by Danny Sullivan. Read the original post at: https://www.wpwhitesecurity.com/multiple-websites-xampp/

Esther L. Gunn