Okay, I want to host my own websites and I use WordPress. Now the challenge begins.
1. I want to host multiple websites.
2. I want to use WordPress. Well most of the time.
3. I want the websites to use SSL for free and auto renew certificates.
Solution: Use dockers for Nginx, Lets-encrypt, WordPress and MariaDB. Sounds all difficult but easy in the end.
Here are the steps to create a working environment:
1: Create initial docker setup paths
sudo mkdir /docker
sudo mkdir /docker/proxy
2: Create initial docker network setup. the nginx-proxy setup and the letsencrypt certificate setup.
You will have to do this just once.
sudo docker network create dockerwp
sudo docker run –name nginx-proxy –net dockerwp -p 80:80 -p 443:443 -v /docker/proxy/certs:/etc/nginx/certs -v /etc/nginx/vhost.d -v /usr/share/nginx/html -v /var/run/docker.sock:/tmp/docker.sock:ro –label com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy -d –restart always jwilder/nginx-proxy
sudo docker run –name letsencrypt-nginx-proxy-companion –net dockerwp -v /docker/proxy/certs:/etc/nginx/certs:rw -v /var/run/docker.sock:/var/run/docker.sock:ro –volumes-from nginx-proxy -d –restart always jrcs/letsencrypt-nginx-proxy-companion
3: Setting up WP paths.
sudo mkdir /docker/wordpress
For each site you want to host:
sudo mkdir /docker/wordpress/(your-site-name)
sudo nano /docker/wordpress/(your-site-name)/docker-compose.yml
4: The docker-compose file setup should look like
version: '3.3' services: db: container_name: 'your-site-name-db' image: 'mariadb' volumes: - './data/mysql:/var/lib/mysql' ports: - 18768:3306 environment: MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: your-site-name_db MYSQL_USER: wordpress_user MYSQL_PASSWORD: wordpress_password wordpress: container_name: 'your-site-name-wp' depends_on: - db image: 'wordpress:latest' ports: - '8092:80' environment: WORDPRESS_DB_HOST: 'your-site-name-db:3306' WORDPRESS_DB_USER: wordpress_user WORDPRESS_DB_PASSWORD: wordpress_password WORDPRESS_DB_NAME: your-site-name_db VIRTUAL_HOST: www.your-site-name.nl LETSENCRYPT_HOST: www.your-site-name.nl LETSENCRYPT_EMAIL: admin@your-site-name.nl volumes: - "./wordpress:/var/www/html" - "./plugins:/var/www/html/wp-content/plugins" networks: default: external: name: dockerwp
Change the ports in db and wordpress for every website you host.
In db: -18678:3306 becomes -18679:3306 for the next site.
In wordpress: -8092:80 becomes -8093:80 for the next website
5: Bring up the docker
cd /docker/wordpress/your-site-name
sudo docker-compose -p “your-site-name-WP” up -d
And thats is. Only step 3 till 5 is needed for every site you want to host.
Remarks:
Make sure that your DNS entries are setup at your provider. So you need a A record www pointing to your ip address.
And you have an exemption in your firewall to allow HTTP 80 and HTTPS 443 to your nginx-proxy docker.
Note: 10-06-2022
So it seems when using the WordPress docker there is an issue with MailPoet v3.
The fix to get that plugin to run is:
1. open Portainer and go to your container containing the website.
2. connect to the console
3. run these commands in the console:
apt-get update
apt-get install -y libzip-dev zlib1g-dev
docker-php-ext-install zip mysqli pdo pdo_mysql
a2enmod rewrite
4. Disconnect and restart the container.
And you should be fine 😉