{am}shuanbao

Create Homestead Env in Docker

Create Homestead Env in Docker

The main content is from:https://store.docker.com/community/images/shincoder/homestead

1.Pull homestead image

1
$ docker pull shincoder/homestead:php7.0

2.Clone && Edit docker-compose.yml

1
$ git clone https://github.com/shincoder/homestead-docker.git

rename docker-compose.dist.yml to docker-compose.yml then edit the file with your own paths and ports.

3.Start your containers

There are only two containers to run. web container ( includes everything except your database ), and mariadb container.

1
$ sudo docker-compose up -d

4.SSH into the container (password: secret):

1
$ ssh -p 2222 homestead@localhost

5.Create Laravel application

1
2
3
4
5
6
7
8
9
 # update composer
composer selfupdate
# config mirror in China
composer config -g repo.packagist composer https://packagist.phpcomposer.com
# install laravel installer
composer global require "laravel/installer"
# install laravel && create an app
cd /apps
laravel new myapp

The mirror:https://pkg.phpcomposer.com

6.Add a virtual host(Running more apps in one Homestead)

Assuming you mapped your apps folder to /apps (you can change mappings in the docker-compose.yml file, it’s prefered to use absolute paths), you can do:

1
cd / && ./serve.sh myapp.dev /apps/myapp/public

In the host(Local), update /etc/hosts to include your app domain:

127.0.0.1               myapp.dev

QA

  1. Maybe you will get Permission denied when you are adding a virtual host

    switch user to su with default password secretin terminal like these:
    sudo su

  2. how to restart nginx in terminal (To use SU user)

    nginix -s reload