What Is Needed to Install and Configure Apache Server

What Is Needed to Install and Configure Apache Server: Bootstrapped in 1995 by the Apache Software Foundation, Apache (short for Apache HTTP Server) is a largely popular open source web server software that’s used by millions of developers and website owners to upload their websites’ content on the Internet.

The primary reason behind Apache’s popularity is that it’s available for everyone to download and use for free.

More than 30% of web servers use Apache including web hosts and reputable brand names like Slack, Delivery Hero, LinkedIn, Facebook, Cisco, VMware, The New York Times, many more.

Despite the rapid growth of other fast and advanced web servers such as Nginx, Apache is still widely used for its reliability, customizable environments, and security..

Even though Apache is part of the LAMP (Linux, Apache, MySQL, PHP) stack on Linux, it can also be installed and used on Microsoft Windows. In this step-by-step guide, we’ll show you how to install and configure Apache on Ubuntu Linux and Microsoft Windows.

How Apache web server works

As a web server software, Apache runs on a HTTP server and its core function is to connect visitors with your website smoothly through the HTTP protocol.

Apache accepts requests from a visitor’s web browser and sends them to the website page they want to view (load) such as your website’s homepage, About Us page, Contact Us page, etc. Also get how to Setting up Direct Admin Control Panel

But, that’s how any web server operates. So, what’s special about Apache?

Apache offers a variety of modules and features that can be adjusted by server admins including, but not limited to:

  • Support for HTTP/2 and IPv6
  • Built-in PHP, Lua, and Perl scripts
  • Gzip compression and decompression
  • DSO support (for loading Dynamic modules)
  • .htaccess
  • mod ssl (to enable SSL and TLS support)
  • Web-based Distributed Authoring and Versioning (WebDAV)
  • FTP connections

See full details of Apache’s performance, security, and latest versions.

Pros and Cons of Apache

Although Apache has established itself as the go-to web server for website deployment and a standard solution for developers, it has its strengths and weaknesses. Let’s view some of them.

Apache’s Pros

  1. Accessibility: Not only is Apache an open source software (the source code is public), but it’s also free for everyone to use – no license required.
  1. Cross-platform compatibility: Works on both Linux and Windows servers.
  1. Flexibility: Apache is highly customizable and flexible because of its dynamic modules such as the Multi-Processing Module (MPM).
  1. Reliability: It can handle large traffic and is regularly updated with the latest security fixes and maintained. Apache is efficient for dynamic content.
  1. User-friendly: Apache can be easily installed and configured (especially on Linux) even if you’re a beginner.
  1. Feature-rich: It has a wide range of modules and implemented features to enhance its performance and security.

Apache’s Cons

  1. Since Apache is an open source software that gives a lot of room for personalizing protocols and making modifications to its configuration, it makes it vulnerable to bugs and cyber threats. That’s why you must regularly monitor it for new updates and latest version releases  to avoid any security breaches.
  1. In spite of its ability to handle large traffic, Apache is still a process-based web server. It needs to create a new process to serve every HTTP request. Therefore, its performance lags behind exceedingly heavy traffic flow as opposed to Nginx.

How to Install and Configure Apache on Ubuntu Linux

By default, Apache is in Ubuntu repositories which means that it can be easily installed using the apt package management tool. The following steps will show you how to quickly install Apache Web Server on Ubuntu:

  1. Run the following command:
sudo apt update
sudo apt install apache2
  1. To check the status of Apache and make sure that it has been properly installed and running on Ubuntu, run the following command:
sudo systemctl status apache2

If Apache is running properly the following lines should be displayed:

apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2021-10-27 11:10:30 CDT; 15s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 4860 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 4864 (apache2)
      Tasks: 55 (limit: 4651)
     Memory: 4.7M
     CGroup: /system.slice/apache2.service
             ├─4864 /usr/sbin/apache2 -k start
             ├─4865 /usr/sbin/apache2 -k start
             └─4866 /usr/sbin/apache2 -k start

