Table of Contents
This repository is used to create a comprehensive web development environment suitable for building high-performance websites and applications.
LEMPStack stands for Linux, Nginx, MySQL and PHP, and includes phpMyAdmin for database administration.
This project leverages images from LinuxServer.io; a trusted fleet of ready-to-use, well-maintained Docker containers.
- Front-End: nginx (includes PHP)
- Back-End: mariadb and phpmyadmin
NOTE: This has only been tested on Ubuntu 22.04 LTS!
Add Docker's Public GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpgAdd the Docker repository
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/nullUpdate
sudo apt updateInstall Docker and Docker Compose plugin
sudo apt install -y docker-ce docker-compose-pluginCreate a symbolic link to the Docker Compose plugin
sudo ln -s /usr/libexec/docker/cli-plugins/docker-compose /usr/bin/docker-composeOptionally, add your user to the Docker group so you don't need sudo
sudo usermod -aG docker <user>Confirm you are using the latest version
docker -v
docker compose version
Clone this repository:
git clone https://github.com/nicolasluckie/LEMPStack.git
We do not want to include sensitive information in the docker-compose.yml file. Instead, we source environment variables and database connection information from the .env file. This way sensitive information is not committed to version control.
Rename .env.example to .env in the /secure folder, and change the values within.
- This is outside the web root for security purposes.
- This file securely passes environment variables to all three Docker containers without hard-coding them in the
docker-compose.ymlfile. - This file is used by
/app/db/db.inc.phpto establish a connection to the database without hard-coding the connection string. Nginx requires a Bind Mount so/db/db.inc.phpcan access the variables within.
NOTE: The MYSQL_SERVER variable must match the service name in docker-compose.yml. In this case, the service name is mariadb, whereas the container name is lempstack_mariadb.
Run the following command from the folder containing the docker-compose.yml file:
sudo docker-compose up -dThis will create 1 stack with 3 containers:
- lempstack
- nginx on ports 80 (HTTP) and 443 (HTTPS)
- mariadb on port 3306
- phpmyadmin on port 8080
The /app/ folder will be mounted to /config/nginx/www for web hosting. Edit files in /app/ to see live changes.
Modify nginx-default.conf as needed. It will overwrite the existing /config/nginx/site-confs/default.conf file.
If you left the default ports, you can access the site by visiting http://localhost/ from a web browser; replacing localhost with the host IP.
The homepage should read "It worked!" if the deployment was successful and the database is online.
A health check is included in the nginx-default.conf file. Test it by visiting http://localhost/nginx-health from a web browser. The page should return "healthy" in plain text.
This can be useful for monitoring services like Uptime-Kuma which validates case-sensitive keywords when determining if a website is accessible or not.
To return different response or format, edit the nginx-default.conf file and change the text/plain to application/json, or any other acceptable format.
You can change the ports as needed by editing the docker-compose.yml file.
For example, if you want to access phpmyadmin from port 8080, change the number left of the colon like so:
ports:
- 8080:80