Setting up a LAMP Stack from Scratch using Docker

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 ก.ย. 2024
  • In this video we setup a LAMP stack using a series of Docker containers. The code in the docker-compose.yml is explained line by line and added on a need to ad basis.
    Full Tutorial: codeadam.ca/le...
    PHP: www.php.net/
    Composer: getcomposer.org/
    Docker: www.docker.com/
    ---
    Website: codeadam.ca/
    Twitter: / codeadamca
    Instagram: / codeadamca
    GitHub: github.com/cod...

ความคิดเห็น • 99

  • @astev52
    @astev52 ปีที่แล้ว +7

    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.

  • @Aryan21able
    @Aryan21able ปีที่แล้ว +7

    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

  • @thanasister
    @thanasister 7 หลายเดือนก่อน +2

    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 4 หลายเดือนก่อน

      Thanks, that's probably why my mailcow didn't work as well. Guess it's time for a newer video

  • @alphamadioubah6169
    @alphamadioubah6169 11 หลายเดือนก่อน +2

    Very good pace, good tone and a true step-by-step guide

  • @alivenumber5
    @alivenumber5 9 หลายเดือนก่อน

    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.

  • @vincentstevenson2200
    @vincentstevenson2200 2 ปีที่แล้ว +3

    I really appreciate your thoroughness on this tutorial. You are a great teacher Adam!

  • @pikadroo
    @pikadroo 8 หลายเดือนก่อน

    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!

  • @MarcMcRae
    @MarcMcRae ปีที่แล้ว

    Brilliant! Video paints a thousand words to actually see the real life process flow. VERY very cool docker stuff & thanks for sharing.

  • @patafrom
    @patafrom 10 หลายเดือนก่อน

    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.

  • @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 :)

  • @shizo_n01z3
    @shizo_n01z3 2 ปีที่แล้ว +1

    Great video, very nice to follow

  • @pw5687
    @pw5687 ปีที่แล้ว +1

    This was a big help, thanks!

  • @alexsilkin5222
    @alexsilkin5222 2 ปีที่แล้ว +1

    Great video and instructions! Thank you for making this.

    • @codeadamca
      @codeadamca  2 ปีที่แล้ว

      You are so welcome!

  • @Happinessisalwaysthere
    @Happinessisalwaysthere ปีที่แล้ว +3

    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

  • @saidbakr
    @saidbakr 2 ปีที่แล้ว +1

    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 ปีที่แล้ว +1

      Great! Docker is awesome!

  • @lalaland1670
    @lalaland1670 ปีที่แล้ว

    Thank you so much for the video. Really helped me get started with Docker.

  • @sparkdogy2k
    @sparkdogy2k 2 ปีที่แล้ว +1

    awesome video man! really helped me with my first time with docker :)

    • @codeadamca
      @codeadamca  2 ปีที่แล้ว

      Glad I could help!

  • @isaacambi1914
    @isaacambi1914 5 หลายเดือนก่อน

    Great content.

  • @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 ปีที่แล้ว +1

      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!

  • @emveeoh
    @emveeoh ปีที่แล้ว +2

    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 ปีที่แล้ว +4

      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

  • @olegfare4625
    @olegfare4625 11 หลายเดือนก่อน

    amazing explanation!

  • @mkannanmsc
    @mkannanmsc ปีที่แล้ว

    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!! :)

  • @stinkybuttonmasher
    @stinkybuttonmasher ปีที่แล้ว

    Thank you! Helped me a ton :)

  • @twodogsandstuff
    @twodogsandstuff 8 หลายเดือนก่อน

    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?

  • @snorky4506
    @snorky4506 2 ปีที่แล้ว +6

    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 ปีที่แล้ว +3

      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.

  • @WilliamKim
    @WilliamKim 10 หลายเดือนก่อน

    Thank you!

  • @ronaldjoytengco7000
    @ronaldjoytengco7000 6 หลายเดือนก่อน

    I had a sqlyog and mysql workbench how can i connect to the database using that software? Thank you

  • @Olliewiener
    @Olliewiener 5 หลายเดือนก่อน

    Is there a way to do it in a single container instead of multiple pls and thanks

  • @queshafiq8952
    @queshafiq8952 10 หลายเดือนก่อน

    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?

  • @mkannanmsc
    @mkannanmsc ปีที่แล้ว

    Very Good Adam.👍 Wondering as per best practices, we won't allow empty passwords to connect mysql

  • @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.

  • @davidlepold
    @davidlepold 10 หลายเดือนก่อน

    I s there such a video with Nginx, fpm-php, sql ...?

  • @Salamaleikum80
    @Salamaleikum80 10 หลายเดือนก่อน

    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?😅

  • @mertcaldag7589
    @mertcaldag7589 2 ปีที่แล้ว +1

    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  ปีที่แล้ว

      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.

  • @rajarajan8869
    @rajarajan8869 2 หลายเดือนก่อน

    How to php.ini file update in the local machine and how it is mount

  • @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.

  • @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  ปีที่แล้ว

      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/

  •  2 ปีที่แล้ว +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 ปีที่แล้ว +3

      Same for me.

    • @codeadamca
      @codeadamca  ปีที่แล้ว

      A few others have had a similar issue. But I can't duplicate it.

    • @emreekmekcioglu3057
      @emreekmekcioglu3057 ปีที่แล้ว +2

      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?

  • @krstech1269
    @krstech1269 ปีที่แล้ว

    thank you...

  • @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 ปีที่แล้ว +1

      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  ปีที่แล้ว

      Thanks for adding this! Can you add a link to this video? I think others have had the same issue.

  • @cellarer6011
    @cellarer6011 ปีที่แล้ว

    Hello, when creating the database i'm getting an error saying no privileges!

    • @codeadamca
      @codeadamca  ปีที่แล้ว

      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

  • @c3cris2
    @c3cris2 ปีที่แล้ว

    Amazing video, but 720p in 2022? Squinted the whole video to read the text.

  • @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 ปีที่แล้ว +1

      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 ปีที่แล้ว +1

      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 ปีที่แล้ว +1

      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 3 หลายเดือนก่อน

    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 ปีที่แล้ว

    This is a very long video.

    • @codeadamca
      @codeadamca  ปีที่แล้ว +1

      Sorry... It is right from scratch! :)

  • @YCode_
    @YCode_ 8 หลายเดือนก่อน

    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 8 หลายเดือนก่อน

      Check out my fix I just posted above.

  • @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 ปีที่แล้ว +1

      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

  • @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.