Skip to content
Follow
CMS

How to install Magento with Apache on Ubuntu 24.04

Richard
Written by
Richard
May 31, 2024 Updated Jun 20, 2026 8 min read
Magento featured image
Magento featured image

You install Magento with Apache on Ubuntu 24.04 to build a powerful online store.

Magento is a highly customizable, open-source e-commerce solution, and Apache is a reliable web server that serves your website to visitors.

This guide focuses on installing Magento version 2.4.7 or a newer release on Ubuntu 24.04 LTS, using Apache as your web server.

⚡ Quick Answer

Install Apache by running sudo apt install apache2. Then, install MariaDB with sudo apt install mariadb-server. Finally, install PHP and necessary modules using sudo apt install php libapache2-mod-php php-intl php-mysql php-curl php-cli php-zip php-gd php-common php-mbstring php-xmlrpc.

Install Apache HTTP server on Ubuntu Linux

Apache is a popular web server that Magento needs to run, so we’ll install it on your Ubuntu system first.

To do that, open the Ubuntu terminal and run the commands below to install the Apache web server.

🐧Bash / Shell
sudo apt update
sudo apt install apache2

Once Apache is installed, the commands below can start, stop, and enable the Apache web server to start automatically when your server boots up.

🐧Bash / Shell
sudo systemctl stop apache2
sudo systemctl start apache2
sudo systemctl enable apache2

You test that the Apache web server is running by opening your web browser and browsing to the server’s localhost or IP address.

http://localhost

Apache2 default landing page confirming successful web server installation for Magento
Apache2 default landing page confirming successful web server installation for Magento

When you see the Apache2 Default Page, it means the Apache HTTP server is successfully installed.

Additional help on installing Apache on Ubuntu is in the link below.

How to install Apache on Ubuntu

Install MariaDB database server on Ubuntu Linux

Magento needs a database to store all its information, and we’ll install MariaDB, a common choice for this on Ubuntu.

To install and use the MariaDB database server, use the instructions below.

Open the Ubuntu terminal and run the commands below to install the MariaDB database server.

🐧Bash / Shell
sudo apt update
sudo apt install mariadb-server

Once the MariaDB database server is installed, use the commands below to stop, start, and enable the MariaDB server to start automatically when the server boots.

🐧Bash / Shell
sudo systemctl stop mariadb
sudo systemctl start mariadb
sudo systemctl enable mariadb

Run the following commands to validate and test if the MariaDB database server is installed successfully.

🐧Bash / Shell
sudo mariadb

Once you run the commands above, it will log you onto the MariaDB console and display a message similar to the one below.

💻Code
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 32
Server version: 10.11.2-MariaDB-1 Ubuntu 23.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]> 

The message tells you that the server is installed successfully.

Additional help on installing MariaDB.

Create a Magento database

After setting up MariaDB, you need to create a specific database for Magento to hold all its data.

It’s important to note that this database will be the repository for all the Magento application content and data, underscoring its significance in the setup process.

As part of the setup, we will create a database named ‘magentodb ‘and a corresponding user account named ‘magentodbuser ‘.

Finally, we’ll grant the magentodbuser full access to the magentodb database.

All the database steps above can be done using the commands below:

But first, log on to the MariaDB database server:

🐧Bash / Shell
sudo mariadb

Then run the commands below to complete the steps:

💻Code
CREATE DATABASE magentodb CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER magentodbuser@localhost IDENTIFIED BY 'type_your_password_here';
GRANT ALL ON magentodb.* TO magentodbuser@localhost WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit

Ensure to replace ‘type_your_password_here‘ with your password.

Install PHP on Ubuntu Linux

Magento is built using PHP, so we need to install it on your Ubuntu system along with some essential extensions.

Run the commands below to install PHP.

🐧Bash / Shell
sudo apt install php libapache2-mod-php php-intl php-mysql php-curl php-cli php-zip php-gd php-common php-mbstring php-xmlrpc php-json php-sqlite3 php-zip php-soap php-bcmath php-xml

Additional help on installing PHP

How to install PHP on Ubuntu Linux

Download Magento files

Now it’s time to get the Magento files onto your server and install Composer, a tool needed to manage Magento’s code.

Run the command below to install these packages and start installing Magento.

🐧Bash / Shell
sudo apt install curl git
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

Before you can download Magento packages from its repository, you must create a new access key for Magento. The key is free.

To create authentication keys:

Log in to the Commerce Marketplace. If you don’t have an account, click Register. Click your account name in the top right of the page and select My Profile.

Click Access Keys in the Marketplace tab.

Magento access key page
Magento access key page

Click Create a New Access Key. Enter a specific name for the keys and click OK.

You can click to copy the new public and private keys associated with your account. Save this information or keep the page open when working on your project.

Use the Public key as your username and the Private key as your password.

With your Access key handy, change into the Apache root directory. Then, run the command below to clone the Magento project and create a new site. Name the site “magento” or whatever you want to call it.

Command Prompt
cd /var/www/
sudo composer create-project --repository=https://repo.magento.com/ magento/project-community-edition magento

