2016-08-19 08:24:02 +08:00
#### Install Docker
2017-04-05 06:32:41 +08:00
- Visit [DigitalOcean ](https://cloud.digitalocean.com/login ) and login.
- Click the `Create Droplet` button.
- Open the `One-click apps` tab.
- Select Docker with your preferred version.
- Continue creating the droplet as you normally would.
- If needed, check your e-mail for the droplet root password.
2016-08-19 08:24:02 +08:00
#### SSH to your Server
2017-04-05 06:32:41 +08:00
Find the IP address of the droplet in the DigitalOcean interface. Use it to connect to the server.
2016-08-19 08:24:02 +08:00
```
ssh root@ipaddress
```
2017-04-05 06:32:41 +08:00
You may be prompted for a password. Type the one you found within your e-mailbox. It'll then ask you to change the password.
2016-08-19 08:24:02 +08:00
2017-04-05 06:32:41 +08:00
You can now check if Docker is available:
2016-08-19 08:24:02 +08:00
```
2017-04-05 06:32:41 +08:00
$root@server:~# docker
2016-08-19 08:24:02 +08:00
```
#### Set Up Your Laravel Project
```
2017-04-05 06:32:41 +08:00
$root@server:~# apt-get install git
$root@server:~# git clone https://github.com/laravel/laravel
$root@server:~# cd laravel
$root@server:~/laravel/ git submodule add https://github.com/LaraDock/laradock.git
$root@server:~/laravel/ cd laradock
2016-08-19 08:24:02 +08:00
```
#### Install docker-compose command
```
2017-04-05 06:32:41 +08:00
$root@server:~/laravel/laradock# curl -L https://github.com/docker/compose/releases/download/1.8.0/run.sh > /usr/local/bin/docker-compose
$root@server:~/chmod +x /usr/local/bin/docker-compose
2016-08-19 08:24:02 +08:00
```
#### Create Your LaraDock Containers
```
2017-04-05 06:32:41 +08:00
$root@server:~/laravel/laradock# docker-compose up -d nginx mysql
2016-08-19 08:24:02 +08:00
```
2017-04-05 06:32:41 +08:00
Note that more containers are available, find them in the [docs ](http://laradock.io/introduction/#supported-software-containers ) or the `docker-compose.yml` file.
2016-08-19 08:24:02 +08:00
#### Go to Your Workspace
```
docker-compose exec workspace bash
```
2017-04-05 06:32:41 +08:00
#### Install and configure Laravel
Let's install Laravel's dependencies, add the `.env` file, generate the key and give proper permissions to the cache folder.
2016-08-19 08:24:02 +08:00
```
2017-04-05 06:32:41 +08:00
$ root@workspace:/var/www# composer install
$ root@workspace:/var/www# cp .env.example .env
$ root@workspace:/var/www# php artisan key:generate
$ root@workspace:/var/www# exit
$root@server:~/laravel/laradock# cd ..
$root@server:~/laravel# sudo chmod -R 777 storage bootstrap/cache
2016-08-19 08:24:02 +08:00
```
2017-04-05 06:32:41 +08:00
You can then view your Laravel site by visiting the IP address of your server in your browser. For example:
2016-08-19 08:24:02 +08:00
```
2017-04-05 06:32:41 +08:00
http://192.168.1.1
2016-08-19 08:24:02 +08:00
```
2017-04-05 06:32:41 +08:00
It should show you the Laravel default welcome page.
2016-08-19 08:24:02 +08:00
2017-04-05 06:32:41 +08:00
However, we want it to show up using your custom domain name, as well.
2016-08-19 08:24:02 +08:00
#### Using Your Own Domain Name
2017-04-05 06:32:41 +08:00
Login to your DNS provider, such as Godaddy, Namecheap.
Point the Custom Domain Name Server to:
2016-08-19 08:24:02 +08:00
```
ns1.digitalocean.com
ns2.digitalocean.com
ns3.digitalocean.com
```
2017-04-05 06:32:41 +08:00
Within DigitalOcean, you'll need to change some settings, too.
Visit: https://cloud.digitalocean.com/networking/domains
Add your domain name and choose the server IP you'd provision earlier.
#### Serving Site With NGINX (HTTP ONLY)
Go back to command line.
2016-08-19 08:24:02 +08:00
```
2017-04-05 06:32:41 +08:00
$root@server:~/laravel/laradock# cd nginx
$root@server:~/laravel/laradock/nginx# vim laravel.conf
2016-08-19 08:24:02 +08:00
```
2017-04-05 06:32:41 +08:00
Remove `default_server`
```
2016-08-19 08:24:02 +08:00
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
```
2017-04-05 06:32:41 +08:00
And add `server_name` (your custom domain)
2016-08-19 08:24:02 +08:00
```
listen 80;
listen [::]:80 ipv6only=on;
server_name yourdomain.com;
```
#### Rebuild Your Nginx
2017-04-05 06:32:41 +08:00
2016-08-19 08:24:02 +08:00
```
2017-04-05 06:32:41 +08:00
$root@server:~/laravel/laradock/nginx# docker-compose down
$root@server:~/laravel/laradock/nginx# docker-compose build nginx
2016-08-19 08:24:02 +08:00
```
#### Re Run Your Containers MYSQL and NGINX
2017-04-05 06:32:41 +08:00
2016-08-19 08:24:02 +08:00
```
2017-04-05 06:32:41 +08:00
$root@server:~/laravel/laradock/nginx# docker-compose up -d nginx mysql
2016-08-19 08:24:02 +08:00
```
2017-04-05 06:32:41 +08:00
**View Your Site with HTTP ONLY (http://yourdomain.com)**
2016-08-19 08:24:02 +08:00
#### Run Site on SSL with Let's Encrypt Certificate
2017-04-05 06:32:41 +08:00
**Note: You need to Use Caddy here Instead of Nginx**
2016-08-19 08:24:02 +08:00
2017-04-05 06:32:41 +08:00
To go Caddy Folders and Edit CaddyFile
2016-08-19 08:24:02 +08:00
```
2017-04-05 06:32:41 +08:00
$root@server:~/laravel/laradock# cd caddy
$root@server:~/laravel/laradock/caddy# vim Caddyfile
2016-08-19 08:24:02 +08:00
```
Remove 0.0.0.0:80
```
0.0.0.0:80
2016-11-01 09:45:50 +08:00
root /var/www/public
2017-04-05 06:32:41 +08:00
```
2016-08-19 08:24:02 +08:00
and replace with your https://yourdomain.com
```
https://yourdomain.com
2016-11-01 09:45:50 +08:00
root /var/www/public
2016-08-19 08:24:02 +08:00
```
2017-04-05 06:32:41 +08:00
2016-08-19 08:24:02 +08:00
uncomment tls
```
#tls self-signed
```
2017-04-05 06:32:41 +08:00
2016-08-19 08:24:02 +08:00
and replace self-signed with your email address
```
2017-04-05 06:32:41 +08:00
tls serverbreaker@gmai.com
2016-08-19 08:24:02 +08:00
```
2017-04-05 06:32:41 +08:00
2016-08-19 08:24:02 +08:00
This is needed Prior to Creating Let's Encypt
2017-04-05 06:32:41 +08:00
#### Run Your Caddy Container without the -d flag and Generate SSL with Let's Encrypt
2016-08-19 08:24:02 +08:00
```
2017-04-05 06:32:41 +08:00
$root@server:~/laravel/laradock/caddy# docker-compose up caddy
2016-08-19 08:24:02 +08:00
```
2017-04-05 06:32:41 +08:00
You'll be prompt here to enter your email... you may enter it or not
2016-08-19 08:24:02 +08:00
```
Attaching to laradock_mysql_1, laradock_caddy_1
caddy_1 | Activating privacy features...
caddy_1 | Your sites will be served over HTTPS automatically using Let's Encrypt.
caddy_1 | By continuing, you agree to the Let's Encrypt Subscriber Agreement at:
caddy_1 | https://letsencrypt.org/documents/LE-SA-v1.0.1-July-27-2015.pdf
caddy_1 | Activating privacy features... done.
caddy_1 | https://yourdomain.com
caddy_1 | http://yourdomain.com
```
2017-04-05 06:32:41 +08:00
After it finishes, press `Ctrl` + `C` to exit.
2016-08-19 08:24:02 +08:00
#### Stop All Containers and ReRun Caddy and Other Containers on Background
```
2017-04-05 06:32:41 +08:00
$root@server:~/laravel/laradock/caddy# docker-compose down
$root@server:~/laravel/laradock/caddy# docker-compose up -d mysql caddy
2016-08-19 08:24:02 +08:00
```
2017-04-05 06:32:41 +08:00
2016-08-19 08:24:02 +08:00
View your Site in the Browser Securely Using HTTPS (https://yourdomain.com)
2017-04-05 06:32:41 +08:00
**Note that Certificate will be Automatically Renew By Caddy**
2016-08-19 08:24:02 +08:00
>References:
>
- [https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-16-04 ](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-16-04 )
- [https://www.digitalocean.com/products/one-click-apps/docker/ ](https://www.digitalocean.com/products/one-click-apps/docker/ )
- [https://docs.docker.com/engine/installation/linux/ubuntulinux/ ](https://docs.docker.com/engine/installation/linux/ubuntulinux/ )
- [https://docs.docker.com/compose/install/ ](https://docs.docker.com/compose/install/ )
- [https://caddyserver.com/docs/automatic-https ](https://caddyserver.com/docs/automatic-https )
- [https://caddyserver.com/docs/tls ](https://caddyserver.com/docs/tls )
- [https://caddyserver.com/docs/caddyfile ](https://caddyserver.com/docs/caddyfile )