Re: NGINX/PHP-FPM (with Docker)

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Keith Smith via PLUG-discuss
Date:  
To: Snyder, Alexander J
CC: techlists, PLUG Distro
Subject: Re: NGINX/PHP-FPM (with Docker)
On 2024-12-19 13:34, Snyder, Alexander J wrote:
> Keith Smith & PLUG (et. al.) --
>
> I'm sorry it took me so long, but y'know -- end of year madness.
>


Good to hear from you!


> Anyhoo -- I had some time free from work and I whipped up a nginx
> webserver with PHP-FPM.
>
> I have never worked with NGINX and I have never worked with PHP-FPM.
> It took a solid 5 minutes of Docker Compose 'ing to get it working.
>
> Here is the Docker Compose file I used:
> https://pastebin.com/KdPvG6wD
> Here is the NGINX Conf file I used: https://pastebin.com/sC8VkBVQ
> Here is the INDEX.php file I used: https://pastebin.com/y5dEjKNS
>
> This is the directory structure of my Docker Compose folder:
>
> --> tree /opt/apps/websitetest/
> /opt/apps/websitetest/
> ├── data
> │ ├── html
> │ │ └── index.php
> │ └── nginx.conf
> └── websitetest-compose.yml
>
> 2 directories, 3 files
>
> ===================
>
> Okay, how here's how you get going on this:
>
> Step 1: Add the Docker CE repo to your computer:
> https://download.docker.com/linux/
> .... I assume you know how to do that part. Its really simple on
> RHEL, I can't speak for Ubuntu or others.
>
> Step 2: Add the packages:
>
>     * containerd.io [1]
>     * docker-buildx-plugin
>     * docker-ce
>     * docker-ce-cli
>     * docker-compose-plugin
>     * python3-docker

>
> The most important being the "docker-compose-plugin"
>
> Once docker is running and you can successfully do their "Hello World"
> test: "docker run --rm docker.io/library/hello-world [2]" (without
> double-quotes)
>
> You should get a message that your docker is installed correctly.
>
> Next, create a common proxy network for these services to communicate
> in: "docker network create website" (_you can name your network
> whatever you want, for simplicity I chose "website", and my files
> reflect that same name_).
>
> This proxy network is reflected in my files, so make the appropriate
> changes if you name it something else:
>
> ----------------------------
> networks:
>   website:
>     external: true

>
> networks:
> - website
> ----------------------------
>
> With the Nginx Conf file and PHP files both staged in the proper
> directories (_remember to adjust the path to reflect on your system
> properly_)
>
> I am in the working directory that contains my COMPOSE file:
> I ran this command: "docker compose -f websitetest-compose.yml up -d"
> (_without double quotes_)
>
> Then, I navigated to my docker host, and put in the host port (3005)
> that I mapped to the container port of 80, and I see this:
> https://imgur.com/a/Vuajx5z
>
> I'm happy to help anyone trying to get this same proof-of-concept
> working for them, but anything beyond a simple POC and I would say I'm
> probably not the guy.
>
> This was just meant to show how quick and easy Docker makes
> development.


Very interesting. While I took a lot of time to get PHP-FPM to work I
learned a lot.

That begs the question was it worth it? I think it was worth the time.
I improved a few skills and learned how to configure PHP-FPM running on
Apache. This process helped me understand modern day LAMP hosting. The
last time I configure a web server was before CentOS made it's exit.

Configuring a LAMP server under CentOS was considerably easier. As I
recall under CentOS it was a 3 step process. 1) create a SSH user,
Create a docroot off the home directory, And create the Apache virtual
host configuration. In this case the SSH user is also the docroot owner.
This makes it easy to upload/download/and edit files as that user.

Today things are configure differently and that is the reason for
PHP-FPM.

Today the default Docroot owner is www-data. That means one cannot
upload/download/or edit files owned by www-data. PHP-FPM makes it
possible to create an SSH user who is the docroot owner. This makes it
possible to use Visual Studio Code for remote editing...etc

I'm of the opinion that all PHP developers should have the skills to
build a local development environment using not-routable IP's and
non-routable domains.

I've spent a lot of time on the Ubuntu command line and doing so has
refreshed some very stale skills and has helped me learn some new ones.

Thank you Alexander, and everyone else, for taking this journey.

Keith

>
> Let me know how I can help!
>
> --
>
> Thanks,
> Alex.
>
>
>
> Links:
> ------
> [1] http://containerd.io
> [2] http://docker.io/library/hello-world

---------------------------------------------------
PLUG-discuss mailing list:
To subscribe, unsubscribe, or to change your mail settings:
https://lists.phxlinux.org/mailman/listinfo/plug-discuss