How would I set up a LAMP stack?

I have a feeling I’m just thinking about this the wrong way. I wanted to set up a toolbox container for testing web dev stuff. But all the tutorials I’ve found online and everything I’ve ever known to do in the past is to run systemctl enable httpd after installing to run the web server. But doing that in the toolbox doesn’t work, becuase I just get an error message about the system not having been booted using systemd.

I have a feeling this is just me adjusting to the container based aspect of Silverblue, and not realizing that there’s an even easier way to do it. Unfortunately my searching online up to this point has not been very helpful. What’s the best way to get this set up, or am I just going about this the completely wrong way to start with?

In general, your best bet for anything like this is going to be by using containers via podman, which is a rootless container runner that’s mostly CLI-compatible with Docker. Unfortunately, when I went to do some online hunting to find some guides, I realized pretty much all of the good ones docker-compose, which…is not supported by podman.

Some options you might try:

  • podman does support containers that have their own systemd instance, maybe look into setting up a standard Fedora container that does this and then put everything inside?
  • You could maybe check out running the services with supervisord instead of systemd.
  • If you don’t mind some learning, arguably the best solution would just to be to check out the guides that use docker-compose and manually convert it to the podman CLI instead. (This may actually be easier than the other two options.)
2 Likes

Just as @refi64 mentioned, using containers is the way to go when using silverblue. I don’t quite use php myself, but when with I do webdev on silverblue, I mount the code on the podman container and have it run my webserver of choice. I can then program and get instant feedback.
I suppose you can do the same with php.
If there is a specific tool you wish to use on top of the lamp stack, list it and I can try and use that myself, then guide you through it if I manage to get it running.

If you do wish to stick with toolbox, running httpd manually should also do the trick. Keep one terminal session with httpd running and then you can attach to toolbox multiple times to do whatever.

Learning is always good. I had experience with self hosting some things with docker-compose, and I know docker-compose files are mostly just docker commands written out in yaml form, so it shouldn’t be too high of a learning curve. I must admit I was surprised that there wasn’t a more clear-cut answer for something as common as a LAMP stack. But I suppose this type of thing is just the nature of containers and I just need to get with the program. Thanks for your help!

2 Likes

Part of the reason is probably since the main adopters of containers thus far have been organizations using microservice-style deployments, which usually follow a much different architecture than traditional stacks.

One of the community members has developed a tool that understands docker-compose YAML files and does the same business via podman - https://github.com/muayyad-alsadi/podman-compose

I actually was talking to the podman folks about this yesterday and they are backing the use of Kubernetes YAML files as the replacement for docker-compose. See podman-generate-kube and podman-play-kube for details.

Thanks for showing me that! I’ll definitely keep an eye out if I need it in the future. I was able to pull a php-apache image last night and get it running with a local folder connected to its var/www/html folder. The only other part of the LAMP stack I’m missing at this point is the database, so since it’s just those two containers I’ll probably just write some scripts to manage them for now.

In case this helps anyone else, I got the containers up and running and started working through this tutorial, with a few differences here and there. I wrote a script to automatically pull down images I prepared with buildah and uploaded to quay.io, set up a pod, and start all the containers with mounted persistent volumes and such. I put all this in a GitHub repository if it would be helpful to anyone else. In the interest of this being a potentially helpful example, if there are any best practices regarding podman or containers I’m violating here, feel free to let me know, I’d be happy to do whatever I can to fix those.

EDIT: Immediately I already see that I have absolute paths specific to my folder setup in the init script! I’ll have to figure a way around that. Perhaps something to do with $PWD since the volumes flag does not work with ./ notation.

You’d do:

dnf install mariadb mariadb-server httpd mod_ssl php php-common

And then you would install each module you need.

That would work in a standard Fedora installation, but it won’t work that way in the default toolbox containers on Silverblue, as those don’t come with systemd by default so you can’t start the httpd service. You would have to either do what I did and combine different containers together or get a Fedora container with systemd instead and then run the commands and start the services. I ended up managing to combine nginx, php-fpm, and mariadb containers in a pod and get that working. I did have a working configuration with php-apache and mariadb before hand though. Even if its not the most optimal way to do it, I did get plenty of experience with OCI containers that I didn’t have before.

If that doesn’t work, I have no idea what has gone wrong with your system. I
have no idea how you even booted without systemd, unless there’s another init
system present. Regardless, there are other ways to start Apache’s httpd than
through the systemd unit.

I’m not sure how this is really related to booting… The toolbox relies on the host systemd instance, so any units you install inside can’t be used from the host.

Out of curiosity, would you be able to share this online, e.g. through a gist? I suspect this type of question is going to be asked pretty often!

This is actually really easy.

There is an official Docker image for MariaDB that you should use for your DB: https://hub.docker.com/_/mariadb

Then all you need is Apache + PHP. You could create your own Dockerfile, but you could also look at pre-built options. For example:

The official PHP one uses mod_php which is not the way to go in production if you want performance. That’s where running PHP in FPM comes in. The same way Nginx does it, also making Apache HTTPD just as fast running PHP as Nginx :wink:

You could combine these two (mariadb & apache+php) in a compose file for easy starting and stopping…