XAMPP is an abbreviation for cross-platform, Apache, MySQL, PHP and Perl. This setup guide will walk you through installing the XAMPP stack as well as hosting a simple web game (tested on Ubuntu 18.04 and 20.04)!
This guide assumes knowledge of the following:
1) Provisioning a VPS
2) Familiarity with SSH
3) Familiarity with linux command line
To begin, you will need to provision a VPS from cloud providers such as digitalocean or upcloud. Other popular services like AWS and google cloud would work as well with their EC2 and compute instances but the nature of those services are such that they are slightly more complicated to work with so they will not be included in this guide.
Once you have your VPS provisioned, SSH into your server with the following command (replacing 11.11.11.11 with your server's IP address):
$ ssh root@11.11.11.11
Within your server, run the update command below:
$ apt-get update
Next, retrieve the download link of the latest version of XAMPP from the official download page. You may then download the file with the wget command. As of writing this guide, the following command downloads the latest version of XAMPP:
$ wget https://www.apachefriends.org/xampp-files/8.0.0/xampp-linux-x64-8.0.0-2-installer.run
After the file download is complete, you have to make it executable with the following command:
$ chmod +x xampp-linux-x64-8.0.0-2-installer.run
Then, execute the file:
$ ./xampp-linux-x64-8.0.0-2-installer.run
You will also need to install net-tools with the command:
$ apt-get install net-tools
Finally, run the command below to start all the services:
$ /opt/lampp/xampp start
If you encounter errors with the above command, it is likely that you have apache2 or mysql service running currently. If you do, stop those services with the commands below then try starting XAMPP again:
$ systemctl stop mysql.service
$ systemctl stop apache2
If you have come this far, the installation is fully complete and you may now type the IP address of your server in your browser which should return the default XAMPP page. Read on for an extended guide to hosting a simple web game!
Before diving into hosting the web game, let us first create a new user that will be handling this web game with. For the purpose of this guide, I will be using my very own web game, SpaceShips as an example which will be handled by the user spaceships. Run the following command to create this new user:
$ adduser spaceships
Give the user superuser permissions:
$ usermod -aG sudo spaceships
For the remaining part of the guide, exit from your root SSH session and login as spaceships instead (again replacing 11.11.11.11 with the IP address of your VPS):
$ ssh spaceships@11.11.11.11
This part will vary greatly depending on the nature of your project. For demonstration purposes, if you are following through with the SpaceShips project, then follow this setup guide to get the project ready.
In addition to the above, you will also need to carry out 2 steps. First, create a new .htaccess file in the base directory of the project with the following template:
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) http://11.11.11.11/$1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
Remember to replace 11.11.11.11 with the IP address of your server! Next, modify the index.php file in /opt/lampp/htdocs/ and replace the line with the default path "/dashboard" to "/spaceships_web".
After the project is properly setup, duplicate the entire spaceships_web project directory into /opt/lampp/htdocs/ with the following command:
$ sudo cp -r spaceships_web /opt/lampp/htdocs/
Visiting the IP address of your server with the path spaceships_web should now show the game window. For example:
http://11.11.11.11/spaceships_web
If you have a domain and would like to host the website with SSL, do checkout this guide. This concludes the guide for installing XAMPP and hosting a simple web game! Thank you for reading!