AMZ DIGICOM

Digital Communication

AMZ DIGICOM

Digital Communication

Ubuntu: install and configure Apache

PARTAGEZ

Apache is often combined with Linux systems. Ubuntu is particularly suitable for web server installation, due to its passionate community and extensive documentation. Discover with us all the steps for installing and configuring Apache under Ubuntu.

Apache under Ubuntu: prerequisites

Apache is one of the oldest and most stable web servers. It is very popular, in particular thanks to its scalability and ease of configuration. There are no specific CPU requirements for installing Apache under Ubuntu 22.04. Most modern CPUs are usually sufficient to run Apache on Ubuntu. The basic elements required are the available RAM and storage capacity on the hard drive.

Apache consumes few resources and can be configured on different types of systems: desktops, laptops, servers, virtual machines, etc. In order to host an efficient website or application, more resources may be required to achieve optimal performance. Warning: remember that Use of modules may change system requirements. For example, if you want to integrate a module intended to improve the performance of an Apache web server, more memory will be needed for caching and other optimizations.

To configure an Apache web server, you must meet the following prerequisites:

  • RAM : 4GB
  • Operating system : Ubuntu (user with sudo access rights)
  • Hard disk space : 5 GB
  • Firewall : sufficient to regulate HTTP traffic and block ports that are not necessary
  • Internet connection : sufficient to download packages

With the Linux hosting offer offered by IONOS, benefit from unlimited traffic, the best performance in terms of speed and the highest security standards. Don’t wait any longer to improve your online visibility with the Linux servers offered by IONOS!

Step-by-step instructions: installing Apache on Ubuntu

Ubuntu 22.04 uses theAPT package management tool to install Apache. Start by refreshing the package index on your Ubuntu system, to ensure that all necessary dependencies are up to date.

If the installation is not local, use the SSH protocol to connect to your Ubuntu server.

Step 1: Update Package List

First call the terminal and then perform an update.

Step 2: Install Apache Package

Then install the Apache package and all its dependencies using the APT command “ install “.

$ sudo apt install apache2

bash

Step 3: Change Firewall Settings

To configure Apache, you need to enable the Uncomplicated Firewall (UFW) program in Ubuntu. Once Apache is installed under Ubuntu, it configures application profiles in UFW, the latter allowing to regulate data traffic to web ports.

Use the following command to display the list of application profiles:

The result displays three profiles for Apache:

Linux Terminal: List of application profiles for Apache
Terminal: list of application profiles for Apache
  • Apache : opens TCP port 80 for HTTP (unencrypted connection)
  • Apache Full : opens TCP port 80 (HTTP, unencrypted connection) and 443 (HTTPS, encrypted connection with TLS/SSL)
  • Apache Secure : only opens HTTPS port 443 for an encrypted connection

Since no SSL has been implemented yet, we can only open port 80.

$ sudo ufw allow ‘Apache’

bash

The “status” command allows you to check that the correct setting has been made.

Step 4: Test Apache Status

Use the system manager ” systemd » to check if the Apache service is active.

$ sudo systemctl status apache2

bash

Step 5: Call the default Apache start page

Enter your IP address in the browser address bar to access the default Apache page. Don’t know your IP address? Just type “hostname” to view it.

You also have the option of using the “icanhazip” tool.

$ curl -4 icanhazip.com

bash

Now call the Apache standard page in your browser, then replace “ server_ip » by your own IP address.

Below is an extract from the page under Ubuntu:

Web browser: Apache home page under Ubuntu
Web browser: Apache home page under Ubuntu

Step 6: Manage the Apache Daemon

You can use “systemctl” to manage the Apache web server daemon (or service).

Start the Apache web server as follows:

$ sudo systemctl start apache2

bash

Stop the Apache web server as follows:

$ sudo systemctl stop apache2

bash

Stop and restart the Apache web server as follows:

$ sudo systemctl restart apache2

bash

Restart Apache and reload the configuration as follows:

$ sudo systemctl reload apache2

bash

If you install Apache under Ubuntu, the web server launches automatically at startup, just after configuration. You can also choose to deactivate this function:

