A B C D E F G H I J K L M N O P Q R S T U V W X Z

Password protect a subsite in a WordPress network with .htaccess

Password protect a subsite in a WordPress network with .htaccess

A wordpress network / multisite setup uses virtual directories.

When you have a wordpress network setup on www.yourdomain.com, you can have multiple blogs with only one WordPress installation, for example:

www.yourdomain.com
www.yourdomain.com/johndoe
www.yourdomain.com/janedoe

Suppose you want to password protect only one subsite e.g. ‘janedoe’, you can’t just create a ‘janedoe’ folder on your webserver with a particular .htaccess in it.

You need to create a secured environment for the virtual folder in your main .htaccess (where all other WordPress rules reside) using the following code:

1
2
3
4
5
6
7
8
9
SetEnvIfNoCase Request_URI "^/janedoe/" SECURED
AuthType Basic
AuthName "restricted area"
AuthUserFile /home/mydomain/.htpasswd
require valid-user
Satisfy any
Order allow,deny
Allow from all
Deny from env=SECURED

From: https://nex.be/password-protect-subsite-wordpress-network-htaccess/

See also: https://wordpress.stackexchange.com/questions/176128/password-protect-a-single-site-on-network

PHP

PHP is an open source script language that is often used to communicate with databases and can be easily integrated into html.

https://www.php.net/manual/de/intro-whatis.php

Dockerizing PHP

PHP can be dockerized. This means creating and running a container that contains php scripts and serves them using a webserver like apache. This can be useful when php is used as an API solution.

Dockerfile

To use php we need to create a Dockerfile which can then be used to start a single container, or included in a docker-compose setup.

1  FROM php:7.4-apache
2  COPY src/ /var/www/html
3  RUN docker-php-ext-install mysqli pdo pdo_mysql

How does it work?

Line 1: Use the official php image from the Dockerhub as base image. By specifying 7.4-apache we choose an image that includes an apache-server to serve the scripts.

Line 2: Copy any php files from a directory (in this case it is called „src“) to the folder „var/www/html“ in the container, so it can be served.

Line 3: Install php extensions if necessary, e.g. mysqli or pdo

docker-compose

With the Dockerfile set up we can create a service in a docker-compose file:

services:
  php:
    build: ./php
    container_name: php
    volumes:
      - ./php/src:/var/www/html
    ports:
      - "7000:8080"

How does it work?

build signifies the context that should be used to create the container. In this case, everything related to the container, including the Dockerfile is located in a folder called „php“, so it’s location is given here.

container_name: php gives the container a name under which it can be accessed once created

volumes mounts the local folder „php/src“ that includes all the php scripts to the folder „var/html/www“ in the container. That way, the container and the local folder will be synchronized and scripts can be edited on the local machine

ports php is running on port 8080 in the docker container. You can forward it to any unused port on a local machine by changing the first port number.

Portainer

Installation

Create the volume that Portainer Server will use to store its database:
docker volume create portainer_data

Download and install the Portainer Server container:
docker run -d -p 8000:8000 -p 9443:9443 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:latest
– Run the container in daemon mode (-d)
– Expose the ports 8000 and 9443 to the public since they are needed to manage the Portainer Server (-p 8000:8000 -p 9443:9443)
– Name the container portainer (--name portainer)
– Set the restart policy to always so the container will start automatically when docker is started (--restart=always)
– Grant the container read-write access to the docker socket (this will enable the container to manage docker containers) (-v /var/run/docker.sock:/var/run/docker.sock)
– Mount the previously created volume portainer_data as /data inside the container (-v portainer_data:/data)
– Use the latest version of the image portainer/portainer-ce (Portainer Community Edition – for Business Edition or Enterprise Edition use portainer/portainer-ee) (portainer/portainer-ce:latest)

Logging in:
https://your-fancy-hostname:9443/
– Open this link inside of a modern browser after you have replaced your-fancy-hostname with the hostname or ip address of the host machine.