Welcome to the page sampledomain.com!

How to Install and Configure Apache Web Server on Ubuntu

Ubuntu Aapache Web Server

Apache or Apache HTTP server is a free and open source web server, developed and maintained by the Apache Software Foundation. Its popularity can be judged by the fact that around 46% of the websites worldwide are powered by Apache. Apache allows website developers to serve their content over the web. It serves as a delivery man by delivering files requested by users when they enter a domain name in their browser’s address bar.

This tutorial is about installing and configuring Apache2 on your Ubuntu system. The commands and procedures mentioned in this article have been run on an Ubuntu 18.04 LTS system. Since we are using the Ubuntu command line, the Terminal, in this article; you can open it through the system Dash or the Ctrl+Alt+T shortcut.

Install Apache 2 on Ubuntu Linux

Please follow the following steps in order to install the Apache2 software through Ubuntu official repositories.

Step 1: Update system repositories

You can download the latest version of a software by first updating the local package index of Ubuntu repositories. Open the Terminal and enter the following command in order to do so:

Update Ubuntu repositories

Step 2: Install Apache 2 with the apt command

Next, enter the following command as sudo in order to install Apache2 and its required dependencies:

Install Apache web server with apt

You may be prompted with a y/n option to continue installation. Please enter Y, after which the installation procedure will begin.

Step 3: Verify the Apache installation

When the installation is complete, you can check the version number and thus verify that Apache2 is indeed installed on your system by entering the following command:

Check installed Apache version

Configure the Firewall Settings

In order to configure Apache, we first need to allow outside access to certain web ports of our system and allow Apache on your UFW firewall.

Step 1: List the UFW application profiles

In order to configure the firewall, let us first list the application profiles we will need to enable access to Apache. Use the following command to list such available applications:

List App presets in UFW Firewall

In the above output, you can see three Apache profiles all providing different levels of security; Apache being the one that provides maximum restriction with port 80 still open.

Читайте также:  Civilisation 5 steam linux

Step 2: Allow Apache on UFW and verify its status

Allowing Apache on UFW will open port 80 for network traffic, while providing maximum security to the server. Please configure UFW to allow Apache through the following command:

Open Apache ports in UFW

The status of UFW will now display Apache enabled on the firewall.

Configure the Apache Web server Settings

Step 1: Verify that the Apache service is running

The first step is to verify that the Apache2 service is up and running on your system, through the following command:

$ sudo systemctl status apache2

Check Apache status

The status “active (running) verifies that the apache2 service is running.

Step 2: Verify that Apache is running properly and listens on your IP address

You can also verify if Apache is running by requesting a page from the Apache server. For this purpose, you can use your server’s IP in order to access the Apache landing page.

Use the following command to know about your server’s IP:

Get server IP addresses

Then try the IPs, one by one from the output, in your web browser as follows:

http://server_IP

In my case, http://192.168.100.4 and http://192.168.100.5. Doing so will display the following Apache web page for Ubuntu, verifying that the Apache server is working properly.

Apache default page

Set Up Virtual Hosts in Apache

A virtual host is similar to what you have server blocks in Nginx. It is used to manage configurations for more than one domain from one server. We will present an example of how to set up a virtual host through the Apache server. We will set up a website named sampledomain.com by using the server block that is enabled by default in Apache for Ubuntu 18.

Step 1: Set up a domain name

The server block that is enabled by default is capable of serving documents from /var/www/html. However, we will create a directory at /var/www/ leaving the default directory intact.

Create this directory through the following command, replacing sampledomain.com by your respective domain name.

sudo mkdir -p /var/www/sampledomain.com/html

Create the directory for virtual host

Then assign the ownership of the directory through the following commands:

sudo chown -R $USER:$USER /var/www/sampledomain.com/html
sudo chmod -R 755 /var/www/sampledomain.com

Change directory ownership

Let us now create an index page that we can later access to test if Apache is running our domain name. Create an HTML file either through the Nano editor or any of your favorite text editor.

$ nano /var/www/sampledomain.com/html/index.html

Enter the following HTML for the index page:

    

You got Lucky! Your sampledomain.com server block is up!

Sample index page

We are using the nano editor to create the HTML file.

You can save a file in nano by using Ctrl+X and then enter Y and hitting Enter.

Apache needs a virtual host file to serve the contents of your server. The default configuration file for this purpose is already created but we will make a new one for our custom configurations.

$ sudo nano /etc/apache2/sites-available/sampledomain.com.conf

Enter the following customized configuration details for our domain name:

 ServerAdmin [email protected] ServerName sampledomain.com ServerAlias www.sampledomain.com DocumentRoot /var/www/sampledomain.com/html ErrorLog $/error.log CustomLog $/access.log combined 

Apache vhost file

We are using the nano editor to create this .conf file.

You can save a file in nano by using Ctrl+X and then enter Y and hitting Enter.

Step 2: Enable the domain configuration file

Let us enable the configuration file we created with the a2ensite tool:

$ sudo a2ensite sampledomain.com.conf

Enable config file in apache

The output will suggest activating the new configuration but we can do it all collectively after running the following command that disables the original configuration file:

$ sudo a2dissite 000-default.conf

Disable default website

Now restart the Apache service:

$ sudo systemctl restart apache2

Step 3: Test for errors

Finally, let us test if there are any configuration errors through the following command:

$ sudo apache2ctl configtest

If you do not get any errors, you will get the following output:

Читайте также:  Mounting img files linux

Test configuration

However, the following error is common in Ubuntu 18.04

Resolve the error:

Enter the following command in order to resolve the above-mentioned error:

