Install Magento 2 Manually on your VPS

Install Magento 2 Manually on your VPS

The process to install Magento 2 is a task that many online businesses need to know how to do. Magento 2 is a top choice, offering immense customization for your online shop. In this guide, we'll teach you how to install Magento 2.4 on a virtual private server (VPS) with Ubuntu 20.04. So, let's dive right in!

Key takeaways

  • Learn how to install Magento 2.4.5 manually on a Virtual Private Server (VPS).
  • The installation includes preparing the server environment, setting up the web server, database, PHP, and search engine.
  • The process of configuring Magento's admin panel is also outlined.
  • Post-installation steps and optimization tips are provided to enhance store functionality and performance.
  • The guide also answers some frequently asked questions related to Magento installation.

Preparing the Environment

1. System Requirements

hero for install magento 2

Before installing Magento 2.4.5 on a VPS running Ubuntu 20.04, it's crucial to ensure that your server meets the necessary system requirements. These requirements include:

  • Minimum 2 GB of RAM
  • At least 20 GB of free disk space
  • A compatible web server (such as Apache or NGINX)
  • PHP 8.1
  • MySQL 8.0
  • Elasticsearch 7.17 or OpenSearch 1.2

Note: Check the latest system requirements based on your Magento 2 version.

2. Upgrade the Operating System

To ensure the best performance and compatibility, it's important to upgrade the operating system on your VPS before installing Magento 2.4.5. To do so, follow these steps:

  1. Update your package list by running: sudo apt update
  2. Upgrade your packages to the latest version: sudo apt upgrade
  3. Reboot your server: sudo reboot

Now, your VPS is running the latest version of Ubuntu 20.04, ensuring a stable and secure software environment.

3. Install Software for a Production Environment

To create a suitable production environment for Magento 2.4.5, you'll need to install several essential software packages:

  1. Web server: Install either Apache or NGINX, depending on your preference. For example, to install Apache, run: sudo apt install apache2

  2. MySQL: Install the MySQL server by running: sudo apt install mysql-server

  3. PHP: Install PHP and the required extensions by running: sudo apt install php php-cli php-common php-curl php-gd php-intl php-mbstring php-mysql php-soap php-xml php-zip

  4. Elasticsearch or OpenSearch: Install the search engine of your choice, either Elasticsearch 7.17 or OpenSearch 1.2. For Elasticsearch, you can follow the official installation guide.

After installing the required software, ensure that all services are running and properly configured. You can then proceed with the Magento 2.4.5 installation process.

Setting Up the Web Server, Database, and PHP

In this section, we will provide step-by-step instructions on how to install the web server, install MySQL, and install PHP to set up a Magento server. These steps are crucial for preparing your environment to run Magento 2.4.5.

1. Install the Web Server (Apache)

First, update the package lists for upgrades and new package installations:

sudo apt update

Next, install the Apache web server:

sudo apt install apache2

Enable the Apache mod_rewrite module for Magento's URL rewriting:

sudo a2enmod rewrite

Configure the web server docroot by editing the Apache configuration file:

sudo nano /etc/apache2/sites-available/000-default.conf

Update the DocumentRoot to point to your Magento installation directory, e.g., /var/www/html/magento2:

DocumentRoot /var/www/html/magento2

Save and close the file. Then, restart the Apache service:

sudo systemctl restart apache2

2. Install MySQL 8.0 Server

Import the MySQL APT repository GPG key:

sudo dpkg -i mysql-apt-config_0.8.17-1_all.deb

Update the package lists:

sudo apt update

Install MySQL 8.0 server:

sudo apt install mysql-server

Secure your MySQL installation:

sudo mysql_secure_installation

Create a new MySQL user and database for Magento:

sudo mysql -u root -p
CREATE USER 'magento_user'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON magento.* TO 'magento_user'@'localhost';

3. Install PHP 8.1 and Required Extensions

Add the Ondřej Surý PPA repository to install PHP 8.1:

sudo add-apt-repository ppa:ondrej/php
sudo apt update

Install PHP 8.1 and the required extensions for Magento:

sudo apt install php8.1 php8.1-common php8.1-opcache php8.1-cli php8.1-gd php8.1-mysql php8.1-soap php8.1-xml php8.1-intl php8.1-mbstring php8.1-xmlrpc php8.1-zip php8.1-curl php8.1-bcmath

Edit the php.ini configuration file for Apache:

sudo nano /etc/php/8.1/apache2/php.ini

Update the following settings to meet Magento's requirements:

memory_limit = 2G
upload_max_filesize = 100M
zlib.output_compression = On

Save and close the file. Restart the Apache service:

sudo systemctl restart apache2