$ sudo systemctl disable apache2

bash

If you want to re-enable Apache to launch automatically on startup, follow these steps:

$ sudo systemctl enable apache2

bash

Step 7: Use virtual hosts

Apache hosts, by default, documents in /var/www/html. If you want to use multiple domains on a server, then you can set up virtual hosts. To do this, create a directory structure for its own domain within /var/www/.

$ sudo mkdir /var/www/your_domain

bash

Then replace “ your_domain » by the name of your domain.

Assign ownership of the directory to the environment variable “ $USE »:

$ sudo chown -R $USER:$USER /var/www/your_domain

bash

It is also possible to explicitly assign read, write and execute rights in octal mode:

$ sudo chmod -R 755 /var/www/your_domain

bash

Step 8: Create a Test Page

Create a index.html as the home page for your domain. To do this, you can use the text editor “ nano “, For example.

$ sudo nano /var/www/your_domain/index.html

bash

Then choose a wording before inserting it into the HTML file:

<html>
    <head>
        <title>Welcome to your_domain!</title>
    </head>
    <body>
        <h1>Here you can see that your_domain virtual host is successfully working!</h1>
    </body>
</html>

html

Step 9: Create a configuration file for the virtual host

Apache must be configured based on the domain for the example page to be displayed. Create a configuration file specific to your domainwithout modifying the default Apache configuration file.

$ /etc/apache2/sites-available/your_domain.conf

bash

Insert the following block, then replace “ your_domain » by the name of your domain. In “ServerAdmin”, it is also necessary to indicate an email address for the administrator:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName your_domain
    ServerAlias www.your_domain
    DocumentRoot /var/www/your_domain
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

bash

Activate the configuration file using “a2ensite”:

$ sudo a2ensite your_domain.conf

bash

Then deactivate the old default page:

$ sudo a2dissite 000-default.conf

bash

Test the configuration to detect any errors:

$ sudo apache2ctl configtest

bash

If there are no errors, you can then restart Apache:

$ sudo systemctl restart apache2

bash

Go to your home page:

Now it is normally possible to see your example page:

Web browser: sample page for a virtual host
Web browser: sample page for a virtual host

Step 10: Important Apache Files and Directories

If you want to use the Apache web server effectively, it may be beneficial to know some of the most frequently used files and directories:

  • /var/www/html : by default, Apache makes the documents available in this directory. You can change this setting in configuration files.
  • /etc/apache2 : All Apache configuration files are kept in this directory.
  • /etc/apache2/apache2.conf : This is the main configuration file, which allows you to modify the configuration as a whole.
  • /etc/apache2/ports.conf : Open ports are listed in this file. Typically this is port 80 and/or port 443.
  • /etc/apache2/sites-available/ : Configured virtual hosts are stored in this folder. To work, the configuration files found there must be associated with the “site-enabled” directory.
  • /etc/apache2/conf-available/, /etc/apache2/conf-enabled/ : Additional configuration files not belonging to virtual hosts are stored in these directories. To activate the configuration, use “a2enconf”; To disable it, use “a2disconf”.
  • /etc/apache2/mods-available/, /etc/apache2/mods-enabled/ : all modules that are available and activated are located in these directories. Use “a2enmod” to enable a module, and “a2dismod” to disable it.
  • /var/log/apache2/access.log : All requests to the web server are recorded in this log file.
  • /var/log/apache2/error.log : all error messages are logged in this file. “LogLevel” information provides information on the severity of events.

You don’t have time to administer and maintain a server? We recommend renting a Managed server from IONOS. You don’t need to know Linux inside out to manage a Managed server. IONOS takes care of all important server management tasks for you, including automatic backups and security checks.

Télécharger notre livre blanc

Comment construire une stratégie de marketing digital ?

Le guide indispensable pour promouvoir votre marque en ligne

En savoir plus

Web Marketing

Overview of the main SEO tools

Andriy OrlovShutterstock Overview of the Best Google SEO Tools If you want to attract as many visitors as possible to your website, you must understand

Souhaitez vous Booster votre Business?

écrivez-nous et restez en contact