Linux serverlinux web serverNETWORK ADMINISTRATIONS

Create a WebServer (Apache) on Linux Ubuntu Server

Step 1 — Installing Apache
Apache is available within Ubuntu’s default software repositories, making it possible to install it using conventional package management tools.
$ sudo apt update
Then, install the apache2 package:
$ sudo apt install apache2

Step 2 — Adjusting the Firewall

List the ufw application profiles by typing:
$ sudo ufw app list
You will receive a list of the application profiles:

Output
Available applications:
Apache
Apache Full
Apache Secure
OpenSSH
As indicated by the output, there are three profiles available for Apache:
$ sudo ufw allow ‘Apache Full’
You can verify the change by typing:

$ sudo ufw status
The output will provide a list of allowed HTTP traffic

Step 3 — Checking your Web Server
Check with the systemd init system to make sure the service is running by typing:

$ sudo systemctl status apache2

As confirmed by this output, the service has started successfully. However, the best way to test this is to request a page from Apache.

Try typing this at your server’s command prompt:

$ hostname -I

When you have your server’s IP address, enter it into your browser’s address bar:

http://your_server_ip
You should see the default Ubuntu 20.04 Apache web page

Step 4 — Managing the Apache Process
To stop your web server, type:
$ sudo systemctl stop apache2
To start the web server when it is stopped, type:
$ sudo systemctl start apache2
To stop and then start the service again, type:
$ sudo systemctl restart apache2
If you are simply making configuration changes, Apache can often reload without dropping connections. To do this, use this command:
$ sudo systemctl reload apache2

$ sudo systemctl disable apache2
To re-enable the service to start up at boot, type:

$ sudo systemctl enable apache2
Apache should now start automatically when the server boots again.

Step 5 — Setting Up Virtual Hosts (Recommended)
Create the directory for your_domain as follows:

$ sudo mkdir /var/www/your_domain
Next, assign ownership of the directory with the $USER environment variable:

$ sudo chown -R $USER:$USER /var/www/your_domain
The permissions of your web roots should be correct if you haven’t modified your umask value, which sets default file permissions. To ensure that your permissions are correct and allow the owner to read, write, and execute the files while granting only read and execute permissions to groups and others, you can input the following command:

$ sudo chmod -R 755 /var/www/your_domain
Next, create a sample index.html page using nano or your favorite editor:

$ sudo nano /var/www/your_domain/index.html
Inside, add the following sample HTML
Save and close the file when you are finished.

In order for Apache to serve this content, it’s necessary to create a virtual host file with the correct directives. Instead of modifying the default configuration file located at /etc/apache2/sites-available/000-default.conf directly, let’s make a new one at /etc/apache2/sites-available/your_domain.conf:

$ sudo nano /etc/apache2/sites-available/your_domain.conf
Let’s enable the file with the a2ensite tool:

$ sudo a2ensite your_domain.conf
Disable the default site defined in 000-default.conf:

$ sudo a2dissite 000-default.conf
Next, let’s test for configuration errors:

$ sudo apache2ctl configtest
You should receive the following output:

Output
Syntax OK
Restart Apache to implement your changes:

$ sudo systemctl restart apache2

source by Systems Administration

linux web server

One thought on “Create a WebServer (Apache) on Linux Ubuntu Server

  • Danke!
    Guter Beitrag. Leider wurden einige Einträge vergessen.
    Status: inactive

    $ sudo ufw enable

    Ich möchte cgi aktivieren. Wie mache ich es ?
    Bitte helfen.

Comments are closed.