Giter Club home page Giter Club logo

docker-laravel-8's Introduction

Docker - Laravel

Docker

Image

A pretty simplified Docker Compose workflow that sets up a LEMP (Linux, NGINX, MySQL, PHP) network of containers for local Laravel development.

Ports

Ports used in the project:

Software Port
nginx 8080
phpmyadmin 8081
mysql 3306
php 9000
xdebug 9001
redis 6379

Use

To get started, make sure you have Docker installed on your system and Docker Compose, and then clone this repository.

  1. Clone this project:

    git clone https://github.com/supermavster/docker-laravel-8.git
  2. Inside the folder docker-laravel-8 and Generate your own .env to docker compose with the next command:

    cp .env.example .env
  3. You need Create or Put your laravel project in the folder source; to create follow the next instructions Here.

  4. Build the project whit the next commands:

    docker-compose up --build

Remember

The configuration of the database must be the same on both sides .

# .env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=db_name
DB_USERNAME=db_user
DB_PASSWORD=db_password
DB_ROOT_PASSWORD=secret
# source/.env
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=db_name
DB_USERNAME=db_user
DB_PASSWORD=db_password

The only change is the DB_HOST in the source/.env where is called to the container of mysql:

# source/.env
DB_HOST=mysql

Special Cases

To Down and remove the volumes we use the next command:

docker-compose down -v

Update Composer:

docker-compose run --rm composer update

Run compiler (Webpack.mix.js) or Show the view compiler in node:

docker-compose run --rm npm run dev

Run all migrations:

docker-compose run --rm artisan migrate

docker-laravel-8's People

Contributors

supermavster avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

docker-laravel-8's Issues

how to use phpmyadmin?

Thank you for your awesome setup. I got it working with my laravel application. The only thing I am not able to do is get phpMyAdmin working. I can get at it using http://localhost:8081/ but no root or other user & password seems to work. I can get to the CLI but I can find no config.inc.php and cannot create and edit one. I have tried to install nano with various ways ( php /bin/sh -c "sudo yum -y install nano") but cannot get it to install in the CLI.
My application works fine but I can't enter phpmyadmin using those credentials either (and on top of this I don't know what to fill in at "Server" and have tried various things there as well).
When I use "mysql" as the server name and fill in my database user name and database password I get this error:
mysqli::real_connect(): (HY000/1130): Host 'phpmyadmin.docker-laravel-8_laravel' is not allowed to connect to this MySQL server

So I am doing something wrong :-) please help. How do I install nano or how do I get phpmyadmin working? how to make a config.inc.php and how can I edit it? Many thanks in advance.

Exception thrown when trying to run docker-compose up --build

When trying to run docker up I get the following exception:

Traceback (most recent call last):
  File "docker-compose", line 3, in <module>
  File "compose\cli\main.py", line 81, in main
  File "compose\cli\main.py", line 200, in perform_command
  File "compose\cli\command.py", line 60, in project_from_options
  File "compose\cli\command.py", line 152, in get_project
  File "compose\cli\docker_client.py", line 41, in get_client
  File "compose\cli\docker_client.py", line 170, in docker_client
  File "docker\api\client.py", line 197, in __init__
  File "docker\api\client.py", line 221, in _retrieve_server_version
docker.errors.DockerException: Error while fetching server API version: (2, 'CreateFile', 'The system cannot find the file specified.')
[1380] Failed to execute script docker-compose

Anyone else getting this message? Any help would be great!

Source Folder Permission denied

Hello my friend,
Today I wanted to put my laravel project online with docker. I followed your guide, but after putting my project in the "source" folder and running the command "docker-compose run --rm composer install" this error appeared:
"[ErrorException]
file_put_contents (/var/www/html/vendor/composer/installed.json): failed to open stream: Permission denied "

Could you help me with this problem? I'm nooby with Docker and Laravel. Thanks for what you do! ๐Ÿ‘

PS. My server run: Ubuntu 20.04.1 Focal Fossa

MySQL Database Issue - Connection Refused

Hello @supermavster, I tried to run the migrations from my project to the mysql database, but when I run docker-compose run --rm artisan migrate --seed command the system returns with:
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = database and table_name = migrations and table_type = 'BASE TABLE') .

.env
{
--MYSQL Password--
DB_ROOT_PASSWORD=secret
--Connection DB--
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=database
DB_USERNAME=username
DB_PASSWORD=secret
}

source folder .env
{
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:43WPYT1zCqO7WmZifstlRbNwf0kUErINrXnLZZAELjo=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=database
DB_USERNAME=username
DB_PASSWORD=secret

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=database
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
}

MySQL login information

I Cant do the migration
SQLSTATE[HY000] [1130] Host 'docker_laravel_artisan_run_5de336c01a78.docker_laravel_laravel' is not allowed to connect to this MySQL server (SQL: select * from information_schema.tables where table_schema = docker and table_name = migrations and table_type = 'BASE TABLE')

Add SSL

Hi, Bro @supermavster I'm new to Docker and Nginx and currently looking for a way for handling HTTPS requests for my Laravel project at my local.

I'm trying to modify your Nginx configuration for handling HTTPS requests. But I keep getting 403 forbidden errors in the browser.

Can you give me a clue why this is happening? And I'm gonna really appreciate it if you can explain to me how to do it in the right way.

Here's my Nginx configuration :

server {
listen 80;
listen 443 ssl;

server_name  localhost;
server_name  127.0.0.1;
root /var/www/html/public;

# return 301 https://127.0.0.1$request_uri;
# return 301 https://localhost$request_uri;

ssl_certificate /etc/ssl/certs/localhost.pem;
ssl_certificate_key /etc/ssl/private/localhost-key.pem;


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

location ~ \.php$ {
    # try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass php:9000;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    # fastcgi_param SCRIPT_NAME     $fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
}

}

Here's the error I got:

directory index of "/var/www/html/public/" is forbidden,

Thank you very much.

RuntimeException

Creating php ... done
Creating docker-laravel-8_composer_run ... done
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Package operations: 95 installs, 0 updates, 0 removals

                                                                 
  [RuntimeException]                                             
  /var/www/html/vendor does not exist and could not be created.  
                                                                 

install [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-suggest] [--no-dev] [--no-autoloader] [--no-scripts] [--no-progress] [--no-install] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--apcu-autoloader-prefix APCU-AUTOLOADER-PREFIX] [--ignore-platform-req IGNORE-PLATFORM-REQ] [--ignore-platform-reqs] [--] [<packages>]...

ERROR: 1

Not working

PHP_FPM and nginx not communicating. php-fpm server stopped after docker-compose up -d. aws return 502 bad gateway

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.