Now, your environment is set up with the required web server, database, and PHP to run Magento 2.4.5. Proceed to the next steps for installing a search engine and Magento 2.

Installing Magento 2 and Configuring the Admin Panel

In this section, we will walk you through the process of installing Magento 2.4.5, including creating a project repository, using composer, and setting up the Magento admin panel. By following these step-by-step instructions, you will have a fully functional Magento installation in no time.

1. Create a Project Repository with Composer

To begin the installation process, use the composer create-project command to create a new Magento project repository. Composer is a dependency management tool that simplifies the process of managing and installing Magento 2 and its required packages.

composer create-project --repository-url= magento/project-community-edition /path/to/your/magento2

Replace /path/to/your/magento2 with the desired installation path for your Magento 2 project.

2. Magento Authentication Keys

During the installation process, you will be prompted to provide your Magento authentication keys. These keys are necessary for accessing Magento's repository and downloading required packages. To generate your authentication keys, sign in to the Magento Marketplace, navigate to "My Profile," and click on "Access Keys" under the "Magento" tab.

Create a new set of keys and copy both the "Public Key" and the "Private Key" for use during installation. These keys will serve as your username and password when prompted by Composer.

3. Install Magento 2

After creating your project repository and obtaining your authentication keys, run the following command to begin the Magento installation process:

bin/magento setup:install --base-url= --db-host=localhost --db-name=magento --db-user=magento --db-password=magento --admin-firstname=YourFirstName --admin-lastname=YourLastName --admin-user=admin --admin-password=admin123 --language=en_US --currency=USD --timezone=America/New_York --use-rewrites=1

Replace the placeholders with your actual domain, database credentials, and admin user information. This command sets up your Magento 2 instance with your specified configurations.

4. Configure the Admin Panel

After the successful installation of Magento 2, you will receive a URL for your admin panel in the command line output. Access the admin panel by navigating to the provided URL in your web browser.

To secure your admin panel, it is recommended to change the default admin URL to a custom one. You can do this by editing the app/etc/env.php file and modifying the frontName value under the backend section.

After making these changes, clear the cache by running:

bin/magento cache:clean

Now, you can access your admin panel using the new custom URL. By following these instructions, you have successfully installed Magento 2.4.5 and configured the admin panel. With these steps completed, you are now ready to start building your Magento store.

Post-Installation and Optimization

Setting Post-Installation File Permissions

After successfully installing Magento 2, it's crucial to set the correct post-installation file permissions to ensure the security and proper functioning of your online store. To do this, navigate to your Magento installation directory and set the appropriate permissions for files and folders:

  1. Set the ownership of the entire Magento installation directory to the web server user.
  2. Set the permissions for directories to 755 and files to 644.

Expanding Advanced Modules Configuration

To further enhance your Magento store, you can expand advanced modules configuration to include additional features and functionalities. This may involve installing and configuring various Magento extensions, such as payment gateways, shipping integrations, and marketing tools. Remember to thoroughly test each extension before deploying it on your production site to ensure compatibility and optimal performance.

Embracing Component-Based Architecture

Implementing a component-based architecture in your Magento store can greatly reduce extension conflicts and compatibility issues. This approach focuses on building your store using modular components that can be easily added, removed, or replaced without affecting the entire system. This results in a more stable, maintainable, and scalable eCommerce platform.

Utilizing Robust Dependency Management

To further minimize conflicts and ensure seamless integration of various components, it's essential to employ robust dependency management in your Magento store. This involves carefully managing the dependencies between different extensions and modules, ensuring that they work together harmoniously without causing conflicts or breaking the entire system.

By focusing on setting the correct file permissions, expanding advanced modules configuration, embracing a component-based architecture, and utilizing robust dependency management, you can create a stable, efficient, and scalable eCommerce platform that meets your business needs and provides an excellent user experience for your customers.

FAQs: Magento 2 Installation

1. How can I install Magento 2 using the command line?

To install Magento 2, navigate to your install directory using 'cd var www html magento install directory'. Then, run the 'php bin magento' command.

2. How to manually install Magento using Magento software?

After downloading the Magento software, use the 'composer create project repository' command to create your project repository. Then, perform 'curl ss https getcomposer. org installer php' to get the Composer Installer.

3. How to install Magento 2 on the server using the command line?

Using the command line, navigate to 'cd var www html magento install directory'. Then run 'root bin magento setup install base url http' to initiate the installation.

4. How to install Magento on shared hosting using php bin magento?

In your shared hosting server, navigate to your Magento install directory using 'cd var www html magento install directory'. Then, run 'php bin magento setup install base url http'

5. How to find the Magento Install Directory?

After installing Magento, the install directory is usually located in the 'var/www/html' directory of your server. Navigate to it using the 'cd /var/www/html/magento2' command from your terminal.