$ echo "ServerName sampledomain.com | sudo tee /etc/apache2/conf-available/servername.conf

Resolve servername error

Enable servername config

Now when you check again for errors, you will see this error resolved through the following output:

Step 4: Test if Apache is serving your domain name

Apache server is now configured to serve your domain name. This can be verified by entering your server name as follows in any of the web browsers running on your system:

http://sampledomain.com

The index page should display as follows, indicating that Apache is now ready to serve your server block!

Access your website by domain name

Some Common Apache Management Commands

After setting up the web server, you might have to perform some basic management operations on Apache. Here are the commands that you can enter in your Terminal application for these operations.

sudo systemctl start apache2

Use this command as sudo in order to start the Apache server.

sudo systemctl stop apache2

Use this command as sudo in order to stop the Apache server when it is in start mode.

sudo systemctl restart apache2

Use this command as sudo in order to stop and then start the Apache service again.

sudo systemctl reload apache2

Use this command as sudo in order to apply the configuration changes without restarting the connection.

sudo systemctl enable apache2

Use this command as sudo in order to enable Apache to be started every time you boot your system.

sudo systemctl disable apache2

Use this command as sudo in order to disable if you have set up Apache to be started every time you boot your system.

Conclusion

Through this article, you have learned to install and configure the Apache web server on your Ubuntu system. This includes making some changes to your UFW firewall and then configuring your web server for your IP address. We also recommend you to set up a virtual host through Apache; this will give you a basis on how to use Apache to host your files on the Internet. The basic Apache management commands will also help you as a web administrator to manage your web server in an optimal manner.

Источник

Install & Configure Apache Web Server In Linux – httpd

Learn how to install and configure Apache web server in Linux. Understand the httpd configuration file and how to start, stop & enable Apache (httpd) in Linux.

UNDERSTANDING THE SUBJECT MATTER

What Is Apache

Apache, also called Apache http server is an open-source web server. A web server, of course, is responsible for handling web requests from various computers hitting the web. (No web server, no website).

Just as there is an Apache web server, there are also a lot of web servers out there such as Nginx, IIS, Tomcat, etc.

Tomcat is also called Apache tomcat because it is developed by the same company that developed Apache (Apache Software Foundation)

Apache is a very popular and commonly used web server and can run on both Linux and Windows operating systems.

Читайте также:  How to check internet speed linux

Just as Nginx, Apache can handle hundreds of thousands of connections trying to fetch information from the web concurrently.

With Apache, you can customize your configuration by using the “.htaccess” file.

When it comes to the Content Management System (CMS) such as WordPress, Joomla, and Drupal, they all work perfectly well on Apache, even without less or no configuration, hence why most web hosting companies use Apache and now Nginx as their web servers.

Apache application/daemon for Linux is “httpd”

How Do I Start Apache (httpd) On Linux

The same way you start other services on Linux is also the same way Apache is started.

To start Apache, use the command

To Stop Apache, use the command,

To enable Apache, use the command,

Apache (httpd) Configuration file

core apache configuration file is in the path /etc/httpd/conf/httpd.conf)

Let’s see the contents in this file.

[root@HQDEV1 ~]# cat /etc/httpd/conf/httpd.conf

search for the line “DocumentRoot”

Apache web server in Linux

you can see the httpd document root (/var/www/html). It is one of the important parameters in the httpd configuration file.

Every website file will have to be on this path. The document root can be changed, especially for hardening web server security.

We will look at how to successfully change the document root of httpd when we get to the advanced configuration in another lesson.

httpd by default listens on port 80.

What is LAMP stack

If you know LEMP stack, you will also know LAMP stack.

LAMP stack consists of (Linux, Apache, MySQL, and PHP). They are all web development software used to manage web applications.

How to install LAMP stack in Linux (RHEL 8 / CentOS 8)

And Of course, in the “ACTION TIME” of this lesson, we will install Apache & configure a basic website.

Having understood what Apache is, let’s get to installing and configuring Apache for a basic website.

ACTION TIME

How To Install & Configure Apache httpd On Linux (RHEL / CentOS 7 & 8)

we will look at how to configure Apache for a basic website.

1. Install Apache web server

[root@HQDEV1 ~]# yum install httpd Updating Subscription Management repositories. Last metadata expiration check: 0:36:27 ago on Sat 04 Jul 2020 10:17:20 PM WAT. ca404a3.x86_64 httpd-filesystem-2.4.37-21.module+el8.2.0+5008+cca404a3.noarch redhat-logos-httpd-81.1-1.el8.noarch Complete! 

2. create a web file in the document root location.

[root@HQDEV1 ~]# vi /var/www/html/tekneed

3. Start the httpd service

[root@HQDEV1 ~]# systemctl start httpd

4. If you wish, you can enable the httpd service

[root@HQDEV1 ~]# systemctl enable httpd Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service. 

5. Verify the service has started

[root@HQDEV1 ~]# systemctl status httpd ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: active (running) since Sat 2020-07-04 23:08:53 WAT; 10min ago Docs: man:httpd.service(8) Main PID: 45702 (httpd) Status: "Running, listening on: port 80" 

6. Test your configuration

You can use any browser or use a text-based browser such as elinks.

To use elinks in RHEL 7, install elinks by using the command,

[root@HQDEV1 ~]# yum install elinks

To install elinks in RHEL 8 or CentOS 8, click on this link

7. Now that elinks has been installed, do a test.

[root@HQDEV1 ~]# elinks http://localhost/tekneed

press the enter key to open the file

You can see that the web server is properly configured.

In another tutorial, we will look at the advanced configuration of the Apache web server

Источник

Оцените статью
Adblock
detector