by Reflexions
- Only depends on Docker
- Edit with Sublime, PhpStorm, Eclipse, etc
- Installs everything necessary to get started - laravel, php, database, imagemagick
- Can start with empty directory or existing laravel project
- No need to install PHP via homebrew / MacPorts / .MSI / apt-get / yum / etc
- Addresses permissions errors without requiring
chmod 777
1.) Install Docker to get docker, docker-compose, and the Kitematic GUI. Open a terminal with the docker env variables via Kitematic -> File -> Open Docker Command Line Terminal
2.) Create a docker-compose.yml and docker-compose.override.yml in the project directory. Define the laravel service and any desired database services:
version: '3'
services:
laravel:
image: reflexions/docker-laravel-fedora:9
env_file: .env
links:
- database
database:
image: postgres:13
env_file: .env
environment:
LC_ALL: C.UTF-8
The override file shouldn't be committed to git. It's for settings that differ between environments.
version: '3'
services:
laravel:
ports:
- "80:80"
volumes:
- .:/var/www/laravel
database:
ports:
- "5432:5432"
3.) Create an .env file in the project directory.
The database
service above corresponds to DB_HOST=database
below.
You'll have to fill in the blanks in the .env example:
# laravel service
APP_KEY=
DB_CONNECTION=pgsql
DB_HOST=database
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=
# database service
POSTGRES_DB=
POSTGRES_USER=
POSTGRES_PASSWORD=
4.) Obtain a Github Personal Access Token. Provide that in the GITHUB_TOKEN env var
Alternatively, create a GitHub user and ssh key that are only used by builds, and cp that to /root/.ssh/id_rsa
4.) With one command download the images, create the service containers, and start the application:
docker-compose up
5.) (optional) APP_KEY
$ docker exec -it $(docker ps | grep reflexions/docker-laravel | awk '{print $1}') bash
root@4c0491540409:/var/www/laravel# php artisan key:generate
6.) (optional) Tinker
$ docker exec -it $(docker ps | grep reflexions/docker-laravel | awk '{print $1}') bash
root@4c0491540409:/var/www/laravel# php artisan tinker
- Runs setup script first time
- Uses github credentials to avoid composer rate limit errors
- Downloads fresh laravel 5.4 if the app directory is missing
- Adds dependency on
reflexions/docker-laravel-fedora
composer package - Updates bootstrap/app.php to use
Reflexions\DockerLaravel\DockerApplication
to prevent permissions errors
These (webpack, gulp, etc) should be configured in your project's Dockerfile
Add a Dockerfile to the root of the project to deploy with Elastic Beanstalk:
FROM reflexions/docker-laravel-fedora:latest
MAINTAINER "Your Name" <[email protected]>
RUN /usr/share/docker-laravel-scripts/setup.sh
COPY . /var/www/laravel
WORKDIR /var/www/laravel
EXPOSE 80
ENTRYPOINT ["/usr/share/docker-laravel/bin/start.sh"]
This will define an application container. Use RDS to create the database. Add all variables from the .env file (including the APP_KEY, DB_HOST, etc) into the AWS Management Console
-> Elastic Beanstalk
-> Your-Environment
-> Configuration
-> Software Configuration
.
$ docker-compose up
ERROR: Couldn't connect to Docker daemon - you might need to run `docker-machine start default`.
$
Solution: Open terminal with Kitematic -> File -> Open Docker Command Line Terminal
.
Solution: Run Kitematic -> Install Docker Commands
. Then add the following line ~/.bash_profile:
eval "$(docker-machine env dev)"
Solution: Restart cluster. Settings in the .env file are only read on start.
$ docker-compose restart
$ docker-compose up
Illegal instruction: 4
$
Solution: Known issue with the Docker Toolbox on older CPUs. Install docker-compose using pip
Solution:
- Check that the DB_CONNECTION corresponds to the correct laravel db driver
- Check that the DB_HOST corresponds to the name of the service listed in docker-compose.yml (i.e. "database" in the example above)
Problem: RuntimeException: No supported encrypter found. The cipher and / or key length are invalid.
Solution:
- Run
php artisan key:generate
to update APP_KEY on .env, then restart the container.
Solution:
- Modify
docker-config.yml
to reference MySQL:
version: '3'
services:
laravel:
image: reflexions/docker-laravel-fedora:26
env_file: .env
links:
- database
database:
image: mysql:5.6
env_file: .env
environment:
LC_ALL: C.UTF-8
version: '3'
services:
laravel:
ports:
- "80:80"
volumes:
- .:/var/www/laravel
database:
ports:
- "3306:3306"
- Modify
.env
to reference MySQL:
DB_CONNECTION=mysql
# database service
MYSQL_ROOT_PASSWORD=
MYSQL_DATABASE=
MYSQL_USER=
MYSQL_PASSWORD=
Solution:
- Modify
docker-config.yml
to remove references to database - Modify
.env
to connect to MySQL via the docker-machine host ip address (192.168.99.1):
DB_CONNECTION=mysql
DB_HOST=192.168.99.1
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=
- Ensure that "bind_address" config parameter is set to 0.0.0.0 on startup. This can be set by your
my.cnf
, or it can be hard coded in your startup script. To check the value use this sql:
show variables like 'bind_address';
- Ensure that the database username has permission to connect from the docker container (usually 192.168.99.100)
CREATE USER 'username'@'192.168.99.100' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON application.* TO 'username'@'192.168.99.100';
FLUSH PRIVILEGES;