Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: Install Magento on Ubuntu 16.04  (Read 1156 times)

0 Members and 2 Guests are viewing this topic.

jibinw

  • Guest
Install Magento on Ubuntu 16.04
« on: May 30, 2018, 12:42:16 am »
Introduction

Magento is an eCommerce open source software, and a content management system for eCommerce websites. It uses MySQL 5.6+ or MariaDB as possible databases, and it’s compatible with both NGINX and Apache web servers. It also requires PHP7+ and some of its extensions.
This tutorial demonstrates how to install Magento 2 on an Ubuntu 16.04 server using NGINX and MySQL.

Update the server

Code: [Select]
# apt update
Install NGINX

NGINX is available on Ubuntu repository, so you can easily install it with apt:

Code: [Select]
# apt install nginx
Install PHP

Since you are likely hoping that the site will be accessed by many visitors, it’s better to install PHP-FPM (FastCGI Process Manager), which has various features. So, install it and the extensions required by Magento:

Code: [Select]
# apt install php7.0-mcrypt php7.0-fpm php7.0-curl php7.0-mysql php7.0-cli php7.0-xsl php7.0-json php7.0-intl php7.0-dev php-pear php7.0-mbstring php7.0-common php7.0-zip php7.0-gd php-soap
Install curl as well:

Code: [Select]
# apt install curl libcurl3
Editing PHP settings

Modify the two configuration files:

Code: [Select]
    /etc/php/7.0/fpm/php.ini – FPM configuration;
    /etc/php/7.0/cli/php.ini – PHP-CLI configuration file;

In both, add the following lines (or edit if already existing):

Code: [Select]
memory_limit = 2G
max_execution_time = 3600
opcache.save_comments = 1
zlib.output_compression = On

Save, exit and restart PHP-FPM so that changes will be applied:

Code: [Select]
# systemct restart php7.0-fpm
Install and configure MySQL

To install MySQL, execute the following command:

Code: [Select]
# apt install -y mysql-server mysql-client
Next, set up a root account for it:

Code: [Select]
# mysql_secure_installation
Code: [Select]
Set root password? [Y/n]
New password:
Re-enter new password:
Remove anonymous users? [Y/n]
Disallow root login remotely? [Y/n]
Remove test database and access to it? [Y/n]
Reload privilege tables now? [Y/n]

If importing a large numbers of products into Magento is required, just increase the value for the max_allowed_packet option using the following code:

Code: [Select]
# $EDITOR /etc/mysql/mysql.cnf
There, search for the mentioned line, and modify as follow:

Code: [Select]
[mysql]
max_allowed_packet=64M

Save, exit and restart MySQL:

Code: [Select]
# systemctl restart mysql
Next, start a MySQL command prompt:

Code: [Select]
# mysql -u root -p
Create a new user and database:

Code: [Select]
mysql> CREATE DATABASE magento_db;
mysql> CREATE USER 'magentousr'@'localhost' IDENTIFIED BY 'user_strong_password';
mysql> GRANT ALL PRIVILEGES ON 'magento_db.*' TO 'magentousr'@'localhost' IDENTIFIED BY 'user_strong_password';
mysql> FLUSH PRIVILEGES;
mysql> EXIT;

Downloading Magento

Magento 2 will be installed in the /var/www/magento2 directory. The installation requires PHP Composer. Install PHP Composer by executing the following command:

Code: [Select]
# curl -sS https://getcomposer.org/installer | php
Move the composer.phar file to /usr/local/bin:

mv composer.phar /usr/local/bin/composer

Test that everything is going smoothly so far with:

Code: [Select]
# composer -v
This should print out the composer version.

To obtain Magento (the Community Edition, in this tutorial), first go to https://www.magentocommerce.com/magento-connect/ and create an account there. Next, follow My Account > Developer > Secure Keys, and generate new keys.

Now it’s time to download Magento. On a terminal, execute the following command:

Code: [Select]
# composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition /var/www/magento2
During this process, use the public key for username and the private key for the password.

Configure a Virtual Host

Create a new Virtual Host file:

Code: [Select]
# $EDITOR /etc/nginx/sites-available/magento
In the Host File, paste the following configuration:

Code: [Select]
upstream fastcgi_backend {
        server  unix:/run/php/php7.0-fpm.sock;
}

server {

        listen 80;
        server_name www.myecommerce.com;
        set $MAGE_ROOT /var/www/magento2;
        set $MAGE_MODE developer;
        include /var/www/magento2/nginx.conf.sample;
}

Magento already contains an NGINX configuration file, so it’s not necessary to create one.

Save and exit.
Next, activate the virtual host:

Code: [Select]
# ln -s /etc/nginx/sites-available/magento /etc/nginx/sites-enabled/
Restart NGINX:

Code: [Select]
# systemctl restart nginx
Install Magento


In /var/www/magento2 there is a binary file named magento. This will be used for installing Magento 2.
Execute:

Code: [Select]
# /var/www/magento2/bin/magento setup:install --backend-frontname="admin" \
--key="cja8Jadsjwoqpgk93670Dfhu47m7rrIp"\
--db-host="localhost" \
--db-name="magento_db" \
--db-user="magentousr" \
--db-password="usr_strong_password" \
--language="en_US" \
--currency="USD" \
--timezone="My/Timezone" \
--use-rewrites=1 \
--use-secure=0 \
--base-url="http://www.myecommerce.com" \
--base-url-secure="https://www.myecommerce.com" \
--admin-user=admin \
--admin-password=admin_password \
--admin-email=admin@myecommerce.com \
--admin-firstname=admin \
--admin-lastname=user \
--cleanup-database
At the end:

Code: [Select]
[SUCCESS]: Magento installation complete.
[SUCCESS]: Magento Admin URI: /admin

Final configuration

 The last step is a “graphical configuration” through a web browser. Go to www.myecommerce.com/admin, and log in with the admin credentials you created during the installation process.
After signing in the Magento Dashboard should appear, signifying that everything went well. The ecommerce web site is now ready to be filled with products!