How to Setup Magento Server on Azure/AWS/GCP

To setup and install Magento 2 open source server on any of the cloud platforms, the recommended way is to deploy using the server image available in the marketplace. It comes pre-installed with Apache Web Server, MySQL Server, all the required PHP modules and ElasticSearch.  View the links below to deploy to your cloud environment:

Magento Cloud Server

Setup Magento Server on Azure


Deploy Magento on Ubuntu Server 20.04

install magento server on azure

Setup Magento Server on AWS


Deploy Magento on Ubuntu Server 20.04

install magento server on aws

Setup Magento Server on GCP


Deploy Magento on Ubunt Server 20.04

install magento server on gcp

Getting Started


Once your Magento server has been deployed, the following links explain how to connect to a Linux VM:



Once connected and logged in, you’re ready to start configuring Magento.

Setting up Magento Community Open Source 2.4 Server

This solution is built using Apache Web Server, MySQL 8 Server and PHP 7.4.

1.) Create a MySQL database for Magento installation

We need to run the following commands to setup a MySQL database using MariaDB Server. 


First we need to set the root mysql password (currently password is blank), run the following command and follow the onscreen instructions to set a new root password.  Press enter when it asks to provide a password.

					sudo mysql_secure_installation

Next we run the following command to create a new database called magento2 with a new user called magentip with password yourpassword that will be used by Magento. 

					sudo mysql


CREATE USER 'magentip'@'localhost' IDENTIFIED BY 'yourpassword';

ALTER USER 'magentip'@'localhost' IDENTIFIED BY 'yourpassword';



2.) Create Magento Access Key

In order to setup magento 2.4 you will require access keys. Sign up for a free account on the following link and create a new access key. You will receive a private and public key that we will use to setup Magento


magento access keys

3.) Configure Apache2 Virtual Host for Magento Site


We need to configure the default Apache host config for our Magento site.


Open the 000-default.conf file:


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


Copy and paste the following into your 000-default.conf file:


DocumentRoot /var/www/html/magento2/
<Directory /var/www/html/magento2/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all

Edit config using VIM editor


Press Shift + I to insert the text into the 000-default.conf file using the VIM editor.  To save and exit, press ESC key and type :wq!


Enable Apache Rewrite


Once you have saved the 000-default.conf and exited back to terminal, we need to enable the Apache rewrite module by running the following command:


sudo a2enmod rewrite


Restart Apache Service


Now restart Apache by running the following command:


sudo systemctl restart apache2

Update PHP.ini File


Next you need to make sure the following entries are configured within your php.ini file.  Run the following command to open your php.ini file:

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

Search through the file and making sure the following are configured:

					file_uploads = On
allow_url_fopen = On
short_open_tag = On
memory_limit = 256M
upload_max_filesize = 100M
max_execution_time = 360
date.timezone = America/Chicago

Then restart Apache service:


sudo systemctl restart apache2

4.) Install Magento into Apache vhost directory


Now we need to run through the Magento installation. We will be using Composer and the Magento access keys we created earlier.


Your access keys will be used as follows:


Username: Your public key

Password: Your private key


Step 1 – Change terminal session path


Make sure the current directory your terminal session is in magento web root directory:


cd /var/www/html


Step 2 – Download Magento2 Open Source files


Run the following command.  It will take some time to download.

					sudo composer create-project --repository= magento/project-community-edition=2.4.3 magento2

You will be prompted for a username and password, this is where you use your Magento access keys as follows:


Username: Your public key

Password: Your private key


magento composer install


Step 3 – Set Magento folder permissions


You must set read-write permissions for the web server group before you install the Magento software. This is necessary so that the command line can write files to the Magento file system.


sudo chown -R www-data:www-data /var/www/html/magento2/

sudo chmod -R 755 /var/www/html/magento2/

cd /var/www/html/magento2
sudo find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +
sudo find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +
sudo chown -R :www-data . 
sudo chmod u+x bin/magento


Step 4 – Restart Elasticsearch


sudo systemctl start elasticsearch
sudo systemctl enable elasticsearch


Step 5 – Install Magento


Make sure you’re currently in your Magento directory


cd /var/www/html/magento2


Run the following command and amend the details to match your URL, database details, passwords, etc

sudo bin/magento setup:install \
--base-url= \
--db-host=localhost \
--db-name=magento2 \
--db-user=magentip \
--db-password=youmysqlpassword \
--admin-firstname=Admin \
--admin-lastname=Admin \ \
--admin-user=admin \
--admin-password=admin123 \
--language=en_US \
--currency=USD \
--timezone=America/Chicago \

Step 5 – Setup Cron Jobs


Magento is using cron jobs to automate important operations. Lets setup the cron jobs.

					sudo bin/magento cron:install

Magento Admin Login


Once the install is complete, you will see the following, make a note of the admin URL as this is the unique URL you will use to login to the Admin portal:


