Tom Butler's programming blog

s.je - an Easy to set up development environment for Docker

Introduction

s.je is a small and very easy to use virtual server. If you're inexplicably still using XAMPP in 2021 or just want to run a server without doing any configuration yourself, this is a good starting point for using Docker.

It's designed for anyone who wants a quick and easy to set up web development server with a lot of flexibility. It's been built with portability and ease of use in mind. The server will run pages on the url https://s.je/ after it's been booted with the docker-compose up command and no further configuration.

Getting started

  1. Install Docker for your operating system (for Linux you can install docker and docker-compose through your distribution's package manager)
  2. Create a folder where your website is going to be stored
  3. Open a terminal at that location (Windows, have the folder open then click File -> Open Windows Powershell)
  4. Run docker run -v ${PWD}:/git alpine/git clone https://github.com/v-je/docker . (note: That last dot is important!)
  5. Run docker-compose up -d (the command may take a few minutes to finish the first time you run it, subsequent runs will be quick)
  6. Navigate to https://s.je/ in your browser
  7. To make files visible on the server put them in the websites/default/public folder that was created.

Features

  1. All hosted websites use HTTPS with a valid SSL certificate from Let's Encrypt
  2. No configuration needed. Run docker-compose up and your website is hosted on https://s.je/
  3. Without configuration host different websites on s.je subdomains e.g. https://subdomain1.s.je/ and https://subdomain2.s.je/
  4. Includes up to date PHP development software*:
    • PHP
    • NGINX
    • MariaDB
    • Composer
    • PHPUnit
  5. Portability: You can run docker-compose up on one machine, then docker-compose up on another and your website will be visible. The database is automatically imported and exported. Most boxes store the database inside the VM. If you move your files to a different PC the database is lost. That's not the case with this box.
  6. URL rewriting is already set up. A request to any file that does not exist is sent to index.php

MySQL

Connect to MySQL from inside or outside the VM with the details:

  • Host: s.je
  • Port: 3306
  • Username: s.je
  • Password: s.je

This MySQL user has full access to create schemas and other users. I suggest using MySQL Workbench from outside the VM to manage your database

Hosting multiple websites

The environment is configured to host multiple websites from different folders within the created websites directory. To create a new website which is available on https://mysite.s.je/:

  1. Create the directory mysite inside the websites directory.
  2. Create the directory public inside the mysite directory.
  3. Place your web-accessible files inside the websites/mysite/public directory. For example, the file in websites/mysite/public/phpinfo.php will be accessible on the URL https://mysite.s.je/phpinfo.php

Any directory you create inside the websites directory is treated as a subdomain of s.je

Easily import databases without rebooting

You can import an SQL database automatically while the server is running. Create the file websites/import.sql, the SQL script inside the file will be executed and the import.sql file deleted.

Starting and stopping the server

To start the server, run the command docker-compose up -d from the project's directory.

To stop the server, run the command docker-compose down from the project's directory