Magento is a free and open-source eCommerce platform based on PHP and MySQL that is used by millions of small businesses to sell and manage their products online. If you want to create an online store, Magento might be the simplest way to do it, especially if you will need support from users to manage and maintain the store. Magento enables users to create a complete online store, including inventory management, product catalogs, shipping, invoicing, and many more. This tutorial is based on Ubuntu Linux. We’ll be installing the Nginx web server, MariaDB database server, and PHP modules. We’ll also link to another post that will show you how to secure your Magento website using Let’s Encrypt free SSL certificates. For more about Magento, please check its homepage To get started with installing Magento on Ubuntu Linux, follow the steps below:

How to install Nginx on Ubuntu Linux

As mentioned above, we’re going to be using the Nginx web server to run Magento. Magento requires a web server to function, and Nginx is one of the most popular open-source web servers available today. To install Nginx on Ubuntu, run the commands below: After installing Nginx, the commands below can be used to stop, start and enable Nginx services always to start up every time your server starts up. To test whether Nginx is installed and functioning, open your web browser and browse to the server’s IP address or hostname. http://localhost If you see the above page in your browser, then Nginx is working as expected.

How to install MariaDB on Ubuntu Linux

A database server is required for Magento to function. Magento stores its content in a database, and MariaDB is probably the best database server available to run Magento. MariaDB is fast, secure and the default server for almost all Linux servers. To install MariaDB, run the commands below: After installing MariaDB, the commands below can be used to stop, start and enable MariaDB services always to start up when the server boots. Next, run the commands below to secure the database server with a root password if you were not prompted to do so during the installation. When prompted, use the guide below to answer: To verify and validate that MariaDB is installed and working, log in to the database console using the commands below: You should automatically be logged in to the database server since we initiated the login request as root. Only the root can log in without password, and only from the server console. If you see a similar screen as shown above, then the server was successfully installed.

How to install PHP-FPM on Ubuntu Linux

As we also mentioned above, we’re installing PHP on Ubuntu since Magento requires it. PHP packages are added to Ubuntu repositories. The versions of the repositories might not be the latest. If you need to install the latest versions, you’ll need to add a third-party PPA repository. To a third-party repository with the latest versions of PHP, run the commands below. At the time of this writing, the latest PHP version is 8.0. Next, run the commands below to install PHP 8.0 and related modules. Once PHP is installed, the commands below can be used to start, stop and enable PHP-FPM services to automatically startup when the server boots. Next, you’ll want to change some PHP configuration settings that work great with Magento. Run the commands below to open the PHP default configuration file. Then change the line settings to be something like the lines below. Save your changes and exit.

How to create a Magento database on Ubuntu

At this point, we’re ready to create a Magento database. As mentioned above, Magento uses databases to store its content. To create a database for Magento, run the commands below: sudo mysql -u root -p Then create a database called magentodb CREATE DATABASE magentodb; Next, create a database user called magentodbuser and set a password CREATE USER ‘magentodbuser’@’localhost’ IDENTIFIED BY ’new_password_here’; Then grant the user full access to the database. GRANT ALL ON magentodb.* TO ‘magentodbuser’@’localhost’ WITH GRANT OPTION; Finally, save your changes and exit.

How to download Magento 2

We’re ready to download Magento and begin configuring it. First, run the commands below to download the latest version of Magento from its repository. To get Magento’s latest release you may want to use the GitHub repository. Install Composer, Curl and other dependencies to get started After installing curl and Composer above, change into the Nginx root directory and download Magento 2 packages from GitHub. When prompted, enter your authentication keys. Your public key is your username; your private key is your password….  ( https://marketplace.magento.com You’ll have to register for an account to create the key above. Then run the command below to allow the www-data user to own the Magento directory. Run the commands below to create a new project called Magento. Copy and paste the authentication key. (Your public key is your username; your private key is your password) After downloading Magento packages, run the commands below to install Magento with the following options:

The Magento software is installed in the root directory on localhost. Admin is admin;  therefore: Your storefront URL is https://exmaple.com The database server is on the same localhost as the webserver…. The database name is magento, and the magentouser and password is 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)

After that, run the commands below to set the correct permissions for Magento 2 to function.

How to configure Nginx for Magento

We have downloaded Magento content into a new folder we called Magento. Now, let’s configure Nginx to create a new server block to use with our Magento website. You can create as many server blocks with Nginx. To do that, run the commands below to create a new configuration file called Magento.conf in the /etc/nginx/sites-available/ directory to host our Magento server block. In the file, copy and paste the content below into the file and save. Save the file and exit. After saving the file above, run the commands below to enable the new file that contains our Magento server block. Restart Nginx after that. At this stage, Magento is ready and can be launched by going to the server’s IP or hostname. However, we want to make sure our server is protected with Let’s Encrypt free SSL certificates. So, continue below to learn how to generate a Let’s Encrypt SSL certificate for websites.

How to setup Let’s Encrypt for Magento

We have written a great post on how to generate and manage Let’s Encrypt SSL certificates for the Nginx web servers. You can use that post, to apply it here for your Magento website. To read the post on how to generate Let’s Encrypt SSL certificates for a website, click on the link below: How to Setup Let’s Encrypt on Ubuntu Linux with Nginx – Website for Students If you were successful in generating a Let’s Encrypt SSL certificate, you should then reopen the server block for our Magento website by running the commands below. The new Magento server block configurations should look similar to the line below. Take notes of the highlighted lines.

The first server block listens on port 80.  It contains a 301 redirect to redirect HTTP to HTTPS. The second server block listens on port 443. It contains a 301 redirect to redirect www to the non-www domain.

Save the file above, then restart Nginx and PHP using the commands below. Finally, if everything went as planned, you should be able to start Magento setup wizard by browsing to the server hostname or IP address over HTTPS. Next, open your browser and browse the server domain name. You should see the Magento homepage. You can now log in as an administrator and start customizing and building your store.

How to upgrade Magento 2

First, stop the webserver. In the future when you want to upgrade to a newly released version, simply run the commands below to upgrade… You may have to re-run the to update Nginx directory permissions. Conclusion: This post showed you how to install Magento 2 on Ubuntu Linux with a link to set up Let’s Encrypt. If you find any error above or have something to add, please use the comment form below.