forked from BadChoice/handesk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for docker setup, xdebug, new-relic monitoring, nginx and…
… ssl installation with letsencrypt
- Loading branch information
Showing
13 changed files
with
1,046 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.git | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
DOMAINS=support.example.com | ||
EMAIL=support@example.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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;"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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;" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.