skip to Main Content

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


  1. 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):

        version: '3.8'
    services:
      db:
        image: mysql:5.7
        volumes:
          - db_data:/var/lib/mysql
        environment:
          MYSQL_ROOT_PASSWORD: your_root_password
          MYSQL_DATABASE: wordpress
          MYSQL_USER: wordpress
          MYSQL_PASSWORD: your_db_password
    
      wordpress:
        image: wordpress:6.3.1-php8.2-apache
        depends_on:
          - db
        ports:
          - "8000:80"
        volumes:
          - ./wp-content:/var/www/html/wp-content
        environment:
          WORDPRESS_DB_HOST: db
          WORDPRESS_DB_USER: wordpress
          WORDPRESS_DB_PASSWORD: your_db_password
    
      php-fpm:
        image: wordpress:6.3.1-php8.2-fpm
        volumes:
          - ./wp-content:/var/www/html/wp-content
        depends_on:
          - db
    

    In this setup:

    1. db uses the MySQL 5.7 image and sets up a database for WordPress.
    2. wordpress uses the Apache-based WordPress image, connects to the
      database, and maps port 8000 on your host to port 80 in the
      container.
    3. php-fpm uses the php-fpm version of the WordPress image. It
      doesn’t expose any ports since Apache will be handling the web
      requests.

    Create a directory for your WordPress files:

    1. Create a directory named wp-content in the same directory as your
      docker-compose.yml file. This will be used to persistently store
      your WordPress files.

    2. 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.

    1. Access your WordPress site: Open your web browser and go to
      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 and your_db_password with actual secure passwords. Also, remember to adjust version numbers or image names if they have changed

    Login or Signup to reply.
  2. If you are using Apache with the mod_php module, switching to php-fpm would require some changes in your server configuration. Here are the steps to switch from mod_php to php-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.):

    sudo apt-get install php-fpm
    

    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:

    listen = /var/run/php/php7.4-fpm.sock
    
    listen.owner = www-data
    listen.group = www-data
    

    3. Configure Apache
    Disable the mod_php module and enable the proxy_fcgi module:

    sudo a2dismod php7.4
    sudo a2enmod proxy_fcgi
    

    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:

    <VirtualHost *:80>
        ServerName your_domain.com
    
        DocumentRoot /var/www/html
        
        <Directory /var/www/html>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Require all granted
        </Directory>
    
        ProxyPassMatch ^/(.*.php(/.*)?)$ unix:/var/run/php/php7.4-fpm.sock|fcgi://localhost/var/www/html/
    
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>
    

    Replace your_domain.com and /var/www/html with your actual domain and document root.

    4. Restart services

    sudo systemctl restart apache2
    sudo systemctl restart php7.4-fpm
    

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search