Skip to content

Commit

Permalink
Add support for docker setup, xdebug, new-relic monitoring, nginx and…
Browse files Browse the repository at this point in the history
… ssl installation with letsencrypt
  • Loading branch information
mofesola committed Sep 10, 2017
1 parent 46d4817 commit 63f3426
Show file tree
Hide file tree
Showing 13 changed files with 1,046 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.git
.idea
8 changes: 7 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ APP_URL=http://localhost
APP_LOCALE=en
APP_FALLBACK_LOCALE=en

MYSQL_ROOT_PASSWORD=super-secret
MYSQL_DATABASE=homestead
MYSQL_USER=homestead
MYSQL_PASSWORD=secret
MYSQL_PORT=3306

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
Expand Down
2 changes: 2 additions & 0 deletions .env.nginx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DOMAINS=support.example.com
EMAIL=support@example.com
37 changes: 37 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM php:7.1.7-fpm
MAINTAINER Mofesola Babalola <[email protected]>

RUN apt update && apt install -y wget
RUN wget -O - https://download.newrelic.com/548C16BF.gpg | apt-key add - \
&& sh -c 'echo "deb http://apt.newrelic.com/debian/ newrelic non-free" \
> /etc/apt/sources.list.d/newrelic.list'

RUN apt update && apt install -y git \
zip \
gettext \
newrelic-php5 \
libxml2-dev \
libc-client-dev \
libkrb5-dev \
openssl \
netcat

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN docker-php-ext-configure imap --with-kerberos --with-imap-ssl \
&& docker-php-ext-install pdo pdo_mysql soap mbstring tokenizer xml imap

RUN pecl install xdebug-2.5.0

RUN newrelic-install install
COPY scripts/newrelic.ini /usr/local/etc/php/conf.d/

WORKDIR /var/www/html/handesk

COPY . /var/www/data
COPY scripts/start.sh /start.sh

RUN chmod +x /start.sh

EXPOSE 9000

ENTRYPOINT /start.sh
40 changes: 40 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
version: '2'
services:
nginx:
build: nginx/.
ports:
- "8000:80"
volumes:
- ./:/var/www/html/handesk/
- nginx:/etc/letsencrypt
env_file: .env.nginx
networks:
- handesk-network

php-fpm:
build: .
volumes:
- ./:/var/www/html/handesk/
env_file: .env
environment:
XDEBUG_HOST: ${XDEBUG_HOST}
networks:
- handesk-network

mysql:
image: mysql:5.7.13
container_name: handesk-mysql
volumes:
- mysql:/var/lib/mysql
env_file: .env
networks:
- handesk-network

volumes:
mysql:
driver: local
nginx:
driver: local

networks:
handesk-network:
12 changes: 12 additions & 0 deletions nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM mofesola/nginx-certbot
LABEL Maintainer Mofesola Babalola <[email protected]>

RUN rm /etc/nginx/conf.d/default.conf
COPY conf/ /etc/nginx/conf.d/
COPY entrypoint.sh /entrypoint.sh

WORKDIR /var/www/html/handesk

EXPOSE 80 443
ENTRYPOINT /entrypoint.sh
CMD ["nginx", "-g", "daemon off;"]
56 changes: 56 additions & 0 deletions nginx/conf/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
server {
listen 80 default_server;

root /var/www/html/handesk/public;
index index.php index.html index.htm;

# Make site accessible from http://localhost/
server_name support.example.com;

# Disable sendfile as per https://docs.vagrantup.com/v2/synced-folders/virtualbox.html
sendfile off;

# Add stdout logging

error_log /dev/stdout info;
access_log /dev/stdout;

location / {
# First attempt to serve request as file, then
# as directory, then fall back to index.html
try_files $uri $uri/ /index.php?q=$uri&$args;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html;
}

# pass the PHP scripts to FastCGI server listening on socket
#
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php-fpm:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
}

location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
expires 5d;
}

# deny access to . files, for security
#
location ~ /\. {
log_not_found off;
deny all;
}

}
12 changes: 12 additions & 0 deletions nginx/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
certbot --nginx --agree-tos --email ${EMAIL} --noninteractive --redirect --expand --domains ${DOMAINS} & > /dev/stout &

#write out current crontab
crontab -l > mycron
#echo new cron into cron file
echo '43 6 * * * certbot renew --post-hook "nginx -s reload"' >> mycron
#install new cron file
crontab mycron
rm mycron

nginx -g "daemon off;"
23 changes: 23 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,29 @@ php artisan migrate --seed
php artisan storage:link #if you use the local driver
```

Alternatively, you can run the entire setup locally by running the following on your computer

```shell
./run-local up --build

# To run in the background, run this:
./run-local up --build -d
```

## Using xdebug for local development
These guidelines are for PHPSTORM
* Find the command that works for your specific OS or manually input your local IP address in this line in `run-local`; `export XDEBUG_HOST=$(ipconfig getifaddr en0) # Specific to MacOS [export XDEBUG_HOST=$(ip -o -4 addr list ppp0 | awk '{print $4}' | cut -d/ -f1) # Specific to Linux distros]`
* Set the debug port in PHPSTORM to 9005 as seen in `scripts/xdebug.ini`
* Create a new server and map the path on your host machine to the exact path on your docker container e.g /Library/WebServer/Documents/handesk -> /var/www/html/handesk
* Go to RUN/Edit Configurations... within the IDE and click on the `+` icon to create a new config. Choose PHP Remote Debug
* Use the docker-server you created in step three and input `PHPSTORM` as the IDE KEY.
* Startup the containers using `./run-local up --build` and start listening for connections

## SSL Setup in production
* Edit the `.env.nginx` file to contain the domain that points to your server and application. Edit the email variable also
* In `nginx/conf/default.conf`, edit the `server_name` directive and use your server name. This should be the same as the domain you put in the first step


> The default admin user is [email protected] / admin
> If you want email pulling, you need to enable the `imap` extension on php (note that on mac the php-cli runs very slow, you need to update your /etc/hosts file
Expand Down
11 changes: 11 additions & 0 deletions run-local
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

# Set environment variables for dev
export XDEBUG_HOST=$(ipconfig getifaddr en0) # Specific to MacOS
export APP_ENV=${APP_ENV:-local}

if [ $# -gt 0 ]; then
docker-compose "$@"
else
docker-compose ps
fi
Loading

0 comments on commit 63f3426

Please sign in to comment.