Hosting Your Own Website in 6 Easy Steps
by dhruvarora561 in Circuits > Raspberry Pi
111 Views, 0 Favorites, 0 Comments
Hosting Your Own Website in 6 Easy Steps
We all are familiar with WordPress. It is a free and open source online content management feature, this allows us to host our websites with ease. WordPress is used by 63.5% of all the websites whose content management system we know. This is 43.2% of all websites. It combines simplicity for users and publishers with under-the-hood complexity for developers.
Supplies
Only a handful of things are required to get started
- BrainyPi or Raspberry pi
- Wifi/ ethernet
- Micro SD card loaded with debian
- keyboard
- mouse
- monitor
- A domain name
Start by Installing Docker
1.1 Before installing docker and its dependencies we need to do a few steps
sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release
1.2 Add docker's official GPG keys
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
1.3 Use the following command to set up the repository
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
1.4 Finally, install Docker Engine
sudo apt-get update && sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
1.5 Lastly, run this to test the installation
sudo docker run hello-world
Creating Configuration Files
2.1 Start by creating a directory
mkdir ~/wordpress
2.2 Create nginx.conf file
nano ~/wordpress/nginx-conf/nginx.conf
2.3 Now paste the following in the file and make sure to change "your_domain" and "www.your_domain" to your domain name.
server {
listen 80;
listen [::]:80;
server_name your_domain www.your_domain;
index index.php index.html index.htm;
root /var/www/html;
location ~ /.well-known/acme-challenge {
allow all;
root /var/www/html;
}
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass wordpress:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location ~ /\.ht {
deny all;
}
location = /favicon.ico {
log_not_found off; access_log off;
}
location = /robots.txt {
log_not_found off; access_log off; allow all;
}
location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
log_not_found off;
}
}
2.4 Creating docker-compose
nano docker-compose.yml
2.5 creating env file
nano .env
2.6 paste the following in .env file and remember to change the values
MYSQL_ROOT_PASSWORD=your_root_password
MYSQL_USER=your_wordpress_database_user
MYSQL_PASSWORD=your_wordpress_database_password
2.7 creating docker-compose( remember to change "your-emailaddress@gmail.com" to your email address)
version: '3'
services:
db:
image: mysql:8.0
container_name: db
restart: unless-stopped
env_file: .env
environment:
- MYSQL_DATABASE=wordpress
volumes:
- dbdata:/var/lib/mysql
command: '--default-authentication-plugin=mysql_native_password'
networks:
- app-network
wordpress:
depends_on:
- db
image: wordpress:5.1.1-fpm-alpine
container_name: wordpress
restart: unless-stopped
env_file: .env
environment:
- WORDPRESS_DB_HOST=db:3306
- WORDPRESS_DB_USER=$MYSQL_USER
- WORDPRESS_DB_PASSWORD=$MYSQL_PASSWORD
- WORDPRESS_DB_NAME=wordpress
volumes:
- wordpress:/var/www/html
networks:
- app-network
webserver:
depends_on:
- wordpress
image: nginx:1.15.12-alpine
container_name: webserver
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- wordpress:/var/www/html
- ./nginx-conf:/etc/nginx/conf.d
- certbot-etc:/etc/letsencrypt
networks:
- app-network
certbot:
depends_on:
- webserver
image: certbot/certbot
container_name: certbot
volumes:
- certbot-etc:/etc/letsencrypt
- wordpress:/var/www/html
command: certonly --webroot --webroot-path=/var/www/html --email your-emailaddress@gmail.com --agree-tos --no-eff-email --force-renewal -d your_domain -d www.your_domain
volumes:
certbot-etc:
wordpress:
dbdata:
networks:
app-network:
driver: bridge
2.8 Finally run
sudo docker-compose up -d
Installing WordPress
3.1 open a browser and type
https://your_domain_name.example
3.2 Follow the on screen instructions to finish the installation.
Installation Screen
4.1 Click on continue
Installation
5.1 Enter the required details
Admin Panel
6.1 This is your admin panel, here you can configure your WordPress site.