Hopp til innhold

Web Server Installation

Skip to content

This is a machine-translated text that may contain errors!

Installing a Web Server

🚧🚧 Work in progress! 🚧🚧

Dubstep Meme

  • Commands: sudo, apt, cd, nano
  • Software: nginx, apache2

Process for Installation

Before we can install the software, we need to update the APT(itude) package list (“the app store” for Linux):

sudo apt update

Then we can install the desired software. Here we will install nginx, which is a very popular web server, but a popular alternative is also apache2.

sudo apt install nginx

Web server configuration and files

We usually find configuration files in /etc/<software_name>/. For nginx, this is therefore /etc/nginx/. We don’t need to look at it now, but if you want to change something in the configuration, such as ports, additional virtual hosts, SSL certificates, etc., that’s where you should do it.

Web files, meaning HTML, CSS, JavaScript, and so on, are typically located in /var/www/html/. Here you can add your own files. For example, you could create an index.html file here with some simple HTML code.

cd /var/www/html/
sudo nano index.html
nano - A little about the text editor

Nano is a very basic text editor that can be used in the terminal. It is easy to use and requires little prior knowledge.

Some basic commands:

  • CTRL + S - Save the file
  • CTRL + X - Exit nano

If you press CTRL + X without saving, it will ask if you want to save the file. Press Y for yes, N for no. Then press ENTER to confirm the filename.

Starting and stopping the web server

Once installation is complete, we can start the web server with:

sudo systemctl start nginx
systemctl - what is it?

systemctl means “system control” and is a tool for controlling system services in Linux. It is used to start, stop, restart and check the status of services running in the background on the system.

systemctl start | stop | restart | status <servicename>

Then visit http://<server-ip-address>/ in your browser to see if the web server is running.

Finding the server’s IP address

To find the IP address of your server, you can use the command:

hostname -I # Capital I

Alternatively, you can use ip a or ifconfig, but these provide more information than just the IP address.