6. What are the common Magento commands for installation?

There are various useful commands for Magento installation:

  • php bin/magento setup:install : This command is used to install Magento.
  • sudo apt update : This updates your package lists for new installations.
  • sudo apt upgrade : This upgrades your packages to the latest version.

You can simply put these commands into your terminal to run them.

7. How to access Magento Admin Panel?

To access the admin panel of your Magento installation, you will use the admin URL provided during the installation. This is generally your domain followed by the admin path. For example, if your domain is '' and your admin path is 'admin', the URL to access Magento Admin Panel would be ''.

8. How to change Magento Admin Path?

To change the admin path for security reasons, you need to edit your 'app/etc/env.php' file. Look for the 'backend' section, and then change the 'frontName' to your new admin path. Once done, clear the cache by running: 'bin/magento cache:clean' command in your terminal.

9. How to secure my Magento installation?

Securing your Magento installation can be done in several ways, such as changing default admin paths, using two-factor authentication, employing strong passwords, keeping your system updated, and setting correct file permissions. For instance, to set file permissions, navigate to your Magento installation directory and set the permissions for directories to 755 and files to 644.

10. Can I use XAMPP for Magento Installation?

Yes, Magento can be installed locally on a XAMPP server. However, this is typically done for development and testing purposes. For live ecommerce stores, it's recommended to use a secure and fully-fledged web server, such as Apache or Nginx.

11. How do XAMPP Control Panel and Magento work together?

XAMPP Control Panel is a local server software that allows you to test and develop your websites on your local machine including Magento store. It provides a complete development environment with Apache Server, PHP, and MySQL. After installing XAMPP, a Magento store can be set up in 'htdocs' folder of XAMPP and can be accessed using 'http://localhost/magento2'.

12. How are Public and Private Keys used in Magento Installation Process?

Public and Private keys serve as your username and password while accessing Magento's repository and downloading required packages during Magento's installation process. After creating a Magento account, you can generate these keys in the 'Magento Marketplace' under the 'Access Keys' option in 'My Profile'.

13. How does the System Path impact the Magento Installation?

The system path refers to the location in your server where Magento is installed. It's specified during the installation process and important for running Magento commands and organizing Magento files. Typically, it's '/var/www/html' in a Linux-based server.

14. How is the Base URL used in Magento?

The base URL is the address where your Magento store can be accessed by users. During installation, the base URL is defined and it's usually in the format ''. It's crucial to correctly set this up to ensure your store is accessible.

15. How to manage Write Permissions for Magento Files?

After installation, Magento files and directories should be set to correct file permissions to secure them. Directories should have 755 permissions and files should have 644 to remove write permissions for other users. This can be done using the chmod command in Linux.

16. How can I Install Sample Data for Magento with Xampp?

With a XAMPP setup, you install Magento's sample data by clonning it through composer. Navigate to the Magento installation directory in 'xampp/htdocs' and run these commands in order:

  1. composer create-project --repository-url= magento/project-community-edition:2.4.0 .
  2. bin/magento sampledata:deploy
  3. php bin/magento setup:install --base-url=http://localhost/magento2/

Ensure to replace necessary placeholders with your information.

17. What is Component Based Architecture in Magento?

Component-based architecture is a method of Magento store development that stresses modularity. It means Magento is broken down into individual components (modules), each of which can be developed, tested, and updated individually. This reduces conflicts, enhances performance and makes the management of your store a lot easier.

18. What is the Function of Magento MetaPackage?

The Magento metapackage is a package that includes Magento software along with other elements such as themes, language packages, and modules. It's the core package needed to install Magento and it's downloaded during the installation process using composer.

19. How to Install Adobe Commerce on Xampp Server?

The installation process of Adobe Commerce (formerly Magento Commerce) is identical to that of Magento Open Source and it can be installed on XAMPP for development and testing. After setting up XAMPP server, you use composer to download Adobe Commerce metapackage and proceed to normal Magento installation steps.


When you need to install Magento 2, having a clear, step-by-step guide makes the process easier. This tutorial shows how to manually set up Magento 2.4.5 on a VPS. It walks you through the whole process, from preparing the environment and ensuring it meets all system requirements and steps to setting up the web server, database, and PHP.

The piece doesn't just end post-installation; it also presents useful tips for improving your store and optimizing its performance. Want to take it a step further and run your store at high speed? Check out managed Magento hosting services and start building your ecommerce store today!

Nikita S.
Nikita S.
Lead Technical Writer

As a lead technical writer, Nikita S. is experienced in crafting well-researched articles that simplify complex information and promote technical communication. She has expertise in cloud computing and holds a specialization in SEO and digital marketing.

Get the fastest Magento Hosting! Get Started