2017-03-17 08:36:00 +01:00
---
2019-07-15 18:59:43 +02:00
title: 2. Getting Started
2017-03-17 08:36:00 +01:00
type: index
weight: 2
---
2019-07-15 18:59:43 +02:00
## 2.1 Requirements
2017-03-17 08:36:00 +01:00
- [Git ](https://git-scm.com/downloads )
2018-02-16 09:36:22 +01:00
- [Docker ](https://www.docker.com/products/docker/ ) `>= 17.12`
2019-07-08 17:36:07 +02:00
- [gcloud ](https://cloud.google.com/sdk/install )
2017-03-17 08:36:00 +01:00
2019-07-15 18:59:43 +02:00
## 2.2 Installation
2017-05-01 12:36:31 +02:00
2017-05-01 21:00:32 +02:00
Choose the setup the best suits your needs.
2017-03-17 08:36:00 +01:00
2017-05-01 21:00:32 +02:00
- [A) Setup for Single Project ](#A )
- [A.1) Already have a PHP project ](#A1 )
- [A.2) Don't have a PHP project yet ](#A2 )
- [B) Setup for Multiple Projects ](#B )
2019-07-08 17:36:07 +02:00
### Setup gcloud for docker registry
```
gcloud auth configure-docker
```
and login to gcloud for use the registry and auth the permission.
```
gcloud auth login
```
2017-05-01 21:00:32 +02:00
< a name = "A" > < / a >
### A) Setup for Single Project
2017-03-17 08:36:00 +01:00
> (Follow these steps if you want a separate Docker environment for each project)
2017-05-01 21:00:32 +02:00
< a name = "A1" > < / a >
### A.1) Already have a PHP project:
2017-03-17 08:36:00 +01:00
1 - Clone laradock on your project root directory:
```bash
git submodule add https://github.com/Laradock/laradock.git
```
2017-05-01 21:00:32 +02:00
Note: If you are not using Git yet for your project, you can use `git clone` instead of `git submodule ` .
*To keep track of your Laradock changes, between your projects and also keep Laradock updated [check these docs ](/documentation/#keep-track-of-your-laradock-changes )*
2017-03-17 08:36:00 +01:00
2019-07-23 22:45:05 +02:00
2 - Make sure your folder structure should look like this:
2017-03-17 08:36:00 +01:00
```
+ project-a
2017-04-25 02:49:25 +02:00
+ laradock-a
2017-03-17 08:36:00 +01:00
+ project-b
2017-04-25 02:49:25 +02:00
+ laradock-b
2017-03-17 08:36:00 +01:00
```
2017-05-01 21:00:32 +02:00
*(It's important to rename the laradock folders to unique name in each project, if you want to run laradock per project).*
2017-03-17 07:46:19 +01:00
2019-07-23 22:45:05 +02:00
3 - Go to the [Usage ](#Usage ) section.
2017-03-17 08:36:00 +01:00
2017-05-01 21:00:32 +02:00
< a name = "A2" > < / a >
### A.2) Don't have a PHP project yet:
2017-03-17 08:36:00 +01:00
1 - Clone this repository anywhere on your machine:
```bash
git clone https://github.com/laradock/laradock.git
```
Your folder structure should look like this:
```
+ laradock
+ project-z
```
2 - Edit your web server sites configuration.
2017-04-23 20:44:18 +02:00
We'll need to do step 1 of the [Usage ](#Usage ) section now to make this happen.
2017-03-17 08:36:00 +01:00
2017-04-23 20:44:18 +02:00
```
cp env-example .env
```
2017-03-17 08:36:00 +01:00
2018-09-08 13:42:58 +02:00
At the top, change the `APP_CODE_PATH_HOST` variable to your project path.
2017-03-17 08:36:00 +01:00
2017-04-23 20:44:18 +02:00
```
2018-09-08 13:42:58 +02:00
APP_CODE_PATH_HOST=../project-z/
2017-04-23 20:44:18 +02:00
```
2017-03-17 01:53:14 +01:00
2017-04-23 20:44:18 +02:00
Make sure to replace `project-z` with your project folder name.
2017-03-17 08:36:00 +01:00
2019-07-23 22:45:05 +02:00
3 - Go to the [Usage ](#Usage ) section.
2017-03-17 08:36:00 +01:00
2017-05-01 21:00:32 +02:00
< a name = "B" > < / a >
### B) Setup for Multiple Projects:
2018-07-01 14:22:25 +02:00
> (Follow these steps if you want a single Docker environment for all your projects)
2017-03-17 08:36:00 +01:00
2017-05-01 21:00:32 +02:00
1 - Clone this repository anywhere on your machine (similar to [Steps A.2. from above ](#A2 )):
2017-03-17 08:36:00 +01:00
```bash
git clone https://github.com/laradock/laradock.git
```
Your folder structure should look like this:
```
+ laradock
+ project-1
+ project-2
```
2019-07-15 18:59:43 +02:00
2 - Go to your web server and create config files to point to different project directory when visiting different domains:
2017-03-17 08:36:00 +01:00
2019-07-15 18:59:43 +02:00
For **Nginx** go to `nginx/sites` , for **Apache2** `apache2/sites` .
Laradock by default includes some sample files for you to copy `app.conf.example` , `laravel.conf.example` and `symfony.conf.example` .
2017-03-17 08:36:00 +01:00
2017-08-01 21:12:43 +02:00
3 - change the default names `*.conf` :
2017-03-17 08:36:00 +01:00
You can rename the config files, project folders and domains as you like, just make sure the `root` in the config files, is pointing to the correct project folder name.
4 - Add the domains to the **hosts** files.
```
2017-12-17 21:35:31 +01:00
127.0.0.1 project-1.test
127.0.0.1 project-2.test
2017-08-01 21:12:43 +02:00
...
2017-03-17 08:36:00 +01:00
```
2019-07-15 18:59:43 +02:00
2017-12-15 13:23:24 +01:00
If you use Chrome 63 or above for development, don't use `.dev` . [Why? ](https://laravel-news.com/chrome-63-now-forces-dev-domains-https ). Instead use `.localhost` , `.invalid` , `.test` , or `.example` .
2017-03-17 08:36:00 +01:00
2019-07-23 22:45:05 +02:00
4 - Go to the [Usage ](#Usage ) section.
2017-03-17 08:36:00 +01:00
2017-05-01 21:00:32 +02:00
< a name = "Usage" > < / a >
2019-07-15 18:59:43 +02:00
## 2.3 Usage
2017-03-17 08:36:00 +01:00
**Read Before starting:**
If you are using **Docker Toolbox** (VM), do one of the following:
2017-03-31 18:35:13 +02:00
- Upgrade to Docker [Native ](https://www.docker.com/products/docker ) for Mac/Windows (Recommended). Check out [Upgrading Laradock ](/documentation/#upgrading-laradock )
2018-06-28 07:29:30 +02:00
- Use Laradock v3.\*. Visit the [Laradock-ToolBox ](https://github.com/laradock/laradock/tree/LaraDock-ToolBox ) branch. *(outdated)*
2017-03-17 08:36:00 +01:00
< br >
2017-05-07 15:17:25 +02:00
We recommend using a Docker version which is newer than 1.13.
< br >
2017-05-01 21:00:32 +02:00
>**Warning:** If you used an older version of Laradock it's highly recommended to rebuild the containers you need to use [see how you rebuild a container ](#Build-Re-build-Containers ) in order to prevent as much errors as possible.
2017-03-17 08:36:00 +01:00
< br >
2017-04-23 20:44:18 +02:00
1 - Enter the laradock folder and copy `env-example` to `.env`
2017-02-22 20:59:06 +01:00
2017-03-17 07:46:19 +01:00
```shell
cp env-example .env
```
2017-02-22 20:59:06 +01:00
2018-11-13 12:44:43 +01:00
You can edit the `.env` file to choose which software's you want to be installed in your environment. You can always refer to the `docker-compose.yml` file to see how those variables are being used.
2017-03-17 08:36:00 +01:00
2017-11-23 20:21:38 +01:00
Depending on the host's operating system you may need to change the value given to `COMPOSE_FILE` . When you are running Laradock on Mac OS the correct file separator to use is `:` . When running Laradock from a Windows environment multiple files must be separated with `;` .
2017-05-01 21:00:32 +02:00
2018-06-24 03:43:54 +02:00
By default the containers that will be created have the current directory name as suffix (e.g. `laradock_workspace_1` ). This can cause mixture of data inside the container volumes if you use laradock in multiple projects. In this case, either read the guide for [multiple projects ](#B ) or change the variable `COMPOSE_PROJECT_NAME` to something unique like your project name.
2018-04-25 08:38:43 +02:00
2018-06-24 03:43:54 +02:00
2 - Build the environment and run it using `docker-compose`
2017-03-17 07:46:19 +01:00
In this example we'll see how to run NGINX (web server) and MySQL (database engine) to host a PHP Web Scripts:
2017-03-17 08:36:00 +01:00
```bash
docker-compose up -d nginx mysql
```
2018-06-24 03:43:54 +02:00
**Note**: All the web server containers `nginx` , `apache` ..etc depends on `php-fpm` , which means if you run any of them, they will automatically launch the `php-fpm` container for you, so no need to explicitly specify it in the `up` command. If you have to do so, you may need to run them as follows: `docker-compose up -d nginx php-fpm mysql` .
2017-03-17 08:36:00 +01:00
2017-05-01 21:00:32 +02:00
2018-04-02 02:53:23 +02:00
You can select your own combination of containers from [this list ](http://laradock.io/introduction/#supported-software-images ).
2017-03-17 08:36:00 +01:00
2017-05-01 21:00:32 +02:00
*(Please note that sometimes we forget to update the docs, so check the `docker-compose.yml` file to see an updated list of all available containers).*
2017-03-17 08:36:00 +01:00
< br >
2017-03-17 07:46:19 +01:00
3 - Enter the Workspace container, to execute commands like (Artisan, Composer, PHPUnit, Gulp, ...)
2017-03-17 08:36:00 +01:00
```bash
docker-compose exec workspace bash
```
2017-05-01 21:00:32 +02:00
*Alternatively, for Windows PowerShell users: execute the following command to enter any running container:*
2017-03-17 08:36:00 +01:00
```bash
docker exec -it {workspace-container-id} bash
```
2017-05-01 21:00:32 +02:00
**Note:** You can add `--user=laradock` to have files created as your host's user. Example:
2017-03-17 08:36:00 +01:00
```shell
docker-compose exec --user=laradock workspace bash
```
2017-05-01 21:00:32 +02:00
*You can change the PUID (User id) and PGID (group id) variables from the `.env` file)*
2017-03-17 08:36:00 +01:00
< br >
2018-06-24 03:43:54 +02:00
4 - Update your project configuration to use the database host
2017-03-17 08:36:00 +01:00
2017-03-17 07:46:19 +01:00
Open your PHP project's `.env` file or whichever configuration file you are reading from, and set the database host `DB_HOST` to `mysql` :
2017-03-17 08:36:00 +01:00
```env
DB_HOST=mysql
```
2019-07-23 22:45:05 +02:00
You need to use the Laradock's default DB credentials which can be found in the `.env` file (ex: `MYSQL_USER=` ).
Or you can change them and rebuild the container.
2017-05-01 21:00:32 +02:00
*If you want to install Laravel as PHP project, see [How to Install Laravel in a Docker Container ](#Install-Laravel ).*
2017-03-17 08:36:00 +01:00
< br >
2019-07-23 22:45:05 +02:00
5 - Open your browser and visit your localhost address.
If you followed the multiple projects setup, you can visit `http://project-1.test/` and `http://project-2.test/` .
[http://localhost:8080 ](http://localhost:8080 )
Make sure you add use the right port number as provided by your running server. Ex: NGINX uses port 8080 by default while Apache2 uses 80.