Setting up a LAMP Stack from Scratch using Docker

  Рет қаралды 27,509

Adam Thomas

Adam Thomas

Күн бұрын

Пікірлер: 102
@astev52
@astev52 Жыл бұрын
Thanks for leaving those errors in the video, it's the biggest struggle I have with docker is finding solutions to little errors like that.
@alivenumber5
@alivenumber5 11 ай бұрын
I'm blown away. This is great stuff. The "aha!" moment for me was when the php container image didn't have the proper mysql data access functions and you just changed the image to one that had that installed and ready to go already. This changes deployment completely.
@Aryan21able
@Aryan21able Жыл бұрын
Best thing is, he never cut the video, if there is a bug the he shows it. This is what we mostly face in real life
@alphamadioubah6169
@alphamadioubah6169 Жыл бұрын
Very good pace, good tone and a true step-by-step guide
@thanasister
@thanasister 9 ай бұрын
Some notes: 1. This is for the v1 of docker Compose (EOL June 2023). The commands are slightly different in v2. Also the `docker-compose.yml` is suggested to be named `compose.yaml` 2. You can set a simple volume in mysql instead of entry point stuff, to persist the db data. The volume will store all the db data in a location outside the container.
@jeffrowe6004
@jeffrowe6004 6 ай бұрын
Thanks, that's probably why my mailcow didn't work as well. Guess it's time for a newer video
@pikadroo
@pikadroo 10 ай бұрын
My friend. I want to thank you with all my heart for making this video. I am not sure if I will be using docker but you presented the best argument for using it then any video I have tried to watch. I appreciate you! Keep up the great content!
@vincentstevenson2200
@vincentstevenson2200 2 жыл бұрын
I really appreciate your thoroughness on this tutorial. You are a great teacher Adam!
@MarcMcRae
@MarcMcRae Жыл бұрын
Brilliant! Video paints a thousand words to actually see the real life process flow. VERY very cool docker stuff & thanks for sharing.
@codeadamca
@codeadamca Жыл бұрын
Thanks!!
@patafrom
@patafrom Жыл бұрын
First , many thanks for this great work. it helped me A LOT ! my contirnution to all who are stuck with some connecticty issues from php to the mysql db. I used to use the IP adress (of the host ) in my php code to join the db. as many of you it was not working. Now i switch the servername in my php code from ip to docker alias. this alias is known from the apache part as all containers are in the same network. now it works and goodbye mysqli_connect errors !
@adryelgainza1686
@adryelgainza1686 2 жыл бұрын
Hey man im getting into cybersecurity and so im trying to learn how to create web applications so i have a further understanding of how to break them and your content man has been a blessing. This is a great in depth video and you provide awesome explanations. Def gonna recommend you to anyone who asks how i learned to create LAMP stacks.
@codeadamca
@codeadamca 2 жыл бұрын
Great! Thanks!
@zedolok4508
@zedolok4508 Жыл бұрын
this help me a lot understand each thing inside of docker compose, thank u very much, now i can create my own docker compose for my projects :)
@viewerck
@viewerck Ай бұрын
thanks, so patient and clear!
@lalaland1670
@lalaland1670 Жыл бұрын
Thank you so much for the video. Really helped me get started with Docker.
@shizo_n01z3
@shizo_n01z3 2 жыл бұрын
Great video, very nice to follow
@alexsilkin5222
@alexsilkin5222 2 жыл бұрын
Great video and instructions! Thank you for making this.
@codeadamca
@codeadamca 2 жыл бұрын
You are so welcome!
@pw5687
@pw5687 Жыл бұрын
This was a big help, thanks!
@saidbakr
@saidbakr 2 жыл бұрын
Wonderful, it is the first time I got an idea about how could I transfer or migrate my code and data from an host to another and running the docker with all configs by just one command.
@codeadamca
@codeadamca 2 жыл бұрын
Great! Docker is awesome!
@sparkdogy2k
@sparkdogy2k 2 жыл бұрын
awesome video man! really helped me with my first time with docker :)
@codeadamca
@codeadamca 2 жыл бұрын
Glad I could help!
@alexandrosroussos
@alexandrosroussos 10 күн бұрын
Hi, thx for the video, in the part you specify ports, is there any syntax that would let me redirect an incoming connection to a specific container based on the domain the user has used ? Similar to Apache's domain based virtual hosts but instead of having apache using a specific /html path depending on the domain used, Docker would redirect the user to the right container instead.
@twodogsandstuff
@twodogsandstuff 10 ай бұрын
Excellent tutorial. I have been playing around with docker and wondered what it would take to have self-hosted environment through there as opposed to mamp pro. so this was helpful to see the initial setup. But I am confused about dumping the db, when you mention restarting the service it db would disappear (thus needing to dump the db). Is that correct for in unexpected scenarios such as a power outage? Once everything boots back up all content not in the dumped database would be gone?
@b4rt1j1
@b4rt1j1 2 жыл бұрын
After watching like 15 tutorials how to run lamp stack using docker, this is the first time i get it, very simply explained thank you so much! One little question, if I want to use composer - should i run it in container? I thought its the matter of local system, but composer images on docker hub dissapointed me. Have a great day!
@codeadamca
@codeadamca 2 жыл бұрын
As long as you are running composer on a connected volume, Docker should sync the files.
@b4rt1j1
@b4rt1j1 2 жыл бұрын
@@codeadamca Sorry for my annoying questions, I still can't get composer woking, I have composer in my windows PATH so I can initialize it locally, but what if I want composer to be installed with all dependecies that my project needs (based on composer.json) when someone pulls my project from GitHub repository, i think vendor folder should'nt be commited to github due to its size. I would appreciate your advice sir, have a great day!
@olegfare4625
@olegfare4625 Жыл бұрын
amazing explanation!
@Happinessisalwaysthere
@Happinessisalwaysthere Жыл бұрын
Not working the same way for me. still receiving the error: atal error: Uncaught Error: Call to undefined function mysqli_connect() in /var/www/html/index.php:3 Stack trace: #0 {main} thrown in /var/www/html/index.php on line 3
@emveeoh
@emveeoh Жыл бұрын
Hello Adam! Thank you for this tutorial. I used your Github repo, ran it without any edits and I get this error (as others have reported): Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in /var/www/html/index.php:3 Stack trace: #0 {main} thrown in /var/www/html/index.php on line 3 Apparently, the php image ( image: php:8.1.1-apache) from Dockerhub does not have mysqli enabled for PHP. Can you please advise us on the proper way to enable it?
@rabbit.it.slabikovsky
@rabbit.it.slabikovsky Жыл бұрын
I had the same problem and I solved it this way: Firstly I created folder (in my case I named it "php_custom"), then inside it I made Dockerfile with following content: FROM php:8.1.1-apache RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli Next, in docker-compose.yml below "www" I added "build" prop with value linked to folder with Dockerfile, like this: www: depends_on: - db image: php:8.1.1-apache build: ./php_custom volumes: - "./:/var/www/html" ports: - 80:80 - 443:443 networks: - lamp-docker This should work with "--build" flag in "docker-compose up" command. The flag is needed only once unless you want to rebuild docker again
@isaacambi1914
@isaacambi1914 7 ай бұрын
Great content.
@mkannanmsc
@mkannanmsc 2 жыл бұрын
You may also create a Tutorial with all the best practices for a LAMP stack production azure k8s cluster, including CI/CD pipe line from Docker..
@codeadamca
@codeadamca Жыл бұрын
I don't even know what half those terms mean!! :)
@mkannanmsc
@mkannanmsc 2 жыл бұрын
Very Good Adam.👍 Wondering as per best practices, we won't allow empty passwords to connect mysql
@codeadamca
@codeadamca Жыл бұрын
Yes, good advice!
@queshafiq8952
@queshafiq8952 Жыл бұрын
Hi Sir How about if the PHP file is a form and dynamically use to key in data into db.? Is data will be gone too after down the container? How to make data persistent?
@Olliewiener
@Olliewiener 7 ай бұрын
Is there a way to do it in a single container instead of multiple pls and thanks
@WilliamKim
@WilliamKim Жыл бұрын
Thank you!
@snorky4506
@snorky4506 2 жыл бұрын
Excellent, just excellent! I kept getting this error at localhost:80 even after changing the php image: Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in /var/www/html/index.php:3 Stack trace: #0 {main} thrown in /var/www/html/index.php on line 3 I'm running it on ubuntu 20.04, and after a whole lotta googling, changing to this image instead fixed my problem: thecodingmachine/php:8.1.1-v4-apache
@codeadamca
@codeadamca 2 жыл бұрын
There are many different way to connect to a database and execute a query. You can use a series of mysql functions (mostly deprecated), mysqli functions (i stands for improved), or PDO. Here is a good page describing the difference and the syntax for each: www.w3schools.com/php/php_mysql_connect.asp
@danielunyu
@danielunyu 2 жыл бұрын
Good job!! Thanks
2 жыл бұрын
@@codeadamca I tried connecting in three different ways: new mysqli, mysqli_connect and new PDO, and all ways didn't work for me.
@marcoverheul
@marcoverheul 2 жыл бұрын
I finally got it working thanks to another tutorial. In the root of the project, add file "php.Dockerfile" with this content: FROM php:8.1.10-apache RUN docker-php-ext-install mysqli pdo pdo_mysql In docker-compose.yml replace "image: php:8.1.10-apache" with build: dockerfile: php.Dockerfile context: . This install mysqli when running the container.
@ZamriRosliGooglePlus
@ZamriRosliGooglePlus Жыл бұрын
thanks bro, it works! got the same error as above back then.
@dannymason3970
@dannymason3970 2 жыл бұрын
This really helped a lot, thanks Adam. I am very new to Docker (having always used XAMPP) for local PHP dev. The only issue I have is when trying to use .htaccess overwrites. Not sure if there is a way to set apache config to allow .htaccess using some env variable in the docker-compose file?
@codeadamca
@codeadamca 2 жыл бұрын
Here is a good link to adding custom configuration to your apache setup: www.cloudreach.com/en/technical-blog/containerize-this-how-to-use-php-apache-mysql-within-docker-containers/
@ronaldjoytengco7000
@ronaldjoytengco7000 8 ай бұрын
I had a sqlyog and mysql workbench how can i connect to the database using that software? Thank you
@Salamaleikum80
@Salamaleikum80 Жыл бұрын
How does docker populate the database with data? Where is that data saved? and why does docker miss the data if you don't define volume?😅
@alloesibanda
@alloesibanda Жыл бұрын
Thank you for the video and excellent teaching but I am having a problem trying to retain the new records in the db. the new records don't show when I restart the containers. Do I have to export the dump.sql everytime I shut down ?
@codeadamca
@codeadamca Жыл бұрын
Each time you fire up the server, you will need to run the migrations script.
@addohm
@addohm Жыл бұрын
Why would you architect anlamp server with your db inside of yhe container rather than outside - with this method you're using writing start data back into the db every restart? It seems like simply storing the actual db file outside the docker container would be better.
@mertcaldag7589
@mertcaldag7589 2 жыл бұрын
Hello, thank you for the video. After I changed image value of www to php:8.1.1-apache and execute docker-compose up, I get the same error "connection refused". Any recommendations?
@codeadamca
@codeadamca 2 жыл бұрын
I would need to see your docker-compose.yml to know for sure. You can view mine from here: github.com/codeadamca/php-docker Try using my file and see if that fixes it. If it does, look for the type in yours.
@davidlepold
@davidlepold Жыл бұрын
I s there such a video with Nginx, fpm-php, sql ...?
@krstech1269
@krstech1269 Жыл бұрын
thank you...
@rajarajan8869
@rajarajan8869 4 ай бұрын
How to php.ini file update in the local machine and how it is mount
2 жыл бұрын
I tried connecting to the database in three different ways: new mysqli, mysqli_connect and new PDO, and all ways didn't work for me. It's very frustrating. 🤥🤥
@mertcaldag7589
@mertcaldag7589 2 жыл бұрын
Same for me.
@codeadamca
@codeadamca 2 жыл бұрын
A few others have had a similar issue. But I can't duplicate it.
@emreekmekcioglu3057
@emreekmekcioglu3057 Жыл бұрын
I have also same problem and tried all of them everytime it throw an exception , could find drive for pdo or mysqli. Did anyone find a soluyion?
@c3cris2
@c3cris2 Жыл бұрын
Amazing video, but 720p in 2022? Squinted the whole video to read the text.
@berndseifert6966
@berndseifert6966 2 жыл бұрын
Thank you for this video. I had the same problem the mysqli_connect error disappeared not. My solution is a combination between your video and the video of arthur man Part 8
@berndseifert6966
@berndseifert6966 2 жыл бұрын
If somebody is interested in my Docker File please write. 😉
@zygmacode
@zygmacode 2 жыл бұрын
@@berndseifert6966 Hello, I'm trying to solve it, I like the base of this tutorial, but I can't find the error, could you show me your docker-compose?
@codeadamca
@codeadamca 2 жыл бұрын
Thanks for adding this! Can you add a link to this video? I think others have had the same issue.
@cellarer6011
@cellarer6011 2 жыл бұрын
Hello, when creating the database i'm getting an error saying no privileges!
@codeadamca
@codeadamca 2 жыл бұрын
I would have to see your docker-compose.yml to know for sure. But I would guess you need to make sure your mysql:latest image (named db) is referenced from your phpmyadmin/phpmyadmin image properly (depends_on: - db and - PMA_HOST=db). If you want, a copy of my files are available here: github.com/codeadamca/php-docker
@sams1669
@sams1669 Жыл бұрын
I tried to migrate my existing Laravel application that used xamp to docker. How do I run the migrations that I had in my application to the new lam_docker db ? if that makes sense ?
@sams1669
@sams1669 Жыл бұрын
When I run 'php artisan migrate' , in the terminal, I get this error: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for mysql failed: nodename nor servname provided, or not known (SQL: select * from information_schema.tables where table_schema = lamp_docker and table_name = migrations and table_type = 'BASE TABLE')
@codeadamca
@codeadamca Жыл бұрын
It's a hard one to debug when I can't see it. But it sounds like the PHP server is not able to connect to the MySQ server. In this video we use separate servers for PHP, MySQ
@ashique12009
@ashique12009 Жыл бұрын
From my side still mysqli_connect is undefined where my image is this: image: php:8.1.1-apache
@SacrumImperiumRomanum517
@SacrumImperiumRomanum517 Жыл бұрын
same
@codeadamca
@codeadamca Жыл бұрын
You may have to enable php_mysqli. Check out this StackOverflow question: stackoverflow.com/questions/46879196/mysqli-not-found-dockerized-php
@b4rt1j1
@b4rt1j1 2 жыл бұрын
Sir, would you please help me, phpmyadmin throwing connection refused every time i provide username and password
@codeadamca
@codeadamca 2 жыл бұрын
Make sure you are using the service name from your docker-compose.yml file as the host in your PHP MySQL connection. In my example, the host should be "db". And make sure the username, password, and database name in your PHP MySQL connection are the same as your MySQL environment variables defined in the docker-compose.yml file. In my example they are lamp_demo, password, and lamp_demo. Hope that helps!
@codeadamca
@codeadamca 2 жыл бұрын
Also make sure the environment variables in the MySQL portion of the docker-compose.yml match the PHPMyAdmin environment variables, also in the docker-compose.yml file. You could also try using some different ports in case your computer is already using one of the specified ports.
@b4rt1j1
@b4rt1j1 2 жыл бұрын
Finally checked some other video and it magically worked, now I'm wondering how to configure apache so the server goes to the public folder where is the entry point index.php I've tried using volumes for that, but failed because when making PROJECT_ROOT constant - my project name is replaced by var/www/html Would you have any suggestions sir?
@codeadamca
@codeadamca 2 жыл бұрын
I believe I found the same question on Stack Overflow, maybe this will help: stackoverflow.com/questions/51393494/how-to-change-the-document-root-in-php7-1-apache-from-docker-compose-yml
@b4rt1j1
@b4rt1j1 2 жыл бұрын
@@codeadamca Thanks!!
@drastically_bad
@drastically_bad Жыл бұрын
it's getting to my nerves plz help me out with this error
@codeadamca
@codeadamca Жыл бұрын
What is the error you are receiving?
@drastically_bad
@drastically_bad Жыл бұрын
@@codeadamca Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in /var/www/html/index.php:3 Stack trace: #0 {main} thrown in /var/www/html/index.php on line
@drastically_bad
@drastically_bad Жыл бұрын
@@codeadamca i am running the same application from your git hub account it giving me error
@CyJobes
@CyJobes 5 ай бұрын
Shouldn't it be setup so you don't have to dump from MySQL, but rather it does it by default. Sure would suck to shutdown and lose all the data. I'm told that doing it the way you are means it is not setup correctly, and you could lose valuable data because of it.
@nothingtoseehere5760
@nothingtoseehere5760 2 жыл бұрын
This is a very long video.
@codeadamca
@codeadamca Жыл бұрын
Sorry... It is right from scratch! :)
@stinkybuttonmasher
@stinkybuttonmasher 2 жыл бұрын
Thank you! Helped me a ton :)
@samuelosoba
@samuelosoba 2 жыл бұрын
Finding it hard getting my version of docker after installation. I use the docker version and docker info, I only see the 19.xx.xx and 20.xx.xx, nothing related to 2, or 3 or 4 anywhere, Any ideas the command you used to obtain the version: 3 you used in the video.? Thanks in anticipation.
@codeadamca
@codeadamca 2 жыл бұрын
The version in the docker-compose.yml is the schema version, not the version of the Docker program. You should be safe using version 3. It's kind of comparable to using VSCode and PHP. VSCode is at version 1.69.1. But I'm using it to write PHP 8. The are unrelated. For more info check out: docs.docker.com/get-started/08_using_compose/
@samuelosoba
@samuelosoba 2 жыл бұрын
@@codeadamca Sorry, I'm using Ubuntu, VSCode and I'm trying to setup php with LAMP.
@samuelosoba
@samuelosoba 2 жыл бұрын
@@codeadamca oh I get it. Thanks
@YCode_
@YCode_ 10 ай бұрын
Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in /var/www/html/index.php:3 Stack trace: #0 {main} thrown in /var/www/html/index.php on line 3 ?
@nickhomboy-ks3it
@nickhomboy-ks3it 10 ай бұрын
Check out my fix I just posted above.
@inteliconn995
@inteliconn995 Жыл бұрын
Adam please - $connect = mysqli_connect - in 2023?
@codeadamca
@codeadamca Жыл бұрын
I tend to use the mysqli series of functions when teaching PHP as they are easier for new programmers to grasp.
Setting up a New Laravel Application and phpMyAdmin using Docker
9:11
Build a Full Stack Web App in PHP and MySQL with Docker from scratch!
26:09
Real Man relocate to Remote Controlled Car 👨🏻➡️🚙🕹️ #builderc
00:24
Random Emoji Beatbox Challenge #beatbox #tiktok
00:47
BeatboxJCOP
Рет қаралды 60 МЛН
СОБАКА ВЕРНУЛА ТАБАЛАПКИ😱#shorts
00:25
INNA SERG
Рет қаралды 3,5 МЛН
Trick-or-Treating in a Rush. Part 2
00:37
Daniel LaBelle
Рет қаралды 43 МЛН
What is a LAMP Stack?
7:55
IBM Technology
Рет қаралды 38 М.
Docker Setup for Local WordPress Development
28:40
Wazoo Web Bytes
Рет қаралды 8 М.
Host Your Own AI Code Assistant with Docker, Ollama and Continue!
17:49
Wolfgang's Channel
Рет қаралды 96 М.
PHP Docker Tutorial - Nginx - PHPFPM VS Apache - Full PHP 8 Tutorial
14:39
Do NOT Learn Kubernetes Without Knowing These Concepts...
13:01
Travis Media
Рет қаралды 318 М.
Vim Tips I Wish I Knew Earlier
23:00
Sebastian Daschner
Рет қаралды 76 М.
How to create a great dev environment with Docker
29:55
Patrick Loeber
Рет қаралды 272 М.
Writing My Own Database From Scratch
42:00
Tony Saro
Рет қаралды 253 М.
Setup a Docker development environment with PHP Apache & MySQL
18:51
Real Man relocate to Remote Controlled Car 👨🏻➡️🚙🕹️ #builderc
00:24