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:
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 DATABASE magento2;
CREATE USER 'magentip'@'localhost' IDENTIFIED BY 'yourpassword';
ALTER USER 'magentip'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT ALL PRIVILEGES ON *.* TO 'magentip'@'localhost' WITH GRANT OPTION;
exit;
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
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
</Directory>
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.
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
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.
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:
http://sitename.com/admin_l6ach9
You should now be able to access Magento, view your homepage using your URL – http://sitename.com 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 authentication:
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
After you add the new key, you will see Authenticator code in your application once you login to Magento 2 dashboard
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:
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.
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
51vote
Article Rating
Subscribe
Login and comment with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.
DisagreeAgree
Login and comment with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.
DisagreeAgree
Please login to comment
7 Comments
Most Voted
NewestOldest
Inline Feedbacks
View all comments
Peter Waugh(@peter_waugh)
Member
11 months ago
/home/713724.cloudwaysapps.com/xrsuqftxbe/public_html/magento2$ 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
Thanks for your feedback, did Step 2 – Download Magento2 Open Source files – download the Magento files successfully ?
Is there any files in /var/www/html ?
HI Andrew, I reinstalled as per instructions,
Another question before i get to that error, Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]? the only option is yes, to continue
Do you want to store credentials for repo.magento.com 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/713724.cloudwaysapps.com/xrsuqftxbe/public_html/magento2
Loading composer repositories with package information
Updating dependencies
Killed
/home/713724.cloudwaysapps.com/xrsuqftxbe/public_html/magento2$ 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
Hi Peter,
Thanks for your feedback, did Step 2 – Download Magento2 Open Source files – download the Magento files successfully ?
Is there any files in /var/www/html ?
HI Andrew, I reinstalled as per instructions,
Another question before i get to that error, Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]? the only option is yes, to continue
Do you want to store credentials for repo.magento.com 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/713724.cloudwaysapps.com/xrsuqftxbe/public_html/magento2
Loading composer repositories with package information
Updating dependencies
Killed
? should it say killed ?
Hi Peter, after doing a Google of the ‘Killed’ error its to do with composer running out of memory. Try the following suggestions on this thread – https://magento.stackexchange.com/questions/238225/magento-2-composer-runs-out-of-memory
Also what is the size of the VM you are currently using ?
thank you