It is very important to have a development or test environment for whatever you are working on. It does not matter if it is your home made project, your personal website, your school project or your work stuff. You should always follow good practice and have a test environment (with backup) for all changes and experiments before going into production. I do the same. I have a few websites and servers, I also test a lot of stuff like custom scripts, CMS, frameworks and engines. I also try to code myself or try to modify someone else’s open source/free code to achieve my goals. BTW, copy and paste from stack overflow is past, now you should ask ChatGPT for mutated AI generated code you can modify and sell ;) . I do all of this in a test environment that simulates production. The test machine should look exactly the same as the production machine, same configuration, same system and same package version. Thanks to this, you can be sure that no additional bugs will show up after you run the test and push the latest version live.
To test things, I use a Virtual Box machine running Linux. In my case Debian, because at the moment all my servers are running Debian 12. Of course I do not share my configuration, instead of that I created a minimal Debian 12 installation with simple configuration similar to what you get when you buy some cheap VPS. I added Nginx with 3 test sites running PHP and MariaDB. You can have a look at the configuration of the system and each installed application to learn how to configure, manage and maintain your own web server.
Now you can confidently upload your scripts and test different sites and configurations, without wasting time building each environment from scratch. Verify that the default settings I have implemented suit your needs, and upload your scripts for testing by modifying the configuration to suit your needs and requirements.
Using this solution you can simulate working with real Virtual Private Server. Before you buy one, learn how to use it!
Test web server for VirtualBox
Here are some technical details about the machine itself:
- System: Debian 12
- Web server: Nginx (mainline)
- PHP: 8.2
- Database: MariaDB 11.1
- Access: SSH
- Firewall: UFW
- SSHD protection: Fail2Ban
- NAT network with port forwarding (8022 SSH; 80 Website 1; 8088 Website 2; 8089 Website 3)
- 1 CPU and 2048 MB RAM (you can adjust it in settings)
Remember my article about Your first VPS server? These are the steps I followed to configure that machine. So to recap:
- Installing the system
- Adding and configuring users
- Configure SSH server
- Firewall and fail2ban configuration
- Enable automatic updates
- Installing and configuring the Nginx web server
- Installing and configuring the PHP and MariaDB
Now you, as the end user, download the machine, import it into VirtualBox and run it (yeah, who would trust you men).
You can access the machine from the VirtualBox interface or leave it running in the background and log in using SSH (like for the real VPS).
Connection command from PowerShell or Bash:
1 | ssh user@localhost -p8022 |
Credentials for the machine are:
1 | Login: root; Password: root |
Please change it after logging in.
Root login via remote access is forbidden, you should always login as a standard user and use the sudo
command for administrative operations.
The MariaDB database is protected by root. All you need to do to access the database is to use the sudo mysql
command.
Once the machine is up and running, you can also open your web browser and type http://localhost/ (port 80). Thanks to port forwarding, you will be automatically redirected to the website hosted by the virtual machine. If you add port 8088
(http://localhost:8088/) and 8089
(http://localhost:8089/) to the address, you will see two other websites configured on this server. The websites are just standard html landing pages for Nginx with modified content to display the website name and additionally Website_1
has a link to an info.php
file with content <?php phpinfo(); ?>
to help you check the installed PHP version and enabled PHP modules.
If you have already configured something on your computer that is running as a local host on the same ports, it may cause a collision. You should then change the ports in Nginx and in Virtual Box for port forwarding.
Here is nginx.conf
content with additional comments:
1 | # Define the user and number of worker processes for Nginx |
Website_1 config with comments:
1 | server { |
Website_2 and Website_3 configs have only changed the website root path and log path.
1 | root /var/www/website_2; |
Do not forget to take snapshots of your virtual machine. If something goes wrong or gets out of control, you can simply import the previous configuration and start again from the last good position.
I hope you find this machine useful. Have fun learning and testing your own scripts and websites.
PS: This machine is also a first step in preparing an Udemy course about creating your first VPS server and the possibilities it offers. I don’t know how long it will take and what the end result will be, but I decided to try something new, to learn some new tools and platforms. Maybe sharing my knowledge in this way will not only make me happy, but also bring in a small steady income. If you have any ideas or suggestions as to what you would like to see in such a course, please feel free to let me know.