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.
1 |
sudo su |
Updating our Ubuntu distribution’s package list:
1 |
apt-get update |
Install and Configuring Apache Web Server:
We’ll require a web server which will be serving our Magento application to the world wide web.
1 |
apt-get install apache2 |
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.
1 |
sudo service apache2 restart |
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:
1 2 |
cd /etc/apache2/ nano apache2.conf |
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:
1 |
systemctl restart apache2.service |
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:
1 |
sudo a2enmod rewrite |
After executing it, again we’ll have to restart our apache2 web server to make the changes live:
1 |
sudo service apache2 restart |
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:
1 2 3 4 |
cd /tmp curl -OL https://dev.mysql.com/get/mysql-apt-config_0.8.3-1_all.deb sudo dpkg -i mysql-apt-config* rm mysql-apt-config* |
Now, we have downloaded it and extracted the .deb compressed file. Now we shall proceed with MySQL Installation.
1 |
sudo apt-get install mysql-server |
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:
1 |
mysql_secure_installation |
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:
1 |
mysqladmin -u root -p version |
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.
1 |
apt-get install libapache2-mod-php php-mysql php-dom php-simplexml php-curl php-intl php-xsl php-mbstring php-zip php-xml composer |
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:
1 |
apt-get install php7.0-gd |
Installing PHP MCrypt 7.0.x Extension:
1 2 3 |
sudo apt install php-dev libmcrypt-dev php-pear sudo pecl channel-update pecl.php.net sudo pecl install mcrypt-1.0.1 |
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:
1 |
sudo nano /etc/php/7.2/cli/php.ini |
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:
1 |
extension=mcrypt.so |
Installing PHP Composer for dependency management:
Composer is a PHP Dependency manager which we’ll be extensively using while installing the magento store.
1 |
apt-get install composer |
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”.
1 |
cd /var/www/html/ |
Then we’ll clone the Magento 2 git repository from Github:
1 |
git clone https://github.com/magento/magento2.git . |
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.
1 |
composer install |
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:
1 2 3 4 5 6 |
chmod -R 755 /var/www/html/magento2/ chmod -R 777 /var/www/html/magento2/var/ chmod -R 777 /var/www/html/magento2/pub/ chmod -R 777 /var/www/html/magento2/pub/ chmod -R 777 /var/www/html/magento2/app/etc chmod -R 777 /var/www/html/magento2/generated . |
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.