How to install Magento 2 on Ubuntu?

The installation of Magento 2 on Ubuntu may be challenging. Today we will consider how to do it step-by-step.

Step 1. First off, you need to make sure that your system meets all the Magento 2 requirements. Here are the main points:

  • Composer
  • Web server: Apache 2.4 
  • Database: MySQL 8.0
  • PHP 7.4.0 with the necessary extensions installed
  • Elasticsearch 7.6.x
  • SSL

Also, to make your installation process secure, set up the Magento file system owner on the server.

→ ?onfused with Magento 2 server settings? Check our server configuration service

Step 2. After preparations are done, you need to get the Magento software. You can do it by using Composer or by downloading the archive. 

If you are using Composer, change to the web server docroot directory with the command:

cd <web server docroot directory>

Then, create a new project with the meta-package:

composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition <install-directory-name>

Authenticate by entering the keys that you can set up in Magento Marketplace.

Step 3. Next, you need to change permissions to read-write. Otherwise, you won’t be able to install Magento files via the command line. The process will be different for shared and private hostings. Let’s see how to configure permissions for shared hosting.

1) Set write permissions for the following directories:

  • vendor
  • app/etc
  • pub/static
  • var
  • Generated

→ Follow the guide to set the right permissions

2) Then, open the command line and enter the commands:

cd <magento_root>
find var generated vendor pub/static pub/media app/etc -type f -exec chmod u+w {} +
find var generated vendor pub/static pub/media app/etc -type d -exec chmod u+w {} +
chmod u+x bin/magento

3) Next, switch to the Magento file system owner with the command:

su <username>

Step 4. Now, we will go directly to the process of installing Magento 2 on Ubuntu.

For this, run the command:

bin/magento setup:install --base-url=http://example.com/ \
--db-host=localhost --db-name=magento --db-user=magento --db-password=magento \
--admin-firstname=Magento --admin-lastname=Admin [email protected] \
--admin-user=admin --admin-password=12345 --language=en_US \
--currency=USD --timezone=America/Chicago --use-rewrites=1 \
--search-engine=elasticsearch7 --elasticsearch-host=es-host.example.com \
--elasticsearch-port=9200

The admin’s first and last names are Magento Admin, username - admin, password - 12345, e-mail - [email protected]. The Magento 2 will be installed to the /var/www/html/magento2 folder, and the storefront URL will be http://example.com/. The database name, the username, and the password are magento

The default store language is U.S. English, the currency is USD, the time zone is the U.S. Central

Elasticsearch 7 is connected through port 9200.

→ Learn how to improve store security with native and advanced tools

Step 5. Finally, you need to verify that everything works correctly. For this, open your website frontend with the http://example.com/ URL and try to log in to the admin panel with the admin’s username and password.

How can we help you?

Didn’t you find the answer to your question? We are always happy to help you out.

© 2009-2024 Amasty. All Rights Reserved.