# How to set up a personal blog

### Introdcution

In order to set up a personal blog, we need the following items:

• A domain
• A place to host the website
• A web application

We can buy a domain at a domain provider such as bluehost. For exmaple, the domain name of this blog compassinbabel.org is bought at bluehost. There are many cloud service providers that provide web hosting service. For example, this blog is currently hosted in digitalocean. In digitalocean, a host is also called a droplet so in this post host and droplet are interchangealbe.

In general, there are two main steps when we set up a personal blog. They will be discussed in the below sections.

#### Step 1: Config DNS

The objective of configuring DNS is to connect the domain name to the host(droplet). As the below diagram illustrates, there are two parts of the configuration. First, we need to let the domain provider know the name server provided by the hosting service, which knows where to find the host. This part is configured in the domain provider account. Second, we need to let the hosting service know the host wants to handle requests associated with the domain name. This configuration is the ultimate domain-to-host mapping we want to establish (solid orange line in the diagram).

It takes up to 72 hours for the DNS configuration update to propagate through the internet. This progress can be tracked in websites such as https://www.whatsmydns.net/.

To verify that the DNS configuration is updated, we can run whois <domain-name> on the local machine. For example, if we run whois compassinbabel.org, we get the folloing outputs

Registrant Country: US
Name Server: NS1.DIGITALOCEAN.COM
Name Server: NS2.DIGITALOCEAN.COM
Name Server: NS3.DIGITALOCEAN.COM

##### Troubleshooting

It can happen that nslookup works but if we ping the domain name we get the unknown host error. To solve this issue, we need to refresh the local DNS cache. For example, on Mac, we can run the following command to refresn the DNS cache

sudo killall -HUP mDNSResponder


#### Step 2: Deploy Flask Application

Here is a tutorial about the flask deployment. Most of the instruction are still valid.

Two components are important in the whole setup:

1. Apache server

Both of them need appropriate access permision. This is important becuase when we log into the droplet account we are root usere and the files created require root permission by defaut. We need to grant permission to files and folders needed by apache server and Flask application.

The most important part in the deployment process is the apache server configuration. We need to connect Flask application to the Apache framework. By Flask application, we mean the main python script that is used to start the Flask application instance. This script usually contains the following line:

app = Flask(__name__)


On the Apache configuration side, we can registere a web application in /etc/apache2/sites-available/. It's a good practice to make the name consistent, therefore, for this blog, we have the following configuration file:

/etc/apache2/sites-available/compassinbabel.conf


Here is te content of the config file:

<VirtualHost *:80>
ServerName compassinbabel.org
WSGIProcessGroup compassinbabel

<Directory /var/www/>
AllowOverride All
Require all granted
</Directory>

Require all granted
</Directory>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log LogLevel warn CustomLog${APACHE_LOG_DIR}/access.log combined

WSGIProcessGroup compassinbabel
WSGIApplicationGroup %{GLOBAL}
Require all granted
</Directory>
</VirtualHost>


Note on /var/www/: If we want to host multiple websites on the same server, we could have the following configuration

<Directory /var/www/<your-website-name>/html>
AllowOverride All
Require all granted
</Directory>


And we need to have an index.html file in the folder /var/www/<your-website-name>/html to make it work. Remember to execute command a2ensite /etc/apache2/sites-available/<config file> as well.

As we can see here, this configuration file makes the flask application known to the Apache server. We can also test if the syntax in the configuration is corret by using the following command:

sudo apache2ctl configtest


The final step is to restart the apache with the following command:

sudo service apache2 restart


By default, logs are saves in

/var/log/apache2/error.log
/var/log/apache2/access.log


The log folder can be configured in the web application configuration file (for example /etc/apache2/sites-available/compassinbabel.conf) and it depends on the environment variable APACHE_LOG_DIR, which is defined in:

/etc/apache2/envvars/APACHE_LOG_DIR


----- END -----

Welcome to join reddit self-learning community.

Want some fun stuff?