How to setup a local server on Ubuntu

Vishal S
2 min readJan 4, 2024

--

credits:Bing Image Creator from Designer

A simple and quick guide to run a local network server on your Ubuntu PC with an open-source server software.

  1. Select a server software: Each comes with it’s own advantages :)

I have explored two options apache and nginx. Nginx does more with less resources when it comes to heavy load on the server and can handle complex configurations. Apache however is very easy to start with and has multiple modules and extensions to support your requirement. In summary, for a starting a simple server both options are ok. I chose nginx.

2. Getting started: Installations and other requirements

# update the packages
sudo apt-get upgrade

# install nginx
sudo apt-get install nginx

# install net-tools
sudo apt-get install net-tools

# install firewall setup
sudo apt-get install ufw

3. Starting the localhost: First server

# start the server
sudo systemctl start nginx

Start the server and Open the browser and type localhost in the url bar. If the server is running you would see the Nginx welcome message.

nginx server welcome page.

Some useful commands for controlling server behavior.

# check current status of the server
sudo systemctl status nginx

# stop the server
sudo systemctl stop nginx

# reload the server
sudo systemctl reload nginx

# enable server start on boot
sudo systemctl enable nginx

4. Accessing the server from a another computer in local network.

Connect both computers to same WiFi network, you can test this functionality via your phone as well. Now, make following changes to the server PC.

# get the ip address for your PC, it should be something like 192.168.X.X
ifconfig
# edit the nginx config
sudo nano /etc/nginx/nginx.conf

look for the server block in the nginx.conf . If it doesn’t exists add it in the the conf file.

# existing lines
events {
worker_connections 768;
}

# adding server configuration
server {
listen 192.168.X.X:80;
}

Now, reload the server. And type the ip address 192.168.X.X in your phone. You should be able to see the nginx welcome page over your phone

--

--

Vishal S
Vishal S

Written by Vishal S

Data scientist by day, professional curiosity piquer by night.