Magento2 Installation

Magento2 – Step by Step Guide to Installation on Ubuntu Server with Performance Tweaking

Magento is a full-featured E-commerce platform written in PHP which is highly scalable turned out to be the conclusion of our evaluation of our client’s E-commerce project. The open source E-commerce platform has numerous features ranging from being a slick content management system to being a highly customizable E-commerce platform facilitator.

Here are some of the features at a glance:

  • Site Management
  • Catalog Management
  • Catalog Browsing
  • Product Browsing
  • Checkout, Payment and Shipping
  • Order Management
  • Customer Accounts
  • Customized Analytics and Reporting
  • …and many other highly useful features.

In this tutorial, we are going to see how one can install Magento 2 (v2.3) on an Ubuntu VPS server. You can opt for AWS or DigitalOcean or any other VPS of your preference.

Prerequisites for Magento 2 Installation:

  • A Web Host (preferably a Linux VPS or Linux Dedicated Server) with administrator control.
  • Apache or Nginx Web Server (we’ll be using Apache for the sake of simplicity)
  • PHP 7.2.x
  • MySQL 5.6 or 5.7
  • Basic knowledge about how to use SSH to login.
  • And we’ll be installing tons of useful high performance extensions to support our Magento platform.

Magento 2 Installation:

Assuming you have logged into your Ubuntu server via SSH. We’ll now proceed to prepare our server for installation.

Preparing our Ubuntu Server:

Before installing/updating anything we will be accessing the super user (su) so that we can manage every aspect of the Ubuntu server.

Updating our Ubuntu distribution’s package list:

Install and Configuring Apache Web Server:

We’ll require a web server which will be serving our Magento application to the world wide web.

After we have downloaded the Apache package and installed it, we’ll need to confirm if the apache2 module is running and working. To perform  confirmationc we’ll be restarting the apache web server.

Hopefully your restart works without any error or problems, if in case it does not, then you’ll have to again update your Ubuntu Package which we have covered in the beginning.

After installation we’ll have to enable the public entry to apache2 web server:

This command will open the apache2 configuration file. Search for Indexes , then change AllowOverride from none ‘ to all ’. And save the file. You’ll have to press CTRL + X to save and exit from nano Ubuntu text editor.

After configuring we’ll have to restart the web server service to make the changes in effect:

Enabling Apache Rewrite Module for Pretty URLs:

Pretty URLs enable us to have more SEO friendly URLs. To enable this in apache2 we’ll have to execute this command:

After executing it, again we’ll have to restart our apache2 web server to make the changes live:

Installing and configuring MySQL as our relational database:

First, we’ll have to download the MySQL Software repository from github and then begin with the installation of it. Here are the commands which need to be executed:

Now, we have downloaded it and extracted the .deb compressed file. Now we shall proceed with MySQL Installation.

After running this command it will install the extracted .deb file on our server.

Let’s quickly make our MySQL installation safe and secure by executing:

and hit [ENTER] on your keyboard. This will run the quick installation wizard in your console.

You’ll be asked to set the root username and password for your MySQL installation.

Ensure that your password is long and strong and you are not using common usernames such as “root” or “admin” or “system”.

Quickly testing your MySQL Installation:

Run the following command in your console to test your MySQL installation:

If you are being asked for the password and after entering in the correct credentials, it will display the MySQL version details. Which confirms that our installation is correct.

Installing PHP and it’s extensions:

Magento is built on top of PHP and utilizes various extensions of PHP. We’ll be installing the extensions to ensure our installation of Magento does not break and the extensions help Magento achieve superior performance.

This command will install the following things:

  • libapache2-mod-php
  • php-mysql
  • php-dom
  • php-simplexml
  • php-curl
  • php-intl
  • php-xsl
  • php-mbstring
  • php-zip
  • Php-xml

After installing the above extension we’ll also need to install php-mcrypt for encryption, and php-gd for manipulating images (used for watermarks, editing, effects etc.). We are installing it separately cause we’ll be using the latest 7.0.x builds for these extensions rather than the 5.6.x versions.

Installing PHP GD 7.0.x Extension:

Installing PHP MCrypt 7.0.x Extension:

We’ll have to manually include the Mcrypt extension to our php.ini because we are downloading the MCrypt extension from the PECL (PHP Extension Community Library).

Manually including MCrypt extension:

From your SSH server execute this command:

This will open the php.ini file for you in the nano ubuntu console text editor. At the second line below “[PHP]” line add this code:

Installing PHP Composer for dependency management:

Composer is a PHP Dependency manager which we’ll be extensively using while installing the magento store.

Downloading Magento 2 from Github:

Because the humongous size of Magento 2 Package we’ll choose to download the Magento package directly from github and avoid downloading it manually and uploading via FTP.

To do so, first we’ll have to navigate of the public directory of our web server. In Ubuntu 18.0.x that directory is called “html”.

Then we’ll clone the Magento 2 git repository from Github:

This command will now begin the downloading process of Magento 2 inside our current html folder.

Installing Magento 2 Installation Modules:

Next we’ll remain in the same directory and start the installation of Magento 2 modules through composer.

Allowing writable access to the Magento 2 folders:

We’ll need to allow “write” access of 755 or 777 (if you are sure you are the only user who will access it) to the newly generated Magento 2 folders.

Allow Access:

And we are ready to go…

Now our server side installation process and completed. We’ll now need to install it from the front end, which is very much similar to installing any other CMS or PHP Script.

To do so, navigate to your domain and you’ll hopefully see the Magento simple installation wizard. Just follow the instructions given on the installation wizard and your fresh Magento website will be up and ready to go live!

Some Performance Recommendations:

For superior Magento 2 performance I would suggest for you to refer the following points:

 

  • Have a standalone host for your relational database: Relational database systems such as MySQL performs various memory intensive queries which can slow down your Magento 2 eCommerce store. Hence a different host for your database and a different host for your Magento 2 application would enhance performance of your store.

 

  • Enabling Caching in Magento 2: Once you have made all your changes to the Magento 2 application then it is highly recommended to enable caching in your application. This will result in Magento making static files for your store pages and products which will utilize less server memory. To enable caching in your Magento 2 application you can do it by executing this command: magento cache:enable [type] or can use the Admin panel in the backend to enable it.

 

  • Extend server memory: According to Magento 2 website, it is recommended to have at least 2 GB of memory for your Magento application to work efficiently. But for blazing fast performance and scalability it is better to have at least 3 or 4 GB of memory for your magento application.

Leave a Comment

Your email address will not be published. Required fields are marked *