Kali http server setup

There are multiple ways to set up an HTTP web server in Kali Linux. Apache, NGINX, and Python are a few of the ways this can be accomplished.

Since you are looking to set up a web server on Kali, it might be safe to assume that you are trying to spoof some other website, or dupe users with some sort of phishing ploy. In that case, all three web server types have their pros and cons, with Python being the quickest one to get up and running.

Whatever the purpose of your web server may be, nefarious or not, you will learn how to install and configure a simple HTTP server using either Apache, NGINX, or Python in this tutorial. Follow through our step by step instructions below to see how it’s done.

In this tutorial you will learn:

  • How to install Python 3 on Kali Linux
  • How to install Apache and NGINX on Kali Linux
  • How to host a web server using Python 3
  • How to host a web server using Apache and NGINX
Kali http server setup
Kali http server setup
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Kali Linux
Software Python 3, Apache, NGINX
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

How to install Apache, NGINX, or Python 3 on Kali Linux




The only prerequisite to follow this guide is that you have either Apache, NGINX, or Python 3 installed on your system, depending on which type of web server you want to host. Use the instructions below to install one of the software packages on your Linux system.

You can use the appropriate command below to install Python 3, Apache, or NGINX with your system’s package manager.

To install Python 3 Kali Linux:

$ sudo apt install python3

To install Apache on Kali Linux:

$ sudo apt install apache2

To install NGINX on Kali Linux:

$ sudo apt install nginx

Configure Python 3 web server in Kali Linux step by step instructions

  1. To start a web server using Python 3, use the following command. With this syntax, our web server will be running on IP address 127.0.0.1 and port 9000. You can change this to anything you want, or omit the options entirely to have Python be hosted on the default IP and port.
    $ python3 -m http.server --bind 127.0.0.1 9000
    
  2. You should see confirmation in your terminal window that Python is now serving an HTTP server on the IP and port you configured.

    Hosting a simple web server in Python on Kali Linux
    Hosting a simple web server in Python on Kali Linux
  3. Now you can open up a browser and navigate to the address you configured, which is http://127.0.0.1:9000 in our case.
    Navigating to our Python hosted web server in Firefox
    Navigating to our Python hosted web server in Firefox

    As you can see, by default the website just displays our home directory and all of the files inside of it. We can now use this as a file browser. This might prove useful if you want to download some of these files from another system on your local area network.

  4. Most likely, you will want to serve some kind of HTML website here. So you can generate a test document to use.
    $ echo Python 3 on Kali Linux > ~/index.html
    
  5. And then we refresh the website to see the page we just created.

    Viewing HTML website hosted with Python 3 on Kali
    Viewing HTML website hosted with Python 3 on Kali

Configure Apache web server in Kali Linux step by step instructions

  1. Once Apache installed, you can use systemd’s systemctl commands to control the service.Enable or disable Apache from starting at system boot:
    $ sudo systemctl enable apache2
    OR
    $ sudo systemctl disable apache2
    

    Start or stop Apache web server:



    $ sudo systemctl start apache2
    OR
    $ sudo systemctl stop apache2
    
  2. Once you have started the Apache web server using the systemctl command shown above, you can test to make sure everything is working correctly by navigating to http://localhost on your system. You should be greeted by the default Apache page, as seen below.

    Default Apache page
    Default Apache page
  3. With Apache up and running, we’re ready to configure our website. The default directory for our website’s files is /var/www/html. Move your files here, or begin by replacing the default index.html greeting page. In this example, we’ll just make a simple HTML document to see the changes reflected on the website.
    $ echo Apache on Kali Linux > index.html
    $ sudo mv index.html /var/www/html
    
  4. Refresh the page in order to see the new changes.

    Viewing HTML website hosted with Apache on Kali
    Viewing HTML website hosted with Apache on Kali

Configure NGINX web server in Kali Linux step by step instructions

  1. After NGINX is installed, you can use systemd’s systemctl commands to control the service.Enable or disable NGINX from starting at system boot:
    $ sudo systemctl enable nginx
    OR
    $ sudo systemctl disable nginx
    

    Start or stop NGINX web server:

    $ sudo systemctl start nginx
    OR
    $ sudo systemctl stop nginx
    



  2. Once you have started the NGINX web server using the systemctl command shown above, you can test to make sure everything is working correctly by navigating to http://localhost on your system. You should be greeted by the default NGINX page, as seen below.

    Default NGINX page
    Default NGINX page
  3. With NGINX up and running, we’re ready to configure our website. The default directory for our website’s files is /var/www/html. Move your files here, or begin by replacing the default index.html greeting page. In this example, we’ll just make a simple HTML document to see the changes reflected on the website.
    $ echo NGINX on Kali Linux > index.html
    $ sudo mv index.html /var/www/html
    
  4. Refresh the page in order to see the new changes.

    Viewing HTML website hosted with NGINX on Kali
    Viewing HTML website hosted with NGINX on Kali

Closing Thoughts




In this tutorial, we saw how to host an HTTP web server using Python 3, Apache, and NGINX on a Kali Linux system. This set of instructions will work for whatever purpose you have, especially to setup a fake website to try and trick users to login to. Python web servers are not as robust as full stack web servers like Apache or NGINX but, they are good for simple purposes and getting a web server up quickly.