In my example, my admin login would be as follows:



You should now be able to access Magento, view your homepage using your URL – or the servers IP



Magento Login – Two Factor Authorization


The first time your login to the admin section, you may get an error about configuring two-factor authenticationmAGENTO-LOGIN:



This error happened because since Magento 2.4, Two-Factor Authorization is enabled by default.


There are 2 ways to fix this:


  • Method 1: Disable Two-Factor Authorization
  • Method 2: Install and enable Two-Factor Authorization

Method 1 – Disable Two-Factor Authorization:


If you don’t need Two-Factor Authorization, run this command within your magento directory to disable it

sudo php bin/magento module:disable Magento_TwoFactorAuth
You should now be able to login.

Method 2 – Enable Two-Factor Authorization


If you wish to use two-factor authorization, follow these step to enable this feature.


First, run this command within your Magento directory to force Magento 2.4 to use Google as the Two-factor authorization provider


sudo bin/magento config:set twofactorauth/general/force_providers google


Next, generate a Base32-encoded string for the OTP secret key. You can use some online tool for this. For example:


Input a normal password like: mypassword and you will receive a Base32-encoded string like this: NV4XAYLTON3W64TE


magento base-32-encode


Next, we will add the secret encoded OTP key to Google Authenticator with this command


sudo bin/magento security:tfa:google:set-secret admin <code>NV4XAYLTON3W64TE</code>


Now open Google Authenticator App on your mobile: and add new key: NV4XAYLTON3W64TE


After you add the new key, you will see Authenticator code in your application once you login to Magento 2 dashboard

Google authenticator-app


Enter the code you you receive in authenticator app to login to admin dashboard



Apply Latest Magento Security Patches

As of Feb 12 2022, for Magento versions 2.4.3-p1 and earlier versions a security patch should be applied as per APSB22-12 (CVE-2022-24086, CVE-2022-24087)


First create a folder within the Magneto2 root directory:  /var/www/html/magento2

					sudo mkdir hotfix
cd hotfix

Download the 2 required patches to your new hotfix directory:

					sudo wget

sudo wget

Now extract to contents of these zip files and copy the contents back to the Magento root directory:

					sudo unzip
sudo unzip

sudo cp MDVA-43395_EE_2.4.3-p1_COMPOSER_v1.patch /var/www/html/magento2/
sudo cp MDVA-43443_EE_2.4.2-p2_COMPOSER_v1.patch /var/www/html/magento2/

cd ..


Within the magento2 root directory run the following commands to apply the patches:

					sudo patch -p1 < MDVA-43395_EE_2.4.3-p1_COMPOSER_v1.patch

sudo patch -p1 < MDVA-43443_EE_2.4.2-p2_COMPOSER_v1.patch

For the changes to be reflected, refresh the cache in the Admin under System > Cache Management.

Magento Firewall Ports


Magento uses the following firewall ports:


  • TCP Port 80 – http
  • TCP Port 443 -https
  • TCP Port 9200 – ElasticSearch


To setup AWS firewall rules refer to – AWS Security Groups

To setup Azure firewall rules refer to – Azure Network Security Groups

To setup Google GCP firewall rules refer to – Creating GCP Firewalls

Support / Documentation


Its recommended to perform the following post setup configurations for Magento


Further documentation and support can be found on the following link:


Disclaimer: Magento is a registered trademark of Magento, Inc. and is licensed under Open Software License (OSL 3.0). No warrantee of any kind, express or implied, is included with this software. Use at your risk, responsibility for damages (if any) to anyone resulting from the use of this software rest entirely with the user. The author is not responsible for any damage that its use could cause.
Avatar for Andrew Fitzgerald
Andrew Fitzgerald

Cloud Solution Architect. Helping customers transform their business to the cloud. 20 years experience working in complex infrastructure environments and a Microsoft Certified Solutions Expert on everything Cloud.

5 1 vote
Article Rating
Notify of
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Peter Waugh

/home/$ sudo find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +
find: ‘var’: No such file or directory
find: ‘generated’: No such file or directory
find: ‘vendor’: No such file or directory
find: ‘pub/static’: No such file or directory
find: ‘pub/media’: No such file or directory
find: ‘app/etc’: No such file or directory

Peter Waugh

HI Andrew, I reinstalled as per instructions,
Another question before i get to that error, Do not run Composer as root/super user! See for details
Continue as root/super user [yes]? the only option is yes, to continue

Peter Waugh

Do you want to store credentials for in /root/.config/composer/auth.json ? [Yn] y
Installing magento/project-community-edition (2.4.2)
 – Downloading magento/project-community-edition (2.4.2)
 – Installing magento/project-community-edition (2.4.2): Extracting archive
Created project in /home/
Loading composer repositories with package information
Updating dependencies

? should it say killed ?

Peter Waugh

thank you

Would love your thoughts, please comment.x