Skip to content

Commit 65639e4

Browse files
committed
fixes #4 - Added mkcert documentation
1 parent 4d5d6b0 commit 65639e4

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ MYSQL_USER=admin
1616
MYSQL_USER_PASS=secret
1717
# This will create a database with the same name as you defined in your APP_NAME variable
1818
MYSQL_DB=${APP_NAME}
19+
# Mkcert local tld. Don't use local for example. Must not be a real tld
20+
TLD=localhost

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
**[Quick Start](#quick-start)** |
1111
**[Settings](#settings)** |
1212
**[Development](#development)** |
13+
**[Localhost SSL](#localhost-ssl)** |
1314
**[Composer](#composer)** |
1415
**[MySQL](#mysql)** |
1516
**[XDebug](#xdebug)** |
@@ -31,6 +32,7 @@ It is intended to provide everything needed to have a structured development LAM
3132
- xdebug-3.1.1 (and documentation for connecting the Visual Studio Code debugger to the container)
3233
- MySQL8
3334
- PhpMyAdmin running by default on port 8080
35+
- A mkcert container that generates certs for a dev domain
3436
- Allowance for customization of mysql, php and apache configuration files
3537
- Composer installed in the Server container
3638
- A simple .env file that handles container naming, allowing for multiple unique container setups and port changes through simple text edits
@@ -87,6 +89,48 @@ docker-compose -d up
8789
- start adding code, and/or packages with composer/composer.json
8890
- Add your docker4lamp project to git
8991

92+
## Localhost SSL
93+
94+
docker4compose uses the [mkcert project](https://github.com/FiloSottile/mkcert) to generate valid SSL certificates for your _docker4lamp_ environment. This relieves you of having to install and run mkcert yourself, or reconfiguring the apache vhost.
95+
96+
All you need to do is retrieve the root cert from the container and install it in your workstation's local certificate store.
97+
98+
By default, the cert will allow for valid SSL access to *.**APP_NAME**.localhost
99+
100+
### Installing the cert
101+
102+
- The /cert directory is designed for you to keep a locally accessible copy of the generated certs
103+
- Step #1: Copy the certs from the container
104+
105+
<div class="highlight highlight-source-shell"><pre>
106+
docker cp mkcert:/root/.local/share/mkcert/mkcert/ ./cert/
107+
</pre></div>
108+
109+
- Step #2: Install the root cert on your workstation
110+
111+
For __Mac/OSX__:
112+
113+
<div class="highlight highlight-source-shell"><pre>
114+
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ./cert/mkcert/rootCA.pem
115+
</pre></div>
116+
117+
For __Windows__:
118+
119+
<div class="highlight highlight-source-shell"><pre>
120+
certutil.exe -addstore root ./cert/mkcert/rootCA.pem
121+
</pre></div>
122+
123+
- Step #3: Add an entry to your /etc/hosts file for your dev domain. Assuming that your **APP_NAME** is "myproject"
124+
125+
<div class="highlight highlight-source-shell"><pre>
126+
127.0.0.1 myproject.localhost www.myproject.localhost
127+
</pre></div>
128+
129+
_Your browser should see your development server as valid when you open https://www.myproject.localhost_
130+
131+
#### Note for Firefox users:
132+
By default Firefox does not trust root certs installed in the operating system. [You can work around this using Mozilla's documentation.](https://support.mozilla.org/en-US/kb/setting-certificate-authorities-firefox)
133+
90134
### Developing your code
91135

92136
Your code goes into the docker4lamp/_project_ directory. Don't change the name of this directory unless you are clear on changes you would need to make to your apache and debug settings
@@ -116,6 +160,7 @@ docker exec -it -u www-data:www-data -w /var/www/html/project your_project-serve
116160
Once you are exec'd in the container you can run composer. This example will create a project composer.json and install the monolog component library
117161

118162
<div class="highlight highlight-source-shell"><pre>
163+
# Example
119164
composer require monolog/monolog
120165
</pre></div>
121166

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ services:
77
image: ${APP_NAME}-mkcert:latest
88
container_name: "${APP_NAME}-mkcert"
99
environment:
10-
domain: "*.${APP_NAME}.localhost,localhost,127.0.0.1,::1"
10+
domain: "*.${APP_NAME}.${TLD},localhost,127.0.0.1,::1"
1111
volumes:
1212
- mkcert-data:/root/.local/share/mkcert
1313
server:

0 commit comments

Comments
 (0)