Linode
Plan
- Introduction to Linode
- Create a Virtual Private Server (VPS) on Linode.
- Set up Nginx web server on droplet.
- Static web pages.
- Some linux commands.
- Set up Python on the machine.
- Close the VPS.
What is Linode?
Register on Linode
- Register on Linode.
Create Linode
- Region - does not really matter for us.
- OS: Ubuntu 24.04 LTS
- Shared CPU Nanode 1Gb - costs $5/month or $0.0075 / hour. 1Gb RAM 25 GB storage.
LISH console
-
User
root -
Look around the disk
-
ls -
pwd -
uptime -
df -h -
top -
htop -
I use
vimto edit files, but if you are not familiar with it then we should start with something closer to what you might be familiar with. -
Use
nanoto edit files.
SSH from Windows
Create ssh keypair
Generate ssh keypair by running git-keygen and accepting all the defaults.
ssh-keygen
ls -l ~/.ssh
Install nginx
-
Visit:
http://IP(replace the IP with the real IP of your machine) -
The browser will report that it cannot find the site
-
Between the command check the used disk size using
df -hto see how much disk space is used by the Operating System and the packages.
apt updateapt upgradeapt install nginxreboot
-
Visit:
http://IPagain (make sure it useshttpand nothttps) -
This file
/etc/nginx/sites-enabled/defaultis the configuration file of Nginx. -
Edit
/var/www/html/index.nginx-debian.htmland see the changes are reflected on the web page. -
Visit
http://IP/hello.htmland observe that the server returns a 404 page. -
Create the file
/var/www/html/404.html -
Edit the
/etc/nginx/sites-enabled/defaultfile, adderror_page 404 /404.html; -
Reload the web server:
systemctl reload nginx -
Visit
http://IP/hello.htmlagain and observe that the server returns our own 404 page. -
Create the file,
/var/www/html/hello.htmland see that it can be loaded via the browser.
Install Python
- Python3 is already installed, so we only need
virtualenv
apt install virtualenv
TODO: Convert the project to use uv and then Install uv
Create user
adduser --gecos '' --disabled-password dev
Add the application source code
Switch to the user:
su - dev
By cloning:
git clone https://github.com/szabgab/python-flask-demo.git
cd python-flask-demo
virtualenv venv
By upload using scp, run the command on your desktop:
scp -r . root@IP:
This is just an example, you need to zip the files on your computer, scp the zip file and unzip in user dev.
Install the Python dependencies
source venv/bin/activate
pip install -r requirements.txt
Try the development flask server
flask run --port 5000 --host 0.0.0.0
Access http://IP:5000/
Install and configure uwsgi
apt install uwsgi
apt install uwsgi-plugin-python3
ln -s /home/dev/python-flask-demo/config/demo-uwsgi.ini /etc/uwsgi/apps-enabled/demo-uwsgi.ini
service uwsgi restart
If there is a problem you might find help by looking at the log file:
/var/log/uwsgi/app/demo-uwsgi.log
I got the following error "Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding"
I had make the home directory of the dev user to be world readable, that solved the problem:
chmod +r /home/dev/
Configure nginx
- As user
root:
ls -l /etc/nginx/sites-enabled/
rm /etc/nginx/sites-enabled/default
ln -s /home/dev/python-flask-demo/config/demo-nginx.conf /etc/nginx/sites-enabled/demo-nginx.conf
Reload the nginx configuration
systemctl reload nginx
If there are problems look at
/var/log/nginx/python-flask-demo.error.log
Linode services
- Add external disk
- Add s3 buckets
- Upgrade the server to more memory and CPU