Laravel Docker Setup

  Рет қаралды 4,211

Tenacity

Tenacity

Күн бұрын

Repo link: github.com/Ten...
In this video I will show you how to setup Laravel with Docker. You will have a Docker Compse file which will contain the Postgres Database (You can use MySQL or any other DB you want), Redis and a Worker for potential jobs you might be running.
We will also setup Caddy web server that can be used as a reverse proxy and to serve static files.
I will go through a setup on how to use this in a development environment but also how to this when you want to run these containers in a more serious manner.
The setup is quick and simple and it gets your app going fast. The setup is very scalable, which means we can run multiple app and worker services that can be load balanced if it comes to that. Also you can host this very easily on your server just by following what I did, developing your app and just cloning it on your local server and running it via Docker.
You can also experiment with different PHP Images, maybe you can use a serversideup image or just remove Caddy and PHP-FPM and use FrankenPHP, there are lots of possibilities.
Hope this video helped you!

Пікірлер: 29
@tenacity_dev
@tenacity_dev 5 күн бұрын
Hey people, I made this video as a first step and a base starting point to use docker containers with Laravel. I see many of you are interested and want to know more about how to handle static files, how to get this ready for production and maybe even how to use nginx with this. If you are curious and want to see the stuff I mentioned above, please like the comment and I can revisit this video in depth if enough people are interested.
@عبدالرحيماحمدامين
@عبدالرحيماحمدامين 5 күн бұрын
😊
@hm-gl1li
@hm-gl1li 3 күн бұрын
Definitely interested
@tenacity_dev
@tenacity_dev 15 күн бұрын
Quick note if you have problems with Caddy, you can easily switch to nginx, just use a nginx image and add the nginx.conf file. To go to production, setup your Laravel env, check permissions and build the containers and you're all set. The more complex your app is the more you will have to dive deeper and configure the project, it would be impossible for me to cover all possible cases without making a 15 hour video.
@lwa.dev74
@lwa.dev74 2 ай бұрын
This is amazing, this is the best explanation of docker setup and laravel thank you
@tenacity_dev
@tenacity_dev 2 ай бұрын
Thank you!!!
@antiquespride8861
@antiquespride8861 2 күн бұрын
how can we use laravel reverb on this setup?
@zsoro2
@zsoro2 Ай бұрын
What about storage folder on production? How would you handle that? Create a volume for storage ? Or what is the best way in your opinion? My problem is i dont want to loose the files, even if i rebuild the image
@tenacity_dev
@tenacity_dev Ай бұрын
If you need storage then you should map a docker volume in your caddy service to /storage in your application and then any uploaded files will be saved.
@indodacinfaceid
@indodacinfaceid 17 күн бұрын
​@@tenacity_dev i have followed your instruction, but why my files is return 404 when i access it? what i have do is: app: volumes: - public-data:/var/www/html/storage/app/public caddy: volumes: - ./laravel-app/storage/app/public:/var/www/html/storage/app/public - storage-volume:/var/www/html/storage volumes: public-data: storage-volume:
@akejemmy6010
@akejemmy6010 Ай бұрын
When switching from 'production' to 'development' mode, do I have to change the 'DB_HOST' from db to localhost?
@tenacity_dev
@tenacity_dev Ай бұрын
When you are running it locally with php artisan serve you should use localhost. When running it in production the container will want to connect the database and since they are running on the internal docker network you will use db.
@thefarshadghanbari
@thefarshadghanbari 2 ай бұрын
Please add reverb, I have a lot of problems with it
@tenacity_dev
@tenacity_dev 2 ай бұрын
I'll keep that in mind for the future videos
@creedio7130
@creedio7130 2 ай бұрын
Solid explanation, Is this suitable for production?
@tenacity_dev
@tenacity_dev 2 ай бұрын
Yes it is. It has everything you need for a production app. You should only modify the Caddyfile to suit your needs and of course have SSL on your site since you don't want to use port 80 in production.
@safwan_gazeli
@safwan_gazeli Ай бұрын
its the same way if im using vue.js as a frontend with inertia?
@tenacity_dev
@tenacity_dev Ай бұрын
I'm not quite sure. I usually add another service in the docker compose file for my UI where I use a framework when building any backend. Try this template out and add any changes you need.
@indodacinfaceid
@indodacinfaceid 17 күн бұрын
how to link the public storage? its always return 404.
@tenacity_dev
@tenacity_dev 16 күн бұрын
It's probably because the permissions need to be setup. Do the following: 1. Create a entrypoint.sh script in your Laravel directory and execute the entrypoint script from your Dockerfile 2. In that entrypoint.sh script you should run php artisan storage:link and run chmod and chown on the storage directory. 3. Now the storage has been linked to the public dir and you should go into the nginx container and check if it has those files. 4. Navigate to the URL. If you can't manage to pull this off, tell me and I'll try to make a video on how to setup storage also. Most people use a UI framework + Laravel (API only) that's why I did not go any deeper for static files.
@AbdiMayu-c3p
@AbdiMayu-c3p 16 күн бұрын
@@tenacity_dev i use laravel for fe and be haha. i've fix it by myself, the storage:link is always produce file named "storage" in public folder idk why. but when i run storage:link before build the image, and then run storage:link straight to the docker image app, it will run. and idk when i change the filesystem_disk to public, still return 404, but if filesystem_disk=local, its work. im sorry for my bad english, but the conclusion is, i dont even know how the storage:link work on docker, i just do a few adjustment to make it work
@tenacity_dev
@tenacity_dev 15 күн бұрын
@@AbdiMayu-c3p That's great, the storage:link command creates a symlink between storage and public directory
@AbdiMayu-c3p
@AbdiMayu-c3p 15 күн бұрын
​@@tenacity_dev but, the storage:link command return a file named 'storage', not a symlink folder. and hey, i have one request. since laravel is much faster if we use FrankenPHP, can u make separate video about it?
@tenacity_dev
@tenacity_dev 14 күн бұрын
@@AbdiMayu-c3p Got it, I'll keep that in mind for future videos. I'll have to read up on FrankenPHP first. I know what it is but I need to prepare and learn it before making the video.
@-Monkey_D_Luffy
@-Monkey_D_Luffy Ай бұрын
Everthing was going fine until i checked localhost:8000 and then found error there : Couldnot translate hostname "db" to address: nodename nor servname provided, or not known (Connection: pgsql, SQL: select * from "sessions" where "id" = ............... limit 1) .
@tenacity_dev
@tenacity_dev Ай бұрын
When you are developing locally go to the .env file and use 127.0.0.1 hostnames for the database and Redis. When you are using Docker environment then use db and redis for the hostname.
@suwandicahyadi9213
@suwandicahyadi9213 5 күн бұрын
@@tenacity_dev How to do development in a Docker environment?
@tenacity_dev
@tenacity_dev 5 күн бұрын
@@suwandicahyadi9213 When you want to develop the application, set the env HOST variable for redis and postgres to be 127.0.0.1 and run redis and postgres docker containers from the docker compose stack. Go to your Laravel project and run php artisan serve and you can then develop. When you are done and want to deploy the containers. SSH to your server, set the env HOST variable to be redis and db for their own services respectively and run the required commands inside the app to optimize imports and so on.
@lwa.dev74
@lwa.dev74 2 ай бұрын
Subs👍
小丑女COCO的审判。#天使 #小丑 #超人不会飞
00:53
超人不会飞
Рет қаралды 16 МЛН
How Strong Is Tape?
00:24
Stokes Twins
Рет қаралды 96 МЛН
Chain Game Strong ⛓️
00:21
Anwar Jibawi
Рет қаралды 41 МЛН
Beat Ronaldo, Win $1,000,000
22:45
MrBeast
Рет қаралды 158 МЛН
Как установить Laravel с Docker Compose
19:07
Laravel Reverb - публичные каналы
24:16
AreaWeb
Рет қаралды 2 М.
The secret behind FrankenPHP: Will it revolutionize PHP?
12:40
Chris Fidao
Рет қаралды 45 М.
docker stack is my new favorite way to deploy to a VPS
27:47
Dreams of Code
Рет қаралды 135 М.
Split A GPU Between Multiple Computers - Proxmox LXC (Unprivileged)
25:59
Setting up a production ready VPS is a lot easier than I thought.
29:50
Tmux From Scratch To BEAST MODE
12:44
DevOps Toolbox
Рет қаралды 134 М.
Laravel Docker Course | Complete Laravel Dockerization
43:31
Emad Zaamout
Рет қаралды 87 М.
Laravel with Docker
18:27
Scrypster
Рет қаралды 106 М.
小丑女COCO的审判。#天使 #小丑 #超人不会飞
00:53
超人不会飞
Рет қаралды 16 МЛН