Skip to content
Follow
CMS

How to Install Magento with Nginx on Ubuntu 24.04

Richard
Written by
Richard
May 31, 2024 Updated Sep 15, 2026 8 min read
Magento featured image
Magento featured image

Magento with Nginx on Ubuntu 24.04 creates a fast online store that handles heavy visitor traffic without slowing down. Magento is a free e-commerce platform for running online shops, and Nginx is a high-speed web server that serves pages quickly.

Advertisement

Pairing these tools gives you a secure setup with strong performance for your shoppers. You need a server running Ubuntu 24.04, root access, and basic command-line knowledge to complete the installation.

⚡ Quick Answer

Install Nginx, MariaDB, and PHP using apt commands. Then, create a dedicated Magento database and user within MariaDB. Finally, configure Nginx to serve your Magento application.

Advertisement

Install Nginx HTTP server on Ubuntu Linux

You can install Nginx on Ubuntu 24.04 by opening your terminal and running the standard package update and installation commands. Nginx acts as the web server to load your store pages for visitors. Type sudo apt update and then sudo apt install nginx to get the software running on your system.

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

🐧Bash / Shell
sudo apt update
sudo apt install nginx

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

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

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

Advertisement

http://localhost

Nginx default welcome page on Ubuntu 24.04
Nginx default welcome page on Ubuntu 24.04

When you see the Welcome to nginx! page means the Nginx HTTP server has been successfully installed.

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

How to install Nginx on Ubuntu

Advertisement

Install MariaDB database server on Ubuntu Linux

You can install MariaDB on Ubuntu 24.04 to store all your store data, products, and customer accounts. Open your terminal and run the package manager commands to download and set up the database server software. This gives Magento the backend storage it needs to save information securely.

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.

Advertisement
🐧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.

Advertisement

Create a Magento database

You can create a Magento database by logging into your MariaDB shell and running a simple SQL command to set up empty storage named magentodb. This database holds all your catalog items, orders, and site settings. Make sure to note your database name and login details for the final installation steps.

The Magento database acts as the central storage for all Magento application content and data, making the database a critical component of the setup process.

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

The magentodbuser account receives full permissions for the magentodb database to ensure Magento can properly manage your store's data.

Advertisement

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
⚠️WarningEnsure to replace ‘type_your_password_here‘ with your password.
Advertisement

Install PHP on Ubuntu Linux

You can install PHP and the required modules on Ubuntu 24.04 by running the apt package manager command with the necessary extension names. Magento needs these specific extensions, such as php-mysql and php-xml, to process code and communicate with your database. Run the apt install command with the complete list of modules to avoid errors.

Run the commands below to install PHP.

🐧Bash / Shell
sudo apt install php-fpm 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

You can download Magento files using Composer, a tool that manages project software and dependencies on Ubuntu. First, install curl and git on your system, then download and run the Composer installer script. This pulls the correct Magento core files directly into your web server directory.

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
📝Good to KnowBefore 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, please change it to the Nginx 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
  • 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.

Correct permissions, a crontab, and Magento indexing are essential for Magento's smooth operation. Run the commands below to set these permissions and generate the necessary crontab, ensuring Magento can process data efficiently.

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 Nginx for Magento

You can configure Nginx for Magento by creating a new virtual host configuration file inside your sites-available directory. This file tells the web server where to find your store files and how to handle requests properly. Open the nano text editor using sudo to create and save your site rules.

Run the commands below to create a Nginx virtual host file for Magento.

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

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

🐘PHP
upstream fastcgi_backend {
server unix:/var/run/php/php8.3-fpm.sock;
}

server {
listen 80;
listen [::]:80;
index index.php;
server_name magento.example.com www.magento.example.com;

set $MAGE_ROOT /var/www/magento;

access_log /var/log/nginx/example.com-access.log;
error_log /var/log/nginx/example.com-error.log;

include /var/www/magento/nginx.conf.sample;

}

Save the file.

Nginx server blocks are configurations that tell Nginx how to handle requests for different websites. Run the following commands to enable the Nginx server block for your Magento installation and then restart the Nginx server so it recognizes the new configuration.

🐧Bash / Shell
sudo ln -s /etc/nginx/sites-available/magento.conf /etc/nginx/sites-enabled/
sudo systemctl restart nginx.service

Setup Let’s Encrypt SSL/TLS for Magento

You can set up a free Let's Encrypt SSL certificate with Nginx to secure your Magento checkout and customer data with HTTPS. Install the Certbot plugin on Ubuntu to automatically request and apply your security certificates. This encrypts traffic between your visitors and the web server.

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

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

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

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

💻Code
https://magento.example.com

Magento default welcome page will appear.

Magento default welcome page after installation
Magento default welcome page after installation

That should do it!

Conclusion:

Conclusion:

  • Installing Magento with Nginx support on Ubuntu 24.04 can significantly improve performance, resource utilization, and user experience.
  • Integrating Nginx, MariaDB, and PHP creates a robust foundation for efficiently hosting a Magento application.
  • The steps for setting up databases, creating a Magento database, installing PHP, downloading Magento files, and configuring Nginx are comprehensive and well-documented.
  • The addition of Let’s Encrypt SSL/TLS provides an essential layer of security for the Magento installation.
  • For any errors or additional information, the comments section is open for further discussion and support.

Was this guide helpful?

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.

Advertisement

📚 Related Tutorials

How to Install Nginx on Ubuntu Linux
Ubuntu Linux How to Install Nginx on Ubuntu Linux
How to Install Magento with Apache on Ubuntu 24.04
CMS How to Install Magento with Apache on Ubuntu 24.04
Install MySQL and MariaDB on Ubuntu: A Step-by-Step Guide
Ubuntu Linux Install MySQL and MariaDB on Ubuntu: A Step-by-Step Guide
How to Install GNOME Desktop on Ubuntu 24.04
Ubuntu Linux How to Install GNOME 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 *