This LAMP stack runs on Docker so you should install that first if you've not already done so. The stack should be compatible with Linux, Windows or MacOS. For windows, although not necessary, you should either install WSL or GitBash to be able to run the setup.sh
script.
The docker containers are built according to the configuration of the docker-compose.yml
file, which consists of two containers - web server & database server. docker-compose
commands (CLI reference) must be run from the directory where the yml
file is located as it references the containers by service name. Alternatively, you can run the equivalent docker
command and specify either container ID or NAME. The docker images of each are based on official docker images. The customisation of these are as follows:
- mysqld options via
99-mysql.cnf
file to enable log files
- Additional package repositories
- Additional packages/php modules installed
- browscap (Lite)
- geoip
- igbinary
- imagick
- memcached
- odbc
- sqlsrv
- tidy
- xdebug
- xmlrpc
TODO:
- Detect if development host already added to hosts file(s) and ignore/update
- Support for configurations using different versions of software stack
- Add support for initialising database with data from SQL dump files
NOTE: On Windows OS (if you've not done so before), you should run configure the following git setting before checking out the project:
git config --global core.autocrlf input
It is recommended you checkout this repository for each web project rather than rely on vhost configuration within the stack. Open a shell and change to the directory that will contain all your projects and clone this repo to your machine.
git clone <repo> <project_name>
Change into the directory you checked out the repo to and run:
./setup.sh
You will be prompted a few questions to configure the .env
and docker-compose.yml
files.
You are given the option to use the Nginx web server proxy. If you are just running a single web project, then it's easier to run without the proxy. If you are running muliple projects, you can choose not to use the proxy, but you would have to ensure each web server uses different ports when running simultaneously or they will conflict with each other. With Nginx, you just choose different hostnames and don't need to worry about conflicting ports.
If you choose to not enable log files, log is output to docker logs for the container. When running services in foreground, the logs are ouput to the screen (-f follow). When running in detached mode (background process), to see the log you need to run docker-compose logs
. When enabling service log files, you can access them from the relevant directory that is mapped to logs
directory of your local machine.
A summary is displayed after the script finishes running to confirm your settings and some information on quickly getting started.
If you are using Nginx Web Proxy, you should start that service first. If you specify the service names (space separated) at the end of a docker-compose
command, it will only apply to those services. Before we copy our website code into our webserver container, it's a good idea to check our LAMP configuration works. Build the containers and try to access the website url as shown in the setup.sh
summary output -- you should see a phpinfo page.
Build Container | |
---|---|
docker-compose up --build | build each container if image not created or changed before starting all services |
docker-compose build | build only |
Stop Container | |
---|---|
[Control]+[C] | Abort all service(s) running as a foreground process |
docker-compose stop | Stop all services if running as detached or in foreground from another localhost shell |
docker-compose down | Stop all services and remove all containers/networks used by the compose file, except external resources |
Start Container | |
---|---|
docker-compose up | Run all services as foreground process |
docker-compose up -d | Run all services as background process |
docker-compose run -d <service_name> | Run a single service as a background process |
docker-compose restart | Run all services as background process (restart if already running) |
Execute a one-time command inside a Container | |
---|---|
docker exec <options> <container_id|container_name> <command> | Execute a command - can be interactive (e.g. bash ) |
docker exec -it <container_id|container_name> <bash> | Run an I nteractive bash T erminal |
The web server's root directory is directly mapped to the www
directory on your local machine. Any changes you make inside this automatically updates the website.
Copy your website code folder into the www
directory (or checkout your code as a directory - just as we did to checkout this LAMP stack). Now update DOCUMENT_ROOT
in the .env
file - you need to restart the webserver container for the DOCUMENT_ROOT
change to take effect.
Once you've built and initialised your database, the data files are populated and mapped to your local machine in data/mysql
. Initialisation should not re-occur once the data is populated. If you need to start with a clean database, simply backup or delete the files.
Within bin
directory are files relating to a docker image. Inside, the image there is a root
directory - this is copied to the root
directory of the docker image. If you make changes to any files in within root
of your local machine, you need to rebuild the docker container so initialisation copies the new files.
config/php/browscap.ini | Directly mapped to `php.d` location on web server (Scan dir for additional .ini files) |
config/php/99-php.ini | As above - Additional PHP ini settings that override other settings |
bin//Dockerfile | Defines the base source of the image and initialisation commands (package installation) |
bin/mysql/root/tmp/mysql/99-mysql.cnf | mysqld configuration file |
bin/webserver/root/usr/libexec | Initialisation script to customise the base docker image |