Install Magento on a Linux Server with Ubuntu 16.04

Leave your reply


Magento is the world's most popular ecommerce platform, with an active community of users and developers and a substantial marketplace of plug-ins and other extensions. Learn how to install the free, open-source Magento CE (Community Edition) on Ubuntu 16.04.


  • A server with Ubuntu 16.04, PHP 5.6+ and MySQL 5.6+ installed.

Use the command php -v to check your PHP version:

user@localhost:~# php -v
PHP 7.0.22-0ubuntu0.16.04.1 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.22-0ubuntu0.16.04.1, Copyright (c) 1999-2017, by Zend                                                                          Technologies

In this example, the server is running PHP version 7.0.22.

Use the command mysql -V to check your MySQL version:

user@localhost:~# mysql -V
mysql  Ver 14.14 Distrib 5.7.20, for Linux (x86_64) using  EditLine wrapper

In this example, the server is running MySQL version 5.7.


  • PHP and MySQL are installed and running on a standard Linux installation by default. If your server was created with a minimal installation, you will need to install and configure PHP and MySQL before you proceed.

  • Magento requires PHP version 5.6 or better. To use Magento on a CentOS 7 server, one option is to follow the steps in our article to Upgrade PHP From 5.4 to 7.0 on a CentOS 7 Server.

  • Magento is also provided to Cloud Server customers as a ready-to-use application for new servers (CentOS 7 only).

Prepare the Server

Connect to the server with SSH, then update your system:

sudo apt update && sudo apt upgrade

Enable Apache's mod_rewrite:

sudo a2enmod rewrite

Install Magento's PHP dependencies:

sudo apt install mysql-client php-soap php7.0-common php7.0-gd php7.0-intl php7.0-zip php7.0-mcrypt php7.0-curl php7.0-xsl php7.0-mbstring php7.0-iconv 

Next, you will need to enable .htaccess files. Open the /etc/apache2/apache.conf file for editing:

sudo nano /etc/apache2/apache2.conf

Find the /var/www/ Directory section:

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted

Change AllowOverride to All:

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted

Save and exit the file.

Restart Apache for the changes to take effect:

sudo systemctl restart apache2

Create a MySQL Database and User

Connect to the server with SSH, then log in to the MySQL command line client:

mysql -u root -p

Create a MySQL database for Magento:

CREATE DATABASE [database name];

For example, to create a database named my_magento the command is:


Create a user for this database with the command:

GRANT ALL ON [database name].* TO [user name]@localhost IDENTIFIED BY '[password]';

For example, to create a user magento_user for the my_magento database with password Pn80dZIBAi the command is:

GRANT ALL ON my_magento.* TO magento_user@localhost IDENTIFIED BY 'Pn80dZIBAi';

Exit MySQL:


Download, Uncompress, and Set Permissions on the Magento Files

Log in to the Magento Tech Resources website and download the latest .tar.gz version of Magento CE.

Use FTP to upload this file to the website's root directory on your server. Then connect to the server with SSL and go to this directory, for example:

cd /var/www/html

Uncompress the Magento install file with the command:

sudo tar -xvf [install file name]

For example, the command to uncompress the file Magento-CE-2.2.1-2017-11-03-11-34-40.tar.gz is:

sudo tar -xvf Magento-CE-2.2.1-2017-11-03-11-34-40.tar.gz

After the files have been uncompressed, set the ownership for the Magento files:

sudo chown -R www-data:www-data .

Then set the file permissions:

sudo find . -type d -exec chmod 700 {} \;
sudo find . -type f -exec chmod 600 {} \;

Complete the Magento Installation

Visit the URL of your Magento installation in a browser. You will see the Magento admin page. Click Agree and Setup Magento to continue.

Install Magento on Ubuntu 16.04

Click to start the readiness check.

Install Magento on Ubuntu 16.04

After passing the readiness check, click Next to continue.

Install Magento on Ubuntu 16.04

Leave Database Server Host at the default localhost. Fill out the database user name, password, and database name. Then click Next to continue.

Install Magento on Ubuntu 16.04

Make sure that the Web Configuration settings are correct. Then click Next to continue.

Install Magento on Ubuntu 16.04

Set your store's default time zone, currency, and language. Then click Next to continue.

Install Magento on Ubuntu 16.04

Create an admin account for your Magento installation. For security reasons, we recommend you NOT choose admin as the user name.

Click Next to continue.

Install Magento on Ubuntu 16.04

Click Install Now to complete the installation.

Install Magento on Ubuntu 16.04

Magento will be installed.

Add the Magento Cron Job

This cron job will automatically reindex the site, which Magento requires for optimal functionality. It is set to run once every minute, as per the official Magento suggestion.

Open the crontab file for editing:

sudo crontab -e

Add the following lines to the file. If you installed Magento in a directory other than /var/www/html be sure to change the file path accordingly:

* * * * * /usr/bin/php /var/www/html/bin/magento cron:run | grep -v "Ran jobs by schedule" &gt;&gt; /var/www/html/var/log/magento.cron.log
* * * * * /usr/bin/php /var/www/html/update/cron.php &gt;&gt; /var/www/html/var/log/update.cron.log
* * * * * /usr/bin/php /var/www/html/bin/magento setup:cron:run &gt;&gt; /var/www/html/var/log/setup.cron.log

Save and exit the file.