Copy and paste the authentication key. (Your public key is your username; your private key is your password).

Enter the Username (your Access public key) and Password (your Access private key) from your marketplace account.

💻Code
Output:
Authentication required (repo.magento.com):
Username: 234f2343435d190983j0ew8u3220
Password:
Do you want to store credentials for repo.magento.com in /opt/magento/.config/composer/auth.json ? [Yn] Y

After downloading Magento packages, run the commands below to install Magento with the following options:

Command Prompt
cd /var/www/magento
sudo bin/magento setup:install --base-url-secure=https://magento.example.com/ --db-host=localhost --db-name=magentodb --db-user=magentodbuser --db-password=db_user_password_here --admin-firstname=Admin --admin-lastname=User --admin-email=admin@example.com --admin-user=admin --admin-password=admin123 --language=en_US --currency=USD --timezone=America/Chicago --use-rewrites=1
  • The Magento software is installed in the root directory on localhost. Admin is admin; Your storefront URL is https://magento.examaple.com
  • The database server is on the same localhost as the webserver.
  • The database name is magentodb, and the magentodbuser and password are db_user_password_here.
  • Uses server rewrites
  • The Magento administrator has the following properties:
    • First and last name are: Admin User
    • Username is: admin
  •  and the password is admin123
  • E-mail address is: admin@example.com
  • Default language is: (U.S. English)
  • Default currency is: U.S. dollars
  • Default time zone is: U.S. Central (America/Chicago)

During the installation, text will move quickly up the screen. When it is done, you will see a message similar to the one below.

💻Code
[Progress: 1448 / 1448]
[SUCCESS]: Magento installation complete.
[SUCCESS]: Magento Admin URI: /admin_f97ul2i
Nothing to import.

If you encounter trouble installing Elasticsearch, read the article below to learn how to install It on Ubuntu.

How to install Elasticsearch on Ubuntu Linux

Ensure the Elasticsearch service is started.

After that, run the commands below to set the correct permissions, generate a crontab, and run Magento indexing.

Finally, clear the cache of your Magento installation.

🐧Bash / Shell
sudo chown -R www-data:www-data /var/www/magento/
sudo -u www-data bin/magento cron:install
sudo -u www-data bin/magento cron:run --group index
sudo -u www-data bin/magento cache:clean

Configure Apache for Magento

With Magento downloaded, we’ll now tell Apache how to find and serve your Magento website files.

Run the commands below to create an Apache virtual host file for Magento.

🐧Bash / Shell
sudo nano /etc/apache2/sites-available/magento.conf

Then, copy and paste the content block below into the Apache server block.

💻Code
<VirtualHost *:80>
ServerName magento.example.com
ServerAlias www.magento.example.com
ServerAdmin admin@example.com
DocumentRoot /var/www/magento

<Directory /var/www/magento/>
Options FollowSymlinks
AllowOverride All
Require all granted
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

Save the file.

Then, run the commands below to enable the server block and restart the Apache server.

🐧Bash / Shell
sudo a2ensite magento.conf
sudo a2enmod rewrite
sudo systemctl restart apache2

Setup Let’s Encrypt SSL/TLS for Magento

To make your Magento site secure with HTTPS, we’ll set up a free SSL certificate using Let’s Encrypt.

Please read the post below for additional resources on installing and creating Let’s Encrypt SSL certificates for Apache.

How to set up Let’s Encrypt SSL certificate for Apache on Ubuntu Linux

After installing, the Certbot Apache plugin automatically configures the Apache server block file /etc/apache2/sites-available/magento.conf with HTTPS.

Once you have restarted the Apache web server, open your browser and browse to the server hostname or IP address defined in the Apache server block.

💻Code
https://magento.example.com

Magento default welcome page will appear.

Magento default welcome page
Magento default welcome page

That should do it!

Conclusion:

  • In this tutorial, you learned how to successfully install and configure the Magento eCommerce platform with Apache on Ubuntu 24.04.
  • Following these comprehensive steps, you have set up a robust and secure environment to run your e-commerce website.
  • Integrating the Apache web server, MariaDB database server, and PHP provides a stable foundation for hosting Magento.
  • Additional resources for setting up Let’s Encrypt SSL certificates for Apache have been provided to secure your Magento installation.

How to check if apache2 is installed in Ubuntu?

It lists all installed packages that contain Apache in their name besides. It in it indicates that the package Apache 2 is installed on the system second method is by giving the command.

Was this guide helpful?

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

📚 Related Tutorials

How to Install BoxBilling with Apache on Ubuntu Linux
Ubuntu Linux How to Install BoxBilling with Apache on Ubuntu Linux
How to Install GNOME Desktop on Ubuntu 24.04
Ubuntu Linux How to Install GNOME Desktop on Ubuntu 24.04
How to Install KDE Desktop on Ubuntu 24.04
Ubuntu Linux How to Install KDE Desktop on Ubuntu 24.04

No comments yet — be the first to share your thoughts!

Leave a Comment

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