Seems like this tutorial for basic Apache with php-fpm which I followed works fine.
I’m having some hard time on how I can build same using docker container running with basic wordpress, lots of tags seems to be confusing on which one to use. I already tried downloading docker images like wordpress:6.3.1-php8.2-apache but still no idea on how to link it on a separate running container wordpress:6.3.1-php8.2-fpm
2
Answers
It sounds like you’re trying to set up a Docker environment with WordPress using Apache and php-fpm. Docker Compose can help you manage this by allowing you to define multiple containers and their configurations in a single YAML file. Here’s a basic setup for WordPress with Apache and php-fpm:
Create a Docker Compose file (docker-compose.yml):
In this setup:
db
uses the MySQL 5.7 image and sets up a database for WordPress.wordpress
uses the Apache-based WordPress image, connects to thedatabase, and maps port 8000 on your host to port 80 in the
container.
php-fpm
uses the php-fpm version of the WordPress image. Itdoesn’t expose any ports since Apache will be handling the web
requests.
Create a directory for your WordPress files:
Create a directory named
wp-content
in the same directory as yourdocker-compose.yml
file. This will be used to persistently storeyour WordPress files.
Start the Docker containers:
Run the following command in the directory where your
docker-compose.yml
file is located:docker-compose up -d
This will pull the necessary images and start the containers in the background.
http://localhost:8000. You should see the WordPress setup page.
This setup should give you a working WordPress site with Apache and php-fpm. The
wp-content
directory will be mounted inside both the Apache and php-fpm containers, allowing them to share the same files.Please replace
your_root_password
andyour_db_password
with actual secure passwords. Also, remember to adjust version numbers or image names if they have changedIf you are using Apache with the
mod_php
module, switching tophp-fpm
would require some changes in your server configuration. Here are the steps to switch frommod_php
tophp-fpm
1. Install php-fpm:
Make sure you have php-fpm installed on your system. You can typically install it using your package manager (e.g., apt, yum, etc.):
2. Configure php-fpm
Edit the php-fpm configuration file. The location may vary depending on your system. Common paths include /etc/php/7.4/fpm/php-fpm.conf or /etc/php/7.4/fpm/pool.d/www.conf (replace 7.4 with your PHP version).
Ensure that the listen parameter in the http://www.conf file is set correctly:
3. Configure Apache
Disable the mod_php module and enable the proxy_fcgi module:
Create a new Apache virtual host configuration or edit an existing one to use php-fpm. Here is an example of what it might look like:
Replace your_domain.com and /var/www/html with your actual domain and document root.
4. Restart services
Verify
Check phpinfo() again to ensure that the Server API now shows FPM/FastCGI. You may also want to create a simple PHP file containing to view the details.
Let me know whether you have anu issue.