install apache ubuntu 22.04
install apache ubuntu 22.04

12

Jun

How to install Apache 2 on Ubuntu 22.04

Are you looking to set up your own web server on Ubuntu? Apache is one of the most popular choices for hosting websites, and it’s relatively easy to install and configure on Ubuntu. In this guide, we’ll walk through the steps to install and configure Apache on your Ubuntu server.

Update Package Lists

First, let’s ensure that our package lists are up to date by running the following command:

sudo apt update

Install Apache

Now, let’s install Apache using the following command:

sudo apt install apache2 -y

Configure Apache

We’ll need to make a couple of configuration changes to Apache to ensure it runs smoothly.

Open the envvars file using your favorite text editor. Here, we’ll define the user and group under which Apache will run. Replace gerson with the appropriate user and group if needed.

sudo nano /etc/apache2/envvars
export APACHE_RUN_USER=gerson #www-data
export APACHE_RUN_GROUP=gerson #www-data

Next, open the main Apache configuration file:

sudo nano /etc/apache2/apache2.conf

Inside this file, find the <Directory /var/www/> section and make sure it looks like this:

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

Enable Modules

Apache needs a couple of modules to handle certain functionalities. Let’s enable them:

sudo a2enmod headers
sudo a2enmod rewrite

Set Permissions

We need to ensure that the Apache user has the necessary permissions to access the web root directory. Run the following command:

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

Restart Apache

Finally, let’s restart Apache to apply the changes:

sudo systemctl restart apache2

And that’s it! Apache is now installed and configured on your Ubuntu server. You can now start hosting your websites or web applications.

If you encounter any issues or have any questions, feel free to ask in the comments below. Happy hosting!

Leave a Reply

Your email address will not be published. Required fields are marked *

RELATED

Posts