The easiest way is to do it using the VirtualHost configuration, if you have control over it.
Tuesday, January 19, 2021
How to Redirect HTTP Traffic to HTTPS in httpd on CentOS
Sunday, January 3, 2021
Force Logout Other User from Linux
First, we need to know the username. This can easily be done using w command
# w
12:34:31 up 36 days, 14:14, 2 users, load average: 0.07, 0.02, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
ironman pts/0 ::1 12:34 2.00s 0.01s 0.01s w
root pts/3 10.29.25.230 12:22 7.00s 0.13s 0.00s bash
Let's say we want to log out ironman from our server. What we have to do is to use a command called pkill against that user.
# pkill -u ironman
12:34:31 up 36 days, 14:14, 2 users, load average: 0.07, 0.02, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/3 10.29.25.230 12:22 7.00s 0.13s 0.00s bash
The ironman user is no longer logged in. Easy peasy.
Thursday, December 24, 2020
Using Volume in Docker to Store Persistent Data
Docker container is not persistent, that means, the data stored in a docker container will be gone if the container is destroyed. One of the way to store persistent data while using docker container, is to use the docker volume feature to store your data.
To use the volume, we need to create the volume first.
$ docker volume create myvolume
We can inspect the volume's detailed information using inspect command. This is how we get to know where exactly in filesystem, that the volume resides. and all other information about the volume.
$ docker volume inspect myvolume
[
{
"CreatedAt": "2020-12-24T09:18:03+08:00",
"Driver": "local",
"Labels": {},
"Mountpoint": "/var/lib/docker/volumes/myvolume/_data",
"Name": "myvolume",
"Options": {},
"Scope": "local"
}
]
To make use of the volume, we will use the --volume flag of the docker run command. For example, we want to create a container from an alpine linux image, run a command in it (in this example, a date command), store the output of the command in a volume, exit, and delete the container after that.
$ docker run --rm --volume=myvolume:/tmp alpine sh -c "date > /tmp/currenttime"
Once the container finished running, we can go to the location of the volume in the filesystem, and we can retrieve the file that is created by the container, even though that container no longer exist.
$ sudo ls /var/lib/docker/volumes/myvolume/_data
currenttime
$ sudo cat /var/lib/docker/volumes/myvolume/_data/currenttime
Thu Dec 24 01:25:34 UTC 2020
So this is how my friend, one of the way to store persistent data generated using docker container.
Wednesday, December 23, 2020
Installing Wordpress using Podman
Podman is a daemonless container engine to manage OCI containers. To run a set of containers for wordpress installation, below are the steps. To install podman in centos 8, you can refer here.
First you need to create a pod, so that the containers can talk to each other easily within the pod. Expose port 8080 for the pod to reach port 80 in the pod
# podman pod create --name mywordpress --publish 8080:80
Wordpress consists of 2 components, a wordpress front end and a database backend. We will create the backend first, using mysql image from dockerhub. Make sure to include the newly created container into our pod.
# podman run --detach --pod mywordpress \
-e MYSQL_ROOT_PASSWORD=1234 \
-e MYSQL_DATABASE=mywpdb \
-e MYSQL_USER=mywpuser \
-e MYSQL_PASSWORD=1234 \
--name mywpdb docker.io/mysql
We will then proceed to create a wordpress container. We will use 127.0.0.1 (localhost) as reference to our mysql container, because both containers are in the same pod.
# podman -run --detach --pod mywordpress \
-e WORDPRESS_DB_HOST=127.0.0.1 \
-e WORDPRESS_DB_NAME=mywpdb
-e WORDPRESS_DB_USER=mywpuser \
-e WORDPRESS_DB_PASWORD=1234 \
--name mywp docker.io/wordpress
Open a web browser, and browse to localhost:8080 (or <ip address>:8080), to get the wordpress installer wizard. Follow through the wizard to continue the wordpress installation.
Tuesday, December 22, 2020
Set Bitnami Wordpress Application to Start on Boot on Ubuntu 20.04
To set a bitnami wordpress application to start on boot, you just need to make sure that systemctl can use the ctlscript. To do that:
1. Locate the installation directory of your bitnami wordpress. If you are following the default setting, the location should be in /opt
2. Locate the ctlscript.sh file, which is the script to start, stop and restart bitnami-application.
$ sudo find / -iname "ctlscript.sh" -type f
/opt/bitnami-wordpress-5.6-0/ctlscript.sh
3. Copy the script to /etc/init.d, and rename it to bitnami-wordpress
$ sudo cp /opt/bitnami-wordpress-5.6-0/ctlscript.sh /etc/init.t/bitnami-wordpress
4. Edit the script, and add "INIT INFO" settings below #!/bin/sh to ensure systemd can understand the script
#!/bin/sh
### BEGIN INIT INFO
# Provides: bitnami-wordpress
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable services provided by daemon.
### END INIT INFO