Oct 27 11:10:30 ubuntu2004 systemd[1]: Starting The Apache HTTP Server...
Oct 27 11:10:30 ubuntu2004 apachectl[4863]: AH00558: apache2: Could not reliably determine the >

How to Allow Apache through Ubuntu Firewall

In the case you’re running Ubuntu with the firewall enabled (in protected mode), you’ll need to provide access for HTTP (80) and HTTPS (443) to the Apache server. In most cases Ubuntu runs without the firewall being enabled. Nginx Vs Apache which is better for cPanel Hosting?

However if you’re not sure, and you’re using UFW to manage your Ubuntu firewall, then use the following command:

sudo ufw allow ‘Apache Full’

This command will allow all traffic to the Apache server.

Now that the firewall is opened, you can browse to the server hostname, or IP address to make sure if the Apache default page is up

http://localhost

If so the Apache default welcome page should appear as follows:

Apache default welcome page Install and Configure Apache Server

Configuring Apache on Ubuntu Linux

Different Linux systems have different folder structures and configuration files. Now that Apache is installed, there are important folders and locations you should be aware of:

  • etc/apache2/apache2.conf – This is the main global Apache configuration folder that includes all other configuration files.
  • /etc/apache2/conf-available – This is where all the available configurations are stored.
  • /etc/apache2/conf-enabled – This includes all the enabled configurations.
  • /etc/apache2/ports.conf – This includes all the ports configurations including changing the default listen ports. These ports are what Apache listens on for traffic.
  • /etc/apache2/mods-available – This includes all available modules
  • /etc/apache2/mods-enabled – This includes all enabled modules
  • /var/log/apache – This directory includes all the log files (access.log and error.log).
  • /etc/apache2/sites-available – Includes the configuration file for all the available sites (virtual hosts)
  • /etc/apache2/sites-enabled – includes the configuration file for all the enabled sites (virtual hosts)

To activate and link a site from the sites-available directory to the sites-enabled, use the following command:

sudo a2ensite example.com.conf (replace example.com.conf with your VirtualHost file)

This command will create a symlink of the website configuration files in the sites-available directory to the site-enabled directory.

Use the following command in order to deactivate a virtual host:

 sudo a2dissite example.com.conf (replace example.com.conf with your website’s VirtualHost file)

Finally, to enable or disable modules, you can use the commands a2enconf and a2disconf. Also get How to create your own server at Home for web Hosting

How to Install and Configure Apache on Microsoft Windows

Installing and configuring Apache on Windows is slightly simpler than on Ubuntu Linux and can be done via the following steps:

1.   Download Apache for Windows

You can download Apache for Windows for free from the ApacheLounge website. Both 32-bit and 64-bit versions are available so make sure you know which version your WIndows is running on.

Download Apache for Windows

For the sake of this tutorial, we’ll assume that the Windows version running is 64-bit and so download Apache 2.4.51 Win64 (httpd-2.4.51-win64-VS16.zip)

You’ll also need to make sure that installed on your server is the relevant C++ Redistributable for Visual Studio. Here you can also get Best Web Hosting for Photographers

Usually it’s already installed. However, in case it isn’t, download and run vc redist x64 (for a 64-bit operating system) or  vc redist x86 (for a 32-bit operating system). You’ll find the link for both versions on the ApacheLounge download page.

2.    Unzip the downloaded file

Once the file labeled httpd-2.4.51-win64-VC15.zip has been downloaded, open it and extract all the its contents to the relevant location on your server (i.e. C:\Apache24 or D:\Apache)

3.   Configure Apache on Windows

Once the extraction is complete, start the configuration by locating the file labeled httpd.conf (located in the “conf” subdirectory) and open it in a standard text editor.

This configuration file assumes, by default, that Apache has been extracted to C:\Apache24. If this isn’t the case and you’ve extracted Apache to a different location (D:\Apache), the ${SRVROOT} variable, within the httpd.conf file, will need to be updated to the new location accordingly as follows:

Define SRVROOT “C:\Apache24” → Define SRVROOT “D:\Apache”

