Setup a Docker development environment with PHP Apache & MySQL

Sdílet
Vložit
  • čas přidán 24. 08. 2024
  • github.com/tru...
    In this video we'll setup a simple PHP, Apache, and MySQL environment. We'll also customize the Dockerfile to connect the mysql environment to your php code and use Adminer to manage the database.
    Setting up a Docker environment is great because it allows you to quickly switch things out as you need them. Switching from Apache to Nginx is easy and it prevents you from cluttering up your local environment.
    Most of the Docker documentation pages don't talk about setting up docker-compose files, the PHP page being a great example. That doesn't mean all the information isn't there though. You just have to know what you're looking for. So we'll start from scratch and work our way up to the environment that we want, starting with just a simple command line php script, then adding apache so we can view the code in the browser. We'll also setup a volume/bind mount to allow editing our code on our local machine to take effect within the Docker container.
    Then finally we'll add MySQL to the mix, add in persistent data storage by setting up a volume for Mysql, then we'll test it all out by creating the table, database, etc.. in Adminer.
    Cloning the source code and running docker-compose up -d should get you a working environment, but it won't get you the database or tables you need. You'll have to adapt the code yourself.
    github.com/tru...

Komentáře • 94

  • @zohaibnawaz7190
    @zohaibnawaz7190 Před 3 lety +6

    I am a beginner in docker. Been searching for two days to setup the port to run my code in browser. Finally found the right video. Big thumbs up. Keep up the good work

  • @zb2747
    @zb2747 Před rokem

    Man thank you! There are so many tutorials out here that try to explain this but imo they are too long with alot of fluff. Here you jump straight to it and provide a good overview of everything without going to much into detail, and show implementation.

  • @MagnoAlbertoAlmeida
    @MagnoAlbertoAlmeida Před 2 lety +2

    The most complete and objective tutorial I found. It was exactly what I was looking for days. Here's a suggestion: It would be a video teaching how to include PHP extensions. Thank you very much!

    • @SeekerLabs
      @SeekerLabs  Před 2 lety

      I would love to get to that! Thank you for the suggestion

  • @julengonijimenez243
    @julengonijimenez243 Před 2 lety

    After 2 hours of desesperation of searching, this video has been the way to the light,. Thank u!

  • @inderpreetsingh6548
    @inderpreetsingh6548 Před 2 lety +1

    Exactly what I was looking for. The great part is that you started with Docker file and followed the instructions from the Dockerhub PHP page, so that the users can also relate to it and eventually build the docker-compose file. Liked and subscribed. Will share in my circle too. Thanks a lot!

  • @andresabello6974
    @andresabello6974 Před 3 lety +6

    The simplest tutorial I found with the right setup. Thank you!

  • @feli-boon
    @feli-boon Před 2 lety

    my finals is now in a safe spot thanks to you 😭🙇‍♀️ thank you!!

  • @beagle3882
    @beagle3882 Před 2 lety

    Best IT tutorial ever watched on CZcams. Keep making them.

  • @IanFarrellCreative
    @IanFarrellCreative Před rokem

    Dude, you just ended about a 5 hour headache for me, going round in circles with tutorials that don't explain what the docker code actually means, or how to actually load anything other than a default nginx page, thank you! I'm going to trawl through your videos in the hopes you have one for Webpack too!

  • @arisemyafrica7623
    @arisemyafrica7623 Před 5 měsíci

    Finally ,after two days tho, Thank you

  • @Philip54320
    @Philip54320 Před 2 lety

    You sir saved my evening. After hours of trying this was exactly the concise example I needed :)
    (as it turns out, there was an prev. unknown bug in my code which made everything weird)

  • @bandantuthuko
    @bandantuthuko Před 2 lety

    Thanks for this awesome tutorial managed to set up my docker apache and php mysql and its working.

  • @tomasmajek7690
    @tomasmajek7690 Před 2 lety

    This is my first ever comment on YT, just to say, thank you

  • @ajit.a1425
    @ajit.a1425 Před 3 lety +4

    how do you persist the data without volume ? . when i try this example . the database get cleared every time i run docker-compose down

  • @dustindaleaquino8422
    @dustindaleaquino8422 Před 2 lety

    great tutorial, I'm totally new to docker and this really helped me a lot.

  • @lukinkoo
    @lukinkoo Před rokem

    Do not forget to add also php.ini and important extensions. For example, you can not debug your code without xdebug extension.

  • @JohnHu1986
    @JohnHu1986 Před 2 lety

    Thanks so much for this video. You just saved my world!!

  • @swharden
    @swharden Před 4 lety +8

    Great video, keep them coming! I think you can replace "$PWD" with %cd% in Windows

  • @PermanaJayanta
    @PermanaJayanta Před 3 lety +1

    I've watched several guides, I see some use ubuntu images? And in this video it doesn't use it. What was the reason?

  • @BrajeshSharma
    @BrajeshSharma Před 3 lety +1

    I have already installed mariadb and phpmyadmin on portainer and both are up and running and working. How do I connect it to php-apache docker?

  • @mileswaring6832
    @mileswaring6832 Před 3 lety +1

    When chaning docker file and building with compose I get the following error. Could anyone help me out?
    Thanks in advance
    Step 2/2 : RUN docker-php-ext-install mysqli
    Invalid signal: SIGWINCH
    Service 'php' failed to build : Build failed

  • @dikshayadav921
    @dikshayadav921 Před 2 lety

    Really impressive.. Great explanation.

  • @virginievillard2230
    @virginievillard2230 Před 2 lety

    Thanks for the tutorial ! Very clear and useful !

  • @MartinBorruel
    @MartinBorruel Před 6 měsíci

    Excellent, I have a server with this configuration except phpmyadmin, but 9nce you restart server data is gone

  • @johnchintall9118
    @johnchintall9118 Před 3 lety +2

    Thanks for this tutorial! How to resolve this issue when logging into adminer:" SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name does not resolve" Any help would be great!

  • @muzamali1879
    @muzamali1879 Před 7 měsíci

    hey buddy you dropped this 👑..... did you make video for other dev enviroment as well ?

    • @SeekerLabs
      @SeekerLabs  Před 7 měsíci

      Not yet, I hope to get around to it soon. Thank you for your kind comment I appreciate it!

  • @aogunnaike
    @aogunnaike Před 2 lety +1

    great tutorial, i keep gettinging server error when trying to connect using PDO

  • @Aryan21able
    @Aryan21able Před rokem

    if I have 3 docker containers i.e apache, php, mysql. how would apache know that I have to go to php conatiner for hosting a index.php file on apache container

  • @MohamadSimo
    @MohamadSimo Před rokem

    Thanks for this amazing explantion, but i have a question inside Dockerfile in cmd line you added index.php what if i had many php pages! what shall i do_

  • @bijianwu5124
    @bijianwu5124 Před rokem

    thanks for the great content

  • @anesthetizedangel4845
    @anesthetizedangel4845 Před 3 lety

    Excellent material. Thank you!

  • @naanunane
    @naanunane Před 3 lety

    Thanks a lot, this was very helpful, lot of info in One go, Amazing

  • @therockingassault
    @therockingassault Před rokem

    Thankyou for your help

  • @seanastro5549
    @seanastro5549 Před 3 lety

    Very very useful. Thanks a lot ! Keep it up.

  • @hugh-martinrouxhughy7419

    Wow this video was great, thank you so much!

  • @re5829
    @re5829 Před 3 lety +1

    one thumbs up from me , thanks ❤️

  • @b4rt1j1
    @b4rt1j1 Před 2 lety

    Hi, Im very beginner to docker, can someone please help me if I have index.php inside some folders like src/public/index.php, Docker says Could not open input file: ./index.php i tried relative path to Dockerfile but didnt work. Thanks for any answers

  • @MrFranciscoooooo
    @MrFranciscoooooo Před 2 lety

    from 7.4 php to a php 7.2 great

  • @BrajeshSharma
    @BrajeshSharma Před 3 lety +1

    Also, can anyone tell me how do I tum multiple php scripts from that src location we setup as per this video? Running like localhost:80/test.php?

  • @danielasema9560
    @danielasema9560 Před 2 lety

    Hey thanks for the tutorial. Im just wondering why my db didnt persist at the end. When I composed down, my db was deleted

  • @user-mfsc-2024
    @user-mfsc-2024 Před 2 lety

    Im new on docker. The docker and its container running in the video looks like not in windows 10 WSL.
    How to run docker container in windows 10 without installation of WSL ?

  • @user-si7ve8yt3v
    @user-si7ve8yt3v Před 2 lety

    I tried on my computer just like what you did , but I got localhost 403 forbidden. Any help?

  • @CartmanMthrFckr
    @CartmanMthrFckr Před 2 lety

    As soon as i change the MYSQL_ROOT_PASSWORD and do a docker compose i can't login with it. I get the msg "Connection refused". But with "example" as password its working. Why is that so? 🤔

  • @moeenakhtarawan
    @moeenakhtarawan Před 4 lety

    It was very useful video, i really liked it.

  • @darius7313
    @darius7313 Před 3 lety

    nice and simple, thanks

  • @AhmedAshrafMo
    @AhmedAshrafMo Před 2 lety

    You helped a lot thanks to you

  • @zarkhakan2340
    @zarkhakan2340 Před 3 lety

    Thank you , it helped me.

  • @PaulAlcabasa
    @PaulAlcabasa Před 3 lety +1

    Hi I was wondering how to connect to remote databases? In my current setup I have different server for my database.

  • @benjamink7311
    @benjamink7311 Před 3 lety +1

    How to configure php.ini

  • @StoryOfTheReality
    @StoryOfTheReality Před 4 lety +1

    the indx.php file not running through localhost, but localhost:8080 routing to adminer. What is the problem for
    me?

    • @stinger1up
      @stinger1up Před 4 lety +1

      Same here. getting
      php_1 | Could not open input file: ./index.php

    • @henryhein
      @henryhein Před 3 lety +1

      @@stinger1up make sure no service is using port 80.

  • @joeys7519
    @joeys7519 Před rokem

    You skipped the part where you added a volume to persist the sqlite db to the yml file

    • @SeekerLabs
      @SeekerLabs  Před rokem

      ahh shoot. Sorry about that. I'll try to get to an update soon.

  • @naufalsyafiqsafikri1453

    thank you for tutorial
    I have question, i use this tutorial to deploy osticket but i got unable to connect mysql, anyone can help me?

  • @cristiandanielherrera4349

    very good!

  • @davidtojalvarez6424
    @davidtojalvarez6424 Před 4 lety +1

    Thank you so much

  • @romualdomariano1457
    @romualdomariano1457 Před rokem

    Still no 8.0 above?

  • @maciejenduro
    @maciejenduro Před 3 lety +1

    Hi :-) Thanks for tutorial. How can I add mod_rewrite?

  • @user-mfsc-2024
    @user-mfsc-2024 Před 2 lety

    isnt the db created in the docker image ?

  • @amrullahdev8895
    @amrullahdev8895 Před 2 lety

    15:04 for u guys who get error where Dockerfile is not read and php exit 0 , u had to do docker-compose build , i solved my problem that way , in my case i use ubuntu 22

  • @sumeeetk
    @sumeeetk Před 3 lety

    Very Helpful

  • @dipenparmar2273
    @dipenparmar2273 Před 3 lety +1

    Great 👍😎

  • @miamoto1412
    @miamoto1412 Před rokem

    hello, i did the exact same set up, connected to Adminer etc, although th econnection to the db is not working, did you have to install any extension off the record ? Much appreciated thanks my friend. Great content btw
    : Fatal error: Uncaught Error: Class 'mysqli' not found

  • @panchox21
    @panchox21 Před 3 lety

    big thank you... question tho. what images can i remove after having everything running to save some space? thanks again

  • @MrTeinnorHD
    @MrTeinnorHD Před 3 lety

    Thank you so much !

  • @abolfazlsafari2002
    @abolfazlsafari2002 Před rokem

    thanks man

  • @mapytekh
    @mapytekh Před 2 lety

    Hi, how to overcome this???
    Forbidden
    You don't have permission to access this resource.
    Apache/2.4.51 (Debian) Server at localhost Port 80
    I am working on ubuntu 20.04LTS Desktop...

  • @philipjfry4465
    @philipjfry4465 Před 3 lety

    I fucking love it man! Thumbs up!

  • @stinger1up
    @stinger1up Před 4 lety +1

    Hello, in the end the Adminer worked, but the index.php did not. The console said php would not load file. Any idea why that would be? I've been over this code a few times and can't figure it out. Thank you for your time!

    • @SeekerLabs
      @SeekerLabs  Před 4 lety

      what's the error message? can you push the code up to a repo? I can't promise I can help but I'm curious to see if I can replicate the problem.

    • @SeekerLabs
      @SeekerLabs  Před 4 lety +1

      also what OS are you on?

    • @stinger1up
      @stinger1up Před 4 lety

      @@SeekerLabs Hello, I'm on Mac OS Catalina. I followed your code exactly but once I deviate to docker compose from just the dockerfile, php gives the following error:
      php_1 | Could not open input file: ./index.php
      studyhall_php_1 exited with code 1

    • @stinger1up
      @stinger1up Před 4 lety +2

      RESOLVED I'm not sure what happened but when I ran "docker images" I saw some older images I had created with another tutorial. I ran "docker rmi [image name]" and removed all the images that I had added and then "docker-compose up" worked for me.
      Thanks so much, this was the best tutorial I found. Simple and showed this nub how to use the docs.

    • @SeekerLabs
      @SeekerLabs  Před 4 lety

      @@stinger1up good job! Yeah those kinds of problems are hard to figure out. Glad you got it

  • @marcarrensalita7404
    @marcarrensalita7404 Před 2 lety

    when ever I'm using command docker-compose down. my database always deleted. how can I retain my database?

    • @SeekerLabs
      @SeekerLabs  Před 2 lety

      Probably need to use volumes/bind mounts. I can't look up examples right now but if you look those up that should hopefully help. Good luck!

    • @marcarrensalita7404
      @marcarrensalita7404 Před 2 lety

      @@SeekerLabs ill try to search for it.. thank you

  • @franciscocaldeira2812
    @franciscocaldeira2812 Před 2 lety

    Paste the command for win

  • @TheSayn006
    @TheSayn006 Před 3 lety

    Ho my god, you are great thx a lot

  • @technomalek297
    @technomalek297 Před 3 lety

    Forbidden
    You don't have permission to access this resource.
    Apache/2.4.38 (Debian) Server at localhost Port 80
    receiving this error. any help?

  • @priyabratrath
    @priyabratrath Před 3 lety

    Awesome...

  • @abdouramanemahamane6887

    thanks :)

  • @brunoa2893
    @brunoa2893 Před 3 lety +2

    You probably aware of it, you might have a battery issue

  • @pepjonak
    @pepjonak Před rokem

    i get forbidden access

    • @momahdy
      @momahdy Před rokem

      I get the same error, did you manage to fix it?

  • @ImDino
    @ImDino Před 2 lety

    dont use stereo mics bro the phasing when using headphones is unbearable, idk what the issue is but at least convert your audio track to mono