How to install Magento2 on Ubuntu Server ?

admin/ March 18, 2016/ Linux, Magento2/ 3 comments

Install LAMP (Linux Apache Mysql Php) on Ubuntu Server.

Add ppa for the php 5.6 and mysql 5.6.

sudo apt-get install -y software-properties-common
sudo add-apt-repository -y ppa:ondrej/php5-5.6
sudo add-apt-repository -y ppa:ondrej/mysql-5.6
sudo apt-get update

Install required packages using below commands.

sudo apt-get install -y apache2 php5 php5-mysql php5-mcrypt mysql-server php5-intl php5-xsl php5-gd php5-curl
sudo php5enmod mcrypt
 sudo nano /etc/php5/apache2/php.ini

Find the line which declares the memory limit for PHP and change it to your desired number (in this case, 512MB).

memory_limit = 512M

add the below line bottom of the file or remove the comments quote from php.ini
always_populate_raw_post_data = -1

sudo nano /etc/apache2/apache2.conf

Replace the below line -:

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

To

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

Enable apache rewrite module.

sudo a2enmod rewrite

To restart apache server

sudo service apache2 restart

Or

sudo /etc/init.d/apache2 restart

Create Database
Now login to your mysql server with admin privileges and create a database and user for new magento 2 installation.

$ mysql -u root -p

mysql> CREATE DATABASE magento2_db;
mysql> GRANT ALL ON magento2_db.* TO magento2_usr@'localhost' IDENTIFIED BY 'password';
mysql> FLUSH PRIVILEGES;
mysql> quit

Magento2 setup via github development.
download the magento2 zip
https://github.com/magento/magento2
Note-: click on download zip

 unzip magento2-2.0.zip
 cd magento2-2.0

or
Git Clone using below command.

 git clone https://github.com/magento/magento2.git 
 cd magento2-2.0

Run command to install the magento2 dependencies.

 composer install

if composer is not installed.
(use the below command to install composer)

curl -sS https://getcomposer.org/installer | php 
mv composer.phar /usr/local/bin/composer
sudo chmod 0755 /usr/local/bin/composer

if prompt while composer install

Installing magento/composer (1.0.2)
    Authentication required (repo.magento.com):
      Username: 
      Password:

Register on https://magento.com/
Login with your email and password.
Click on “My Account” > “Connect” tab > Secure Key
You will find the Public Key and Private key.
Add key using or regenerate and use in below
magento2_setup

 nano ~/.composer/auth.json

or

 vi ~/.composer/auth.json
{
   "github-oauth": {
     "github.com": ""
   },
   "http-basic": {
      "repo.magento.com": {
         "username": "",
         "password": ""
      }
   }
}

To change the permission of current directory.

sudo chmod -R 755 .

Edit .htaccess file of main folder and set RewriteBase with your application directory name.

 RewriteBase /magento2/

Follow the Magento Installer Steps.
Your Magento2 Setup is ready.

http://< ip > /magento2-2.0/
http://< localhost >/magento2-2.0/

Schedule Magento2 Cronjobs

Finally schedule the backgound cronjobs for your magento2 installation. These cronjobs does some activities like, re-indexing, Newsletters, Update of currency rates, sending automatic emails and generating sitemaps etc. To schedule these jobs edit crontab file

$ crontab -e

and add below cronjobs at the end of file and save it.

*/1 * * * * www-data php /var/www/html/magento2/bin/magento cron:run
*/1 * * * * www-data php /var/www/html/magento2/update/cron.php
*/1 * * * * www-data php /var/www/html/magento2/bin/magento setup:cron:run

3 Comments

  1. Thanks for sharing this tutorial. I doubt it will work though, because this will install MySQL 5.5 whereas Magento 2 requires MySQL 5.6.

    1. Hi Nick Weisser,
      Thanks for the suggestion. Please use the below ppa to install Mysql 5.6 installation.

      sudo apt-get install -y software-properties-common
      sudo add-apt-repository -y ppa:ondrej/php5-5.6
      sudo add-apt-repository -y ppa:ondrej/mysql-5.6
      sudo apt-get update
      sudo apt-get install -y mysql-server php5

      I have also updated in my blog.

      Thanks again

  2. Hello thx you for your article ! i was in a troube since 1 week for install magento on my local server. thx a lot

Leave a Reply