If you don’t find the SRVROOT variable in the httpd.conf file, then alternatively you’ll need to update all the “C:\Apache24” instances manually as follows:

ServerRoot “C:\Apache24” → ServerRoot “D:\Apache”
DocumentRoot “C:\Apache24\htdocs” → DocumentRoot “D:\Apache\htdocs”
<Directory “C:\Apache24\htdocs”> → <Directory “D:\Apache\htdocs”>
ScriptAlias \cgi-bin\ "C:\Apache24\cgi-bin\" → ScriptAlias \cgi-bin\ "D:/Apache/cgi-bin\"                                                

You’ll also need to make the following modifications to the httpd.conf file, regardless of where you extracted Apache to:

  1. To the “Options” directive, add “ExecCGI”:
  • To do that locate the following line:
Options Indexes FollowSymLinks
  • Add to it “ExecCGI” as follows:

Options Indexes FollowSymLinks ExecCGI

This will inform Apache that the CGI/Perl scripts are allowed outside the cgi-bin directory

  1. Locate and uncomment (by removing the # symbol from the beginning of the line) the following line:
AddHandler cgi-script .cgi

Add the following line:

AddHandler cgi-script .pl

These commands will inform Apache how to handle .cgi/.pl files (i.e. execute instead of presenting them as text to the web browser)

  1. To the end of the httpd.conf file, add the following line:
ScriptInterpreterSource Registry

This allows Apache to determine the location of Perl from the Windows Registry instead of using the very first line of the .cgi/.pl files which direct Apache to the install location of Perl.

4.   Starting Apache

At the location where you extracted Apache, open a command/PowerShell prompt in the bin folder (hold “Shift” whilst right-clicking and select “Open command window here” or Open PowerShell window here”):

Starting Apache

In the command prompt, or window, start Apache using the following command:

httpd.exe

If you’re using or opened a PowerShell prompt, then use the following command:

& D:\Apache\bin\httpd.exe

If you have Apache in a different location (i.e. C:\Apache24), then replace “D:\Apache with that location.

If the Windows firewall window pops up, click on “Allow Access” at the bottom of the window to allow access for the Apache server. If you fail to do so, other computers/devices will be unable to connect to your web server. Here you can also get the Best Dedicated Server Hosting for Beginners

 allow access for the Apache server

If the command you entered failed to start and an “could not bind to address” error appears, this most probably means that another service is already running on Apache’s default port (80).

In this case, you need to check if you don’t have an IIS (Internet Information Services) server already currently running.

If this is the case, you’ll need to stop/disable the IIS or change the port used by the IIS or Apache in order to allow both services to run simultaneously.

5.   Check Apache to see if it’s running properly

While the previous command window is still open, open your browser and navigate to http://127.0.0.1

Check Apache to see if it’s running properly

You should “It works!” displayed in your browser if Apache is working.

6.   Install Apache as a continuously running Windows service

Once you close the command, or PowerShell window, Apache will automatically exit. To ensure that Apache keeps running, it has to be installed as a Windows service. To do so, open an administrative command prompt or PowerShell prompt and enter the following command:

http.exe -k install

If you’re using PowerShell prompt, then enter the following command instead:

Start-Process PowerShell -Verb RunAs

This command ensures that PowerShell is running as an administrator. Now, enter the following command:

& “D:\Apache\bin\httpd.exe -k install

If Apache is in a different location, then just replace “D:\Apache” with that location. At this point a message should appear that Apache 2.4 has been successfully installed. Now you can start the service by entering the following command:

Net start Apache2.4
Install Apache as a continuously running Windows service

Conclusion

As you can see, Apache is easy to use and can be installed and configured on different operating systems.

Whether you’re a Linux or Windows user, you shouldn’t have any trouble with the installation process as long as you follow the steps properly.

If you have any questions or comments, let’s discuss in the comments section!

0 0 votes
Your rating
Subscribe
Notify of
guest
Your rating
0 Comments
Inline Feedbacks
View all comments