Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
vgocoder committed Apr 13, 2021
0 parents commit 02ff0aa
Show file tree
Hide file tree
Showing 14 changed files with 3,687 additions and 0 deletions.
126 changes: 126 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Docker-compose-laravel-alpine-for-mac-m1
A pretty simplified Docker Compose workflow that sets up a LNMP network of containers for local Laravel development on Mac M1.

- `docker_php 130MB`
- `redis 2.3MB`
- `nginx 20.5MB`
- `mysql/mysql-server 436MB`

## Guide

To get started, make sure you have [Docker installed](https://docs.docker.com/docker-for-mac/install/) on your system, and then clone this repository.

Next, navigate in your terminal to the directory you cloned this, and spin up the containers for the web server by running :
- `docker-compose up -d --build`

Without buiding,just run:
- `docker-compose up -d`

Other useful command:
- `docker-compose down`
- `docker-compose stop php`
- `docker-compose start php`
- `docker exec -it php sh`

After that completes, follow the steps from the [src/README.md](src/README.md) file to get your Laravel project added in (or create a new blank one).

The following are built for our web server, with their exposed ports detailed:

- **nginx:stable-alpine** - `:80`
- **mysql/mysql-server:latest-aarch64** - `:3306`
- **php:7.4.16-fpm-alpine3.13** - `:9000`
- **redis:alpine** - `:6379`

## PHP

- `docker exec -w /var/www/your-site-root php composer install`
- `docker exec -w /var/www/your-site-root php php artisan serve`
- `docker exec -w /var/www/your-site-root php artisan migrate`

#### Extensions

- `bcmath`
- `Core`
- `ctype`
- `curl`
- `date`
- `dom`
- `fileinfo`
- `filter`
- `ftp`
- `gd`
- `hash`
- `iconv`
- `imap`
- `intl`
- `json`
- `libxml`
- `mbstring`
- `memcached`
- `mysqlnd`
- `openssl`
- `pcntl`
- `pcre`
- `PDO`
- `pdo_mysql`
- `pdo_sqlite`
- `Phar`
- `posix`
- `readline`
- `redis`
- `Reflection`
- `session`
- `SimpleXML`
- `sodium`
- `SPL`
- `sqlite3`
- `standard`
- `tidy`
- `tokenizer`
- `xml`
- `xmlreader`
- `xmlwriter`
- `Zend OPcache`
- `zip`
- `zlib`

## MySQL
Mysql Client: Default password :12345678
```
docker exec -it mysql mysql -uroot -p
```
Mysql Data Storage:
```
volumes:
- mysqldata:/var/lib/mysql
```

Starting with MySQL 8 you no longer can (implicitly) create a user using the GRANT command. Use CREATE USER instead, followed by the GRANT statement:

```
mysql> CREATE USER 'root'@'%' IDENTIFIED BY 'PASSWORD';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
```
**Caution:** about the security risks about WITH GRANT OPTION, see:
[Grant all privileges on database](https://dev.mysql.com/doc/refman/8.0/en/privileges-provided.html#priv_all)

Now, you can use any MySQL Client program to connect with MySQL Server,running on the container.
```
HOST:127.0.0.1
PORT:3306
USER:root
PASSWORD:12345678
```

## Redis
Redis Client: Default password :(empty)
```
docker exec -it redis redis-cli
```
Redis Data Storage
```
volumes:
- redisdata:/var/lib/mysql
```

95 changes: 95 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
version: "3.9"

services:
### PHP-FPM Container #######################################

php:
build:
context: ./php
dockerfile: Dockerfile
container_name: php
depends_on:
- mysql
- redis
restart: unless-stopped
tty: true
ports:
- "8000:8000"
working_dir: /var/www
volumes:
- ./wwwroot:/var/www
- ./php/php.ini:/usr/local/etc/php/php.ini
networks:
- app-network

### Nginx Server Container ##################################

nginx:
image: nginx:stable-alpine
container_name: nginx
depends_on:
- php
restart: unless-stopped
tty: true
ports:
- "80:80"
- "443:443"
environment:
MYSQL_ROOT_PASSWORD: 12345678
TZ: Asia/Shanghai
volumes:
- ./wwwroot:/var/www
- ./nginx/conf.d/:/etc/nginx/conf.d/
- ./nginx/log:/var/log/nginx
networks:
- app-network

### MySQL Container #########################################

mysql:
image: mysql/mysql-server:latest-aarch64
container_name: mysql
restart: unless-stopped
tty: true
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: 12345678
TZ: Asia/Shanghai
volumes:
- mysqldata:/var/lib/mysql
- ./mysql/my.cnf:/etc/mysql/my.cnf
restart: always
networks:
- app-network

### Redis Container #########################################

redis:
image: redis:alpine
container_name: redis
ports:
- "6379:6379"
environment:
MYSQL_ROOT_PASSWORD: 12345678
TZ: Asia/Shanghai
volumes:
- redisdata:/data
- ./redis/conf:/usr/local/etc/redis
- ./redis/log:/log
# 指定配置文件启动redis
command: ["redis-server", "/usr/local/etc/redis/redis.conf"]
restart: always
networks:
- app-network

#Docker Networks
networks:
app-network:
driver: bridge
#Volumes
volumes:
mysqldata:
driver: local
redisdata:
driver: local
35 changes: 35 additions & 0 deletions mysql/my.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation. The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

#
# The MySQL Client configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[mysql]

[mysqld]
skip-host-cache
skip-name-resolve
general_log = 1
general_log_file = /var/lib/mysql/general.log
45 changes: 45 additions & 0 deletions nginx/conf.d/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
server {
listen 80;
listen [::]:80;
server_name localhost;

#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;

location / {
root /usr/share/nginx/html;
index index.html index.htm;
}

#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 /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
49 changes: 49 additions & 0 deletions nginx/conf.d/demo.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
server {
listen 80;
listen [::]:80;
server_name demo.test;
root /var/www/demo/public;
index index.html index.htm index.php;

#charset koi8-r;
error_log /var/log/nginx/demo.test.error.log;
access_log /var/log/nginx/demo.test.access.log main;

#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 /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

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

location / {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
Empty file added nginx/log/.ignore
Empty file.
Loading

0 comments on commit 02ff0aa

Please sign in to comment.