v.je - an Easy to set up development environment for Docker
Introduction
v.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://v.je/ after it's been booted with the docker-compose up
command and no further configuration.
The source code is available in this github repository: https://github.com/v-je/docker
Getting started
- Install Docker for your operating system (for Linux you can install docker and docker-compose through your distribution's package manager)
- Create a folder where your website is going to be stored
- Open a terminal at that location (Windows, have the folder open then click File -> Open Windows Powershell)
- Run
docker run --rm -v ${PWD}:/install vjedev/installer:latest
(this command downloads the configuration files used in the next step) - 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) - Navigate to https://v.je/ in your browser
- To make files visible on the server put them in the
websites/default/public
folder that was created.
Features
- All hosted websites use HTTPS with a valid SSL certificate from Let's Encrypt
- No configuration needed. Run
docker-compose up
and your website is hosted on https://v.je/ - Without configuration host different websites on v.je subdomains e.g. https://subdomain1.v.je/ and https://subdomain2.v.je/
- Includes up to date PHP development software*:
- PHP
- NGINX
- MariaDB
- Composer
- PHPUnit
- Portability: You can run
docker-compose stop
on one machine, copy the folder, thendocker-compose up
on another and your website will be visible. The database is automatically imported and exported. Most environments store the database inside a local volume. If you move your files to a different PC the database is lost. That's not the case with this environment. - 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 your desktop using:
- Host: v.je
- Port: 3306
- Username: v.je
- Password: v.je
To connect to the server from PHP you must use mysql as the host. For example:
<?php
$pdo = new PDO('mysql:dbname=test;host=mysql', 'v.je', 'v.je');
This MySQL user has full access to create schemas and other users. I suggest using MySQL Workbench but you can install the clunky PHPMyAdmin tool if you want a worse experience.
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
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.v.je/:
- Create the directory
mysite
inside thewebsites
directory. - Create the directory
public
inside themysite
directory. - Place your web-accessible files inside the
websites/mysite/public
directory. For example, the file inwebsites/mysite/public/phpinfo.php
will be accessible on the URL https://mysite.v.je/phpinfo.php
Any directory you create inside the websites
directory is treated as a subdomain of v.je
Easily import databases
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.
PHPUnit
To run PHPUnit tests you can use the command:
docker-compose run phpunit
This will run PHPUnit from the context of the websites/default
directory and look for phpunit.xml
at the path websites/default/phpunit.xml
. If you wish to run unit tests for another directory you can specify it as a command line argument. For example to run php unit tests from the websites/subdomain
directory you can run the command
docker-compose run phpunit /websites/subdomain
Composer
Composer is included and like PHPUnit defaults to the websites/default
directory. Running the following command:
docker-compose run composer require level-2/dice
Will create a vendor directory and install Dice Dependency Injection Container in websites/default/vendor
. To specify a different folder, pass the directory to the command using the -d
switch:
docker-compose run composer require level-2/dice -d /websites/subdomain