Skip to content

Commit ebbf86c

Browse files
authored
Merge pull request #208 from caboodle-tech/master
adds feature #196 ssl support
2 parents 42c5ffb + 3990670 commit ebbf86c

File tree

12 files changed

+212
-86
lines changed

12 files changed

+212
-86
lines changed

README.md

Lines changed: 122 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,31 @@
1-
# LAMP stack built with Docker Compose
1+
# LAMP stack built with Docker Compose
22

33
![Landing Page](https://user-images.githubusercontent.com/43859895/141092846-905eae39-0169-4fd7-911f-9ff32c48b7e8.png)
44

5-
65
A basic LAMP stack environment built using Docker Compose. It consists of the following:
76

8-
* PHP
9-
* Apache
10-
* MySQL
11-
* phpMyAdmin
12-
* Redis
7+
- PHP
8+
- Apache
9+
- MySQL
10+
- phpMyAdmin
11+
- Redis
1312

1413
As of now, we have several different PHP versions. Use appropriate php version as needed:
1514

16-
* 5.4.x
17-
* 5.6.x
18-
* 7.1.x
19-
* 7.2.x
20-
* 7.3.x
21-
* 7.4.x
22-
* 8.0.x
23-
* 8.1.x
24-
25-
26-
## Installation
27-
28-
* Clone this repository on your local computer
29-
* configure .env as needed
30-
* Run the `docker-compose up -d`.
15+
- 5.4.x
16+
- 5.6.x
17+
- 7.1.x
18+
- 7.2.x
19+
- 7.3.x
20+
- 7.4.x
21+
- 8.0.x
22+
- 8.1.x
23+
24+
## Installation
25+
26+
- Clone this repository on your local computer
27+
- configure .env as needed
28+
- Run the `docker-compose up -d`.
3129

3230
```shell
3331
git clone https://github.com/sprintcube/docker-compose-lamp.git
@@ -38,31 +36,39 @@ docker-compose up -d
3836
// visit localhost
3937
```
4038

41-
Your LAMP stack is now ready!! You can access it via `http://localhost`.
39+
Your LAMP stack is now ready!! You can access it via `http://localhost`.
40+
41+
## Configuration and Usage
4242

43-
## Configuration and Usage
43+
### General Information
4444

45-
### General Information
4645
This Docker Stack is build for local development and not for production usage.
4746

4847
### Configuration
48+
4949
This package comes with default configuration options. You can modify them by creating `.env` file in your root directory.
5050
To make it easy, just copy the content from `sample.env` file and update the environment variable values as per your need.
5151

5252
### Configuration Variables
53+
5354
There are following configuration variables available and you can customize them by overwritting in your own `.env` file.
5455

5556
---
57+
5658
#### PHP
59+
5760
---
61+
5862
_**PHPVERSION**_
59-
Is used to specify which PHP Version you want to use. Defaults always to latest PHP Version.
63+
Is used to specify which PHP Version you want to use. Defaults always to latest PHP Version.
6064

6165
_**PHP_INI**_
62-
Define your custom `php.ini` modification to meet your requirments.
66+
Define your custom `php.ini` modification to meet your requirments.
6367

6468
---
65-
#### Apache
69+
70+
#### Apache
71+
6672
---
6773

6874
_**DOCUMENT_ROOT**_
@@ -84,15 +90,17 @@ _**APACHE_LOG_DIR**_
8490
This will be used to store Apache logs. The default value for this is `./logs/apache2`.
8591

8692
---
93+
8794
#### Database
95+
8896
---
8997

90-
> For Apple Silicon Users:
91-
Please select Mariadb as Database. Oracle doesn't build their SQL Containers for the arm Architecure
98+
> For Apple Silicon Users:
99+
> Please select Mariadb as Database. Oracle doesn't build their SQL Containers for the arm Architecure
92100
93101
_**DATABASE**_
94102

95-
Define which MySQL or MariaDB Version you would like to use.
103+
Define which MySQL or MariaDB Version you would like to use.
96104

97105
_**MYSQL_INITDB_DIR**_
98106

@@ -116,8 +124,8 @@ Apache is configured to run on port 80. So, you can access it via `http://localh
116124

117125
By default following modules are enabled.
118126

119-
* rewrite
120-
* headers
127+
- rewrite
128+
- headers
121129

122130
> If you want to enable more modules, just update `./bin/phpX/Dockerfile`. You can also generate a PR and we will merge if seems good for general purpose.
123131
> You have to rebuild the docker image by running `docker-compose build` and restart the docker containers.
@@ -136,22 +144,22 @@ The installed version of php depends on your `.env`file.
136144

137145
#### Extensions
138146

139-
By default following extensions are installed.
147+
By default following extensions are installed.
140148
May differ for PHP Versions <7.x.x
141149

142-
* mysqli
143-
* pdo_sqlite
144-
* pdo_mysql
145-
* mbstring
146-
* zip
147-
* intl
148-
* mcrypt
149-
* curl
150-
* json
151-
* iconv
152-
* xml
153-
* xmlrpc
154-
* gd
150+
- mysqli
151+
- pdo_sqlite
152+
- pdo_mysql
153+
- mbstring
154+
- zip
155+
- intl
156+
- mcrypt
157+
- curl
158+
- json
159+
- iconv
160+
- xml
161+
- xmlrpc
162+
- gd
155163

156164
> If you want to install more extension, just update `./bin/webserver/Dockerfile`. You can also generate a PR and we will merge if it seems good for general purpose.
157165
> You have to rebuild the docker image by running `docker-compose build` and restart the docker containers.
@@ -194,28 +202,28 @@ Example:
194202
#xdebug.idekey=VSCODE
195203
```
196204

197-
Xdebug VS Code: you have to install the Xdebug extension "PHP Debug". After installed, go to Debug and create the launch file so that your IDE can listen and work properly.
205+
Xdebug VS Code: you have to install the Xdebug extension "PHP Debug". After installed, go to Debug and create the launch file so that your IDE can listen and work properly.
198206

199207
Example:
200208

201209
**VERY IMPORTANT:** the `pathMappings` depends on how you have opened the folder in VS Code. Each folder has your own configurations launch, that you can view in `.vscode/launch.json`
202210

203211
```json
204212
{
205-
"version": "0.2.0",
206-
"configurations": [
207-
{
208-
"name": "Listen for Xdebug",
209-
"type": "php",
210-
"request": "launch",
211-
// "port": 9000, // Xdebug 2
212-
"port": 9003, // Xdebug 3
213-
"pathMappings": {
214-
// "/var/www/html": "${workspaceFolder}/www" // if you have opened VSCODE in root folder
215-
"/var/www/html": "${workspaceFolder}" // if you have opened VSCODE in ./www folder
216-
}
217-
}
218-
]
213+
"version": "0.2.0",
214+
"configurations": [
215+
{
216+
"name": "Listen for Xdebug",
217+
"type": "php",
218+
"request": "launch",
219+
// "port": 9000, // Xdebug 2
220+
"port": 9003, // Xdebug 3
221+
"pathMappings": {
222+
// "/var/www/html": "${workspaceFolder}/www" // if you have opened VSCODE in root folder
223+
"/var/www/html": "${workspaceFolder}" // if you have opened VSCODE in ./www folder
224+
}
225+
}
226+
]
219227
}
220228
```
221229

@@ -227,15 +235,60 @@ Now, make a breakpoint and run debug.
227235

228236
It comes with Redis. It runs on default port `6379`.
229237

238+
## SSL (HTTPS)
239+
240+
Support for `https` domains is built-in but disabled by default. There are 3 ways you can enable and configure SSL; `https` on `localhost` being the easiest. If you are trying to recreating a testing environment as close as possible to a production environment, any domain name can be supported with more configuration.
241+
242+
**Notice:** For every non-localhost domain name you wish to use `https` on, you will need to modify your computers [hosts file](https://en.wikipedia.org/wiki/Hosts_%28file%29) and point the domain name to `127.0.0.1`. If you fail to do this SSL will not work and you will be routed to the internet every time you try to visit that domain name locally.
243+
244+
### 1) HTTPS on Localhost
245+
246+
To enable `https` on `localhost` (https://localhost) you will need to:
247+
248+
1. Use a tool like [mkcert](https://github.com/FiloSottile/mkcert#installation) to create an SSL certificate for `localhost`:
249+
- With `mkcert`, in the terminal run `mkcert localhost 127.0.0.1 ::1`.
250+
- Rename the files that were generated `cert.pem` and `cert-key.pem` respectively.
251+
- Move these files into your docker setup by placing them in `config/ssl` directory.
252+
2. Uncomment the `443` vhost in `config/vhosts/default.conf`.
253+
254+
Done. Now any time you turn on your LAMP container `https` will work on `localhost`.
255+
256+
### 2) HTTPS on many Domains with a Single Certificate
257+
258+
If you would like to use normal domain names for local testing, and need `https` support, the simplest solution is an SSL certificate that covers all the domain names:
259+
260+
1. Use a tool like [mkcert](https://github.com/FiloSottile/mkcert#installation) to create an SSL certificate that covers all the domain names you want:
261+
- With `mkcert`, in the terminal run `mkcert example.com "*.example.org" myapp.dev localhost 127.0.0.1 ::1` where you replace all the domain names and IP addresses to the ones you wish to support.
262+
- Rename the files that were generated `cert.pem` and `cert-key.pem` respectively.
263+
- Move these files into your docker setup by placing them in `config/ssl` directory.
264+
2. Uncomment the `443` vhost in `config/vhosts/default.conf`.
265+
266+
Done. Since you combined all the domain names into a single certificate, the vhost file will support your setup without needing to modify it further. You could add domain specific rules if you wish however. Now any time you turn on your LAMP container `https` will work on all the domains you specified.
267+
268+
### 3) HTTPS on many Domain with Multiple Certificates
269+
270+
If you would like your local testing environment to exactly match your production, and need `https` support, you could create an SSL certificate for every domain you wish to support:
271+
272+
1. Use a tool like [mkcert](https://github.com/FiloSottile/mkcert#installation) to create an SSL certificate that covers the domain name you want:
273+
- With `mkcert`, in the terminal run `mkcert [your-domain-name(s)-here]` replacing the bracket part with your domain name.
274+
- Rename the files that were generated to something unique like `[name]-cert.pem` and `[name]-cert-key.pem` replacing the bracket part with a unique name.
275+
- Move these files into your docker setup by placing them in `config/ssl` directory.
276+
2. Using the `443` example from the vhost file (`config/vhosts/default.conf`), make new rules that match your domain name and certificate file names.
277+
278+
Done. The LAMP container will auto pull in any SSL certificates in `config/ssl` when it starts. As long as you configure the vhosts file correctly and place the SSL certificates in `config/ssl`, any time you turn on your LAMP container `https` will work on your specified domains.
279+
230280
## Contributing
231-
We are happy if you want to create a pull request or help people with their issues. If you want to create a PR, please remember that this stack is not built for production usage, and changes should be good for general purpose and not overspecialized.
232-
> Please note that we simplified the project structure from several branches for each php version, to one centralized master branch. Please create your PR against master branch.
233-
>
234-
Thank you!
281+
282+
We are happy if you want to create a pull request or help people with their issues. If you want to create a PR, please remember that this stack is not built for production usage, and changes should be good for general purpose and not overspecialized.
283+
284+
> Please note that we simplified the project structure from several branches for each php version, to one centralized master branch. Please create your PR against master branch.
285+
>
286+
> Thank you!
235287
236288
## Why you shouldn't use this stack unmodified in production
237-
We want to empower developers to quickly create creative Applications. Therefore we are providing an easy to set up a local development environment for several different Frameworks and PHP Versions.
289+
290+
We want to empower developers to quickly create creative Applications. Therefore we are providing an easy to set up a local development environment for several different Frameworks and PHP Versions.
238291
In Production you should modify at a minimum the following subjects:
239292

240-
* php handler: mod_php=> php-fpm
241-
* secure mysql users with proper source IP limitations
293+
- php handler: mod_php=> php-fpm
294+
- secure mysql users with proper source IP limitations

bin/php54/Dockerfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,17 @@ RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-di
4242
RUN pecl install xdebug-2.4.0RC4 && docker-php-ext-enable xdebug \
4343
&& echo "xdebug.remote_enable=1" >> /usr/local/etc/php/php.ini
4444

45+
# Insure an SSL directory exists
46+
RUN mkdir -p /etc/apache2/ssl
47+
48+
# Enable SSL support
49+
RUN a2enmod ssl && a2enmod rewrite
50+
4551
# Enable apache modules
4652
RUN a2enmod rewrite headers
47-
4853
RUN a2enmod rewrite rpaf
4954

5055
EXPOSE 80
56+
EXPOSE 443
5157

5258
ENTRYPOINT ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]

bin/php56/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,16 @@ RUN docker-php-ext-install curl \
2828
&& pecl install xdebug-2.5.5 && docker-php-ext-enable xdebug \
2929
&& echo "xdebug.remote_enable=1" >> /usr/local/etc/php/php.ini
3030

31+
# Insure an SSL directory exists
32+
RUN mkdir -p /etc/apache2/ssl
33+
34+
# Enable SSL support
35+
RUN a2enmod ssl && a2enmod rewrite
36+
3137
# Enable apache modules
3238
RUN a2enmod rewrite headers
3339

3440
EXPOSE 80
41+
EXPOSE 443
3542

3643
ENTRYPOINT ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]

bin/php71/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,11 @@ RUN apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev
4242
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
4343
RUN docker-php-ext-install -j$(nproc) gd
4444

45+
# Insure an SSL directory exists
46+
RUN mkdir -p /etc/apache2/ssl
47+
48+
# Enable SSL support
49+
RUN a2enmod ssl && a2enmod rewrite
50+
4551
# Enable apache modules
4652
RUN a2enmod rewrite headers

bin/php72/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,11 @@ RUN apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev
5252
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
5353
RUN docker-php-ext-install -j$(nproc) gd
5454

55+
# Insure an SSL directory exists
56+
RUN mkdir -p /etc/apache2/ssl
57+
58+
# Enable SSL support
59+
RUN a2enmod ssl && a2enmod rewrite
60+
5561
# Enable apache modules
5662
RUN a2enmod rewrite headers

bin/php73/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ RUN apt-get -y update && \
4949
docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && \
5050
docker-php-ext-install -j$(nproc) gd
5151

52+
# Insure an SSL directory exists
53+
RUN mkdir -p /etc/apache2/ssl
54+
55+
# Enable SSL support
56+
RUN a2enmod ssl && a2enmod rewrite
57+
5258
# Enable apache modules
5359
RUN a2enmod rewrite headers
5460

bin/php74/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ libpng-dev && \
7676
docker-php-ext-configure gd --enable-gd --with-freetype --with-jpeg && \
7777
docker-php-ext-install gd
7878

79+
# Insure an SSL directory exists
80+
RUN mkdir -p /etc/apache2/ssl
81+
82+
# Enable SSL support
83+
RUN a2enmod ssl && a2enmod rewrite
84+
7985
# Enable apache modules
8086
RUN a2enmod rewrite headers
8187

bin/php8/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ libpng-dev && \
9090
docker-php-ext-configure gd --enable-gd --with-freetype --with-jpeg && \
9191
docker-php-ext-install gd
9292

93+
# Insure an SSL directory exists
94+
RUN mkdir -p /etc/apache2/ssl
95+
96+
# Enable SSL support
97+
RUN a2enmod ssl && a2enmod rewrite
98+
9399
# Enable apache modules
94100
RUN a2enmod rewrite headers
95101

bin/php81/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ libpng-dev && \
8989
docker-php-ext-configure gd --enable-gd --with-freetype --with-jpeg && \
9090
docker-php-ext-install gd
9191

92+
# Insure an SSL directory exists
93+
RUN mkdir -p /etc/apache2/ssl
94+
95+
# Enable SSL support
96+
RUN a2enmod ssl && a2enmod rewrite
97+
9298
# Enable apache modules
9399
RUN a2enmod rewrite headers
94100

0 commit comments

Comments
 (0)