![install apache ubuntu 22.04](https://me.gersonhernandez.net/wp-content/uploads/2024/06/Install-Apache-Ubuntu-22.04.webp)
![install apache ubuntu 22.04](https://me.gersonhernandez.net/wp-content/uploads/2024/06/Install-Apache-Ubuntu-22.04.webp)
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!
Author
I'm a web developer with eight years of experience and a proud graduate of the Universidad Tecnológica de El Salvador, where I earned my degree in Computer Science. Specializing in PHP, WordPress, Laravel, and Magento, I've channeled my passion for technology into crafting innovative and functional web solutions.