Skip to content

Commit 927d6e2

Browse files
committed
Support env file in project root
1 parent 1bb4846 commit 927d6e2

File tree

5 files changed

+80
-35
lines changed

5 files changed

+80
-35
lines changed

.env-example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
IP=127.0.0.1
2+
DOMAIN=myapp.local
3+
DB_HOST=mysql
4+
DB_NAME=myapp
5+
DB_ROOT_PASSWORD=password
6+
DB_TABLE_PREFIX=wp_

README.md

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,38 @@ Use WordPress locally with Docker using [Docker compose](https://docs.docker.com
2424
+ [Docker](https://www.docker.com/get-started)
2525
+ Openssl for creatng the SSL cert. Install using Homebrew `brew install openssl`
2626

27+
### Setup environment variables
28+
29+
#### For Docker
30+
31+
Copy `.env-example` in the project root to `.env` and edit your preferences.
32+
33+
Example:
34+
35+
```yml
36+
IP=127.0.0.1
37+
APP_NAME=myapp
38+
DOMAIN="myapp.local"
39+
DB_HOST=mysql
40+
DB_NAME=myapp
41+
DB_ROOT_PASSWORD=password
42+
DB_TABLE_PREFIX=wp_
43+
44+
```
45+
46+
#### For WordPress
47+
48+
Copy `.env-example` in the `src` folder to Copy `.env` and edit your preferences.
49+
50+
Use the following database settings:
51+
52+
```yml
53+
DB_HOST=mysql:3306
54+
DB_NAME=myapp
55+
DB_USER=root
56+
DB_PASSWORD=password
57+
```
58+
2759
### Create SSL cert
2860

2961
```shell
@@ -46,32 +78,12 @@ cd cli
4678
./trust-cert.sh
4779
```
4880

49-
> Edit the script to your your custom domain, this example uses myapp.local
50-
5181
### Setup vhost in /etc/hosts
5282

5383
```shell
5484
cd cli
5585
./setup-hosts-file.sh
5686
```
57-
> Follow the instructions. For example use `myapp.local`
58-
59-
### Setup ENV
60-
61-
```shell
62-
cd src
63-
cp .env.example .env
64-
```
65-
66-
Use the following database settings:
67-
68-
```yml
69-
DB_HOST=mysql:3306
70-
DB_NAME=myapp
71-
DB_USER=root
72-
DB_PASSWORD=password
73-
```
74-
7587
## Install WordPress and Composer dependencies
7688

7789
```shell
@@ -89,6 +101,12 @@ docker-compose up -d
89101

90102
🚀 Open up [https://myapp.local](https://myapp.local)
91103

104+
## PhpMyAdmin
105+
106+
PhpMyAdmin comes installed as a service in docker-compose.
107+
108+
109+
Open [http://127.0.0.1:8080/](http://127.0.0.1:8080/)
92110

93111
### Notes:
94112

@@ -111,6 +129,10 @@ wp search-replace https://olddomain.com https://newdomain.com --allow-root
111129
112130
### Changelog
113131

132+
#### 2020-01-11
133+
- Added `.env` support for specifying your own app name, domain etc. Copy `.env-example` to `.env` and edit your preferences.
134+
- Added phpMyAdmin. Visit [http://127.0.0.1:8080/](http://127.0.0.1:8080/)
135+
114136
#### 2019-08-02
115137
- Added Linux support. Thanks to [@faysal-ishtiaq](https://github.com/faysal-ishtiaq).
116138

cli/create-cert.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ BLUE='\033[0;34m'
88
YELLOW='\033[0;93m'
99
NC='\033[0m'
1010

11+
source "../.env"
12+
13+
DOMAIN=$(echo "$DOMAIN")
14+
1115
if [[ "$OSTYPE" == "linux-gnu" ]]; then
1216
OPENSSL_CNF_PATH=/etc/ssl/openssl.cnf
1317
fi
@@ -20,17 +24,18 @@ openssl req \
2024
-newkey rsa:2048 \
2125
-x509 \
2226
-nodes \
23-
-keyout myapp.local.key \
27+
-keyout "${DOMAIN}".key \
2428
-new \
25-
-out myapp.local.crt \
26-
-subj /CN=myapp.local \
29+
-out "${DOMAIN}".crt \
30+
-subj /CN="${DOMAIN}" \
2731
-reqexts SAN \
2832
-extensions SAN \
2933
-config <(cat $OPENSSL_CNF_PATH \
30-
<(printf '[SAN]\nsubjectAltName=DNS:myapp.local')) \
34+
<(printf '[SAN]\nsubjectAltName=DNS:'${DOMAIN})) \
3135
-sha256 \
3236
-days 3650
3337

38+
rm -rf ../certs/*
3439
mkdir -p ../certs
3540

3641
mv *.crt ../certs/

cli/trust-cert.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@ BLUE='\033[0;34m'
88
YELLOW='\033[0;93m'
99
NC='\033[0m'
1010

11+
source "../.env"
12+
13+
DOMAIN=$(echo "$DOMAIN")
14+
15+
1116
if [[ "$OSTYPE" == "darwin"* ]]; then
12-
sudo security add-trusted-cert -d -r trustRoot -k "/Library/Keychains/System.keychain" "../certs/myapp.local.crt"
17+
sudo security add-trusted-cert -d -r trustRoot -k "/Library/Keychains/System.keychain" "../certs/${DOMAIN}.crt"
1318
fi
1419

1520
if [[ "$OSTYPE" == "linux-gnu" ]]; then

docker-compose.yml

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: '3.6'
22
services:
33
nginx:
44
image: nginx:latest
5-
container_name: myapp-nginx
5+
container_name: ${APP_NAME}-nginx
66
ports:
77
- '80:80'
88
- '443:443'
@@ -16,12 +16,12 @@ services:
1616

1717
mysql:
1818
image: mariadb
19-
container_name: myapp-mysql
19+
container_name: ${APP_NAME}-mysql
2020
volumes:
2121
- './data/db:/var/lib/mysql:delegated'
2222
environment:
2323
- MYSQL_ROOT_PASSWORD=password
24-
- MYSQL_DATABASE=myapp
24+
- MYSQL_DATABASE=${APP_NAME}
2525
restart: always
2626
ports:
2727
- '3306:3306'
@@ -30,22 +30,29 @@ services:
3030
build:
3131
context: .
3232
dockerfile: Dockerfile
33-
container_name: myapp-wordpress
33+
container_name: ${APP_NAME}-wordpress
3434
volumes:
3535
- ./src:/var/www/html:rw,cached
3636
- ./config/php.ini:/usr/local/etc/php/conf.d/php.ini
37-
environment:
38-
- WORDPRESS_DB_NAME=myapp
39-
- WORDPRESS_TABLE_PREFIX=wp_
40-
- WORDPRESS_DB_HOST=mysql
41-
- WORDPRESS_DB_PASSWORD=password
4237
depends_on:
4338
- mysql
4439
restart: always
4540

41+
phpmyadmin:
42+
image: phpmyadmin/phpmyadmin
43+
container_name: ${APP_NAME}-phpmyadmin
44+
environment:
45+
PMA_HOST: "${DB_HOST}"
46+
PMA_PORT: 3306
47+
MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}"
48+
ports:
49+
- ${IP}:8080:80
50+
links:
51+
- mysql:mysql
52+
4653
composer:
4754
image: composer
48-
container_name: myapp-composer
55+
container_name: ${APP_NAME}-composer
4956
working_dir: /var/www/html
5057
restart: 'no'
5158
volumes:

0 commit comments

Comments
 (0)