Giter Club home page Giter Club logo

lamp-docker's Introduction

Welcome to Local Docker Config for LAMP Stack

๐Ÿณ This is a simple Docker Compose workflow that sets up a LAMP network of containers for local development. This also allows customizing the optional PHP version ๐Ÿ˜

This configuration can be used for any PHP project (Laravel, Yii, CodeIgniter, Pure PHP, etc.) ๐ŸŽ‰

Docker

Table of Contents

Other docker configs: LEMP Stack (Nginx, PHP, MariaDB, Redis) ๐Ÿณ

Add your custom bash script to run the docker

Because maybe my configuration is not enough for the configuration required by your project or purpose, you need to add more configuration to the docker.

With nature of allowing you to customize the PHP version according to your. We should also allow custom bash scripts to run when starting the docker.

So, you can add your custom bash script to run docker in the file docker/bash/custom.sh with the following steps:

1. Create a file docker/bash/custom.sh:

Run:

cd docker/bash
cp custom.sh.example custom.sh

2. Add your custom bash script to run the docker

Then, you can add your custom bash script to run docker in the file docker/bash/custom.sh.

For example, you want to install ngrok extension for your docker container:

#!/bin/bash

# Install ngrok
snap install ngrok

# Install ngrok for php
docker-php-ext-install ngrok

# You can install other extensions here
# docker-php-ext-install <extension_name>

# etc.
npm install -g localtunnel

And now, just follow the steps below and run the docker.

Configuration requirements

To use the optional PHP image, you need an additional web server, such as Apache, that can proxy HTTP-request to the Apache-pot of the container. This is not a requirement for the fpm image but is for the web server.

  • Multi-site integration
  • PHP optional version with custom in .env file (example: 7.4, 8.0, 8.1, 8.2, etc.)
  • Web server: Apache
  • DBMS (database management system): Mariadb
  • In-memory database: Redis
  • SSL Certificate (using mkcert)

Installation and Setup

Warning: If you don't want to use SSL, you can skip steps 1 and 2 and edit conf files in docker/server/apache/sites-enabled/*.conf to remove the SSL configuration.

Please remove the 443 port in docker/server/apache/sites-enabled/*.conf file and use 80 port for HTTP:

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName local.localhost.com
    ServerAlias local.com
    DocumentRoot /var/www/local

    ErrorLog /var/www/logs/error-local.log
    CustomLog /var/www/logs/access-local.log combined

    SSLEngine on
	SSLCertificateFile /var/www/certs/local.localhost.com.pem
	SSLCertificateKeyFile /var/www/certs/local.localhost.com-key.pem

    <Directory /var/www/local>
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require all granted
  </Directory>
</VirtualHost>

If you want to use SSL, please ignore the above warning and follow all the steps below.

1. Install SSL certificate

Using mkcert to create ssl certificate

For Ubuntu

sudo apt install libnss3-tools

sudo wget https://github.com/FiloSottile/mkcert/releases/download/v1.4.3/mkcert-v1.4.3-linux-amd64 && \
sudo mv mkcert-v1.4.3-linux-amd64 mkcert && \
sudo chmod +x mkcert && \
sudo cp mkcert /usr/local/bin/

For Mac or Windows

Please check and install mkcert at: https://github.com/FiloSottile/mkcert

Now that the mkcert utility is installed, run the command below to generate and install your local CA:

mkcert -install

2. Create an SSL certificate for this project

Go to this docker folder and run:

cd docker/server/certs
mkcert local.localhost.com
mkcert local.lamp.com

3. Copy .env.example to .env

Go to this docker folder and run:

cp .env.example .env

4. Edit .env file

PHP_VERSION_SELECTED=8.2 # Choose the PHP version for your project

APP_NAME=lamp-local # name of your docker project
APP_PORT=91 # port for docker server (apache)
SSL_PORT=445 # port for docker server (apache) with SSL
DB_PORT=13393 # port for a database (MariaDB)

MYSQL_ROOT_PASS=root
MYSQL_USER=root
MYSQL_PASS=root
MYSQL_DB=lamp-local # name of your database

PHPMYADMIN_PORT=19011 # port for phpmyadmin (database admin)
PHPMYADMIN_UPLOAD_LIMIT # upload limit for phpmyadmin
IP_DB_SERVER=127.0.0.1

REDIS_PORT=16379 # port for Redis (in-memory database)

4. Run to start the containers

Go to this docker folder and run:

docker-compose up -d

Check the network ID and connect the Database

1. Check CONTAINER_ID

  • Run docker ps to check the Container ID of APP_NAME-db
  • Run the command docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <container_ID>
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <container_ID>

image

2. Connect to Database

Use the IP address to connect to the database using the database management system (DBMS) of your choice. For example, using MySQL Workbench:

image

You can also connect to the database using the DB_PORT in the .env file

For example, using MySQL Workbench: DB_PORT=13393

image

Demo

This is a demo of the project with the environment variable PHP_VERSION_SELECTED=8.2

image

lamp-docker's People

Contributors

tanhongit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

tanhongit

lamp-docker's Issues

GitHub Actions to use Node.js 16 instead of Node.js 12

Warning:

Node.js 12 actions are deprecated. Please update the following actions to use Node.js 16: docker/setup-buildx-action@v1, docker/login-action@v1, docker/metadata-action@v3, docker/build-push-action@v2. For more information see: https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/

I needed to update the compatible versions in the GitHub action to eliminate the above warning.

Set default PHP version in Dockerfile

To avoid auto-detecting the wrong PHP version, I needed to add a default value to the Dockerfile.

image

It's to minimize the laxity in version determination when doing the GitHub action workflow!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.