YouTube Icon

Code Playground.

How to Install Magento 2 on Ubuntu 18.04

CFG

How to Install Magento 2 on Ubuntu 18.04

Magento is main employer-elegance e-commerce platform constructed on open-source era combining effective functions with flexibility and user-friendly interface.

With capabilities like Engaging Shopping Experiences, Flexible Modular Architecture and Enterprise-grade Scalability and Performance Magento is a platform of desire for most on line merchants.

In this tutorial, we will show you a way to set up Magento 2.3 on an Ubuntu 18.04 device. We’ll be the use of Nginx as a web server, the ultra-modern PHP 7.2 and MySQL/MariaDB as a database server.

Also Read:-How to implement DataTables Server-side Processing with CodeIgniter

Prerequisites
Ensure that you have met the subsequent prerequisites before continuing with this tutorial:

Have a domain call pointing in your public server IP. We will use example.Com.
Nginx is installed in your Ubuntu server with the aid of following these commands .
An SSL certificate installed in your area to encrypt person’s facts. You can deploy a free Let’s Encrypt SSL certificates by means of following these commands .

Also Read:-Shopping Cart Implementation in CodeIgniter
To be capable of get right of entry to to the Magento 2 code repository you’ll need to generate authentication keys. If you don’t have a Magento Marketplace account, you may create one right here . Once you create the account, please test those instructions on a way to generate a new set of authentication keys.
Update the system applications to the modern day variations and installation the unzip application :

sudo apt update && sudo apt upgrade
sudo apt install unzip

Also Read:-Delete Multiple Records from Database in CodeIgniter

Creating MySQL database
If you have MySQL or MariaDB installed on your server you could bypass this step, if not you can install the MySQL 5.7 server bundle from the Ubuntu’s default repositories by way of typing:

sudo apt install mysql-server mysql-client
Also Read:-Autocomplete Textbox in CodeIgniter using jQuery UI

For clean MySQL installations, it's miles advocated to run the mysql_secure_installation command to improve the security of your MySQL server.
Login to the MySQL shell the usage of the following command:

sudo mysql

From within the MySQL shell, run the following SQL announcement to create a new database named magento:

CREATE DATABASE magento;


Next, create a MySQL user account named magento and supply the essential permissions to the person through jogging the following command:

GRANT ALL ON magento.* TO 'magento'@'localhost' IDENTIFIED BY 'change-with-strong-password';
Also Read:-How to create Dynamic Dependent Dropdown in CodeIgniter using jQuery and Ajax

Make positive you convert trade-with-strong-password with a sturdy password.
Once completed, go out the MySQL console by way of typing:

EXIT;
Creating System User
Also Read:-How to develop RESTful Web Services in CodeIgniter

Create a brand new user and group, to be able to be Magento record machine proprietor , for simplicity we can name the person magento:

sudo useradd -m -U -r -d /opt/magento magento


Add the www-facts user to the magento group and exchange the /choose/magento directory permissions so that the Nginx can get admission to the Magento set up:

sudo usermod -a -G magento www-data
sudo chmod 750 /opt/magento


Also Read:-How to Generate SEO Friendly URL in CodeIgniter

Installing and Configuring PHP
PHP 7.2 which is the default PHP version in Ubuntu 18.04 is completely supported and advocated for Magento 2.Three. Since we can be the use of Nginx as a web server we’ll also set up the PHP-FPM package deal.

Run the following command to install PHP and all required PHP modules:

sudo apt install php7.2-common php7.2-cli php7.2-fpm php7.2-opcache php7.2-gd php7.2-mysql php7.2-curl php7.2-intl php7.2-xsl php7.2-mbstring php7.2-zip php7.2-bcmath php7.2-soap
Also Read:-Sending Email via SMTP Server in CodeIgniter

PHP-FPM provider will robotically begin after the installation process is whole, you may verify it by means of printing the carrier popularity:

sudo systemctl status php7.2-fpm

The output must indicate that the fpm carrier is active and running.

? php7.2-fpm.service - The PHP 7.2 FastCGI Process Manager
   Loaded: loaded (/lib/systemd/system/php7.2-fpm.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2018-12-12 15:47:16 UTC; 5s ago
     Docs: man:php-fpm7.2(8)
 Main PID: 16814 (php-fpm7.2)
   Status: "Ready to handle connections"
    Tasks: 3 (limit: 505)
   CGroup: /system.slice/php7.2-fpm.service
Also Read:-User Registration and Login System in CodeIgniter User Registration and Login System in CodeIgniter

Set the desired and advocated PHP options via enhancing the personal home page.Ini document with sed ::

sudo sed -i "s/memory_limit = .*/memory_limit = 1024M/" /etc/php/7.2/fpm/php.ini
sudo sed -i "s/upload_max_filesize = .*/upload_max_filesize = 256M/" /etc/php/7.2/fpm/php.ini
sudo sed -i "s/zlib.output_compression = .*/zlib.output_compression = on/" /etc/php/7.2/fpm/php.ini
sudo sed -i "s/max_execution_time = .*/max_execution_time = 18000/" /etc/php/7.2/fpm/php.ini
sudo sed -i "s/;date.timezone.*/date.timezone = UTC/" /etc/php/7.2/fpm/php.ini
sudo sed -i "s/;opcache.save_comments.*/opcache.save_comments = 1/" /etc/php/7.2/fpm/php.ini


Next we want to create a FPM pool for the magento consumer.

Open your textual content editor and create the subsequent file:

sudo nano /etc/php/7.2/fpm/pool.d/magento.conf

/etc/php/7.2/fpm/pool.d/magento.conf

Also Read:-How to Implement Captcha in CodeIgniter using Captcha Helper
[magento]
user = magento
group = www-data
listen.owner = magento
listen.group = www-data
listen = /var/run/php/php7.2-fpm-magento.sock
pm = ondemand
pm.max_children =  50
pm.process_idle_timeout = 10s
pm.max_requests = 500
chdir = /


Restart the PHP-FPM carrier for modifications to take effect:

systemctl restart php7.2-fpm

Also Read:-Create Custom URL Helper Function in CodeIgniter
Verify whether the PHP socket became successfully created with the aid of going for walks the subsequent ls command :

ls -al /var/run/php/php7.2-fpm-magento.sock

The output need to appearance some thing like this:

srw-rw---- 1 magento www-data 0 Dec 12 16:07 /var/run/php/php7.2-fpm-magento.sock=

Installing Composer
Composer is a dependency manager for PHP and we will be the use of it to download the Magento middle and installation all necessary Magento additives.

To install composer globally, down load the Composer installer with curl and flow the record to the /usr/neighborhood/bin listing

curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

Verify the set up by way of printing the composer version:

composer --version

Also Read:-How to Implement PayPal Payment Gateway in CodeIgniter
The output ought to look something like this:

Composer version 1.8.0 2018-12-03 10:31:16


Installing Magento
There are several approaches to install Magento 2. Avoid putting in Magento from the Github repository because that version is supposed for development and now not for manufacturing installations.

Also Read:-Live Editable table with jQuery AJAX in CodeIgniter

At the time of writing this newsletter, the present day solid model of Magento is model 2.Three.Zero. In this academic, we will set up Magento from their repositories using composer.

Switch over to the user magento by typing:

sudo su - magento


Start the set up with the aid of downloading magento documents to the /opt/magento/public_html listing:

composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition /opt/magento/public_html

You’ll be triggered to enter the access keys, copy the keys from your Magento market account and keep them in the auth.Json file, so later whilst updating your set up you don’t should upload the equal keys once more.

Also Read:-Export MySQL data to CSV file in CodeIgniter
Authentication required (repo.magento.com):
      Username: e758ec1745d190320ca246e4e832e12c
      Password: 
Do you want to store credentials for repo.magento.com in /opt/magento/.config/composer/auth.json ? [Yn] Y


The command above will fetch all required PHP applications. The system may take a few minutes and if it is a hit the give up of the output ought to appear to be the following:

Writing lock file
Generating autoload files

Also Read:-Insert record to Database Table – Codeigniter
Once the project is created we can begin the Magento set up. We can install Magento either from the command line or using the web Setup Wizard. In this academic, we’ll install Magento using the command line.

We will use the following options to put in the Magento store:

Base and Base comfortable URLs are set to https://example.Com, exchange it together with your domain.
Magento administrator:
John Doe as first and closing name.
John@example.Com as email.
John as username and j0hnP4ssvv0rD as password.
Database call magento, username magento, password change-with-robust-password and the database server is on the equal host as the web server.
En_US, US English as a default language.
USD greenbacks as default forex.
America/Chicago as a time quarter.
You can find all the set up options right here .
Change to the Magento ~/public_html directory:

cd ~/public_html
Also Read:-Codeigniter Get File Extension Before Upload

Run the following command to begin the installation:

php bin/magento setup:install --base-url=https://example.com/ \
        --base-url-secure=https://example.com/ \
        --admin-firstname="John" \
        --admin-lastname="Doe" \
        --admin-email="john@example.com" \
        --admin-user="john" \
        --admin-password="j0hnP4ssvv0rD" \
        --db-name="magento" \
        --db-host="localhost" \
        --db-user="magento" \
        --currency=USD \
        --timezone=America/Chicago \
        --use-rewrites=1 \
        --db-password="change-with-strong-password"


Don’t forget to change the password (j0hnP4ssvv0rD) to some thing greater comfy.
The technique may also take a couple of minutes and as soon as finished you may be presented with a message that carries the URI to the Magento admin dashboard.

[Progress: 773 / 773]
[SUCCESS]: Magento installation complete.
[SUCCESS]: Magento Admin URI: /admin_13nv5k
Nothing to import.

Also Read:-Codeigniter Form Validation with Error Message

Creating Magento crontab
Magento uses cron jobs to schedule responsibilities like re-indexing, notifications, sitemaps, emails and greater.

To create the Magento crontab run the following command as magento person:

php ~/public_html/bin/magento cron:install
Crontab has been generated and saved

Also Read:-How to fetch single row from database in php codeigniter?
Verify that the crontab is established by way of typing:

crontab -l
#~ MAGENTO START adc062915d7b30804a2b340095af072d
* * * * * /usr/bin/php7.2 /opt/magento/public_html/bin/magento cron:run 2>&1 | grep -v "Ran jobs by schedule" >> /opt/magento/public_html/var/log/magento.cron.log
* * * * * /usr/bin/php7.2 /opt/magento/public_html/update/cron.php >> /opt/magento/public_html/var/log/update.cron.log
* * * * * /usr/bin/php7.2 /opt/magento/public_html/bin/magento setup:cron:run >> /opt/magento/public_html/var/log/setup.cron.log
#~ MAGENTO END adc062915d7b30804a2b340095af072d

Configuring Nginx
By now, you have to have already got Nginx with SSL certificates mounted on your Ubuntu server, if not take a look at the stipulations for this educational.

Also Read:-How to change date format in PHP Codeigniter?

We are going to include the default Nginx configuration shipped with Magento.

Switch over for your sudo person, open your text editor and create the subsequent document:

sudo nano /etc/nginx/sites-available/example.com

/etc/nginx/sites-available/example.com

upstream fastcgi_backend {
  server   unix:/var/run/php/php7.2-fpm-magento.sock;
}

server {
    listen 80;
    server_name example.com www.example.com;

    include snippets/letsencrypt.conf;
    return 301 https://example.com$request_uri;
}

server {
    listen 443 ssl http2;
    server_name www.example.com;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
    include snippets/ssl.conf;
    include snippets/letsencrypt.conf;

    return 301 https://example.com$request_uri;
}

server {
    listen 443 ssl http2;
    server_name example.com;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
    include snippets/ssl.conf;
    include snippets/letsencrypt.conf;

    set $MAGE_ROOT /opt/magento/public_html;
    set $MAGE_MODE developer; # or production

    access_log /var/log/nginx/example.com-access.log;
    error_log /var/log/nginx/example.com-error.log;

    include /opt/magento/public_html/nginx.conf.sample;
}

Don’t overlook to update instance.Com together with your Magento domain and set an appropriate course to the SSL certificates documents. The snippets used in this configuration are created on this guide .
Before restarting the Nginx service make a check to ensure that there aren't any syntax mistakes:

sudo nginx -t

Also Read:-Crop Image Before Upload Codeigniter 3 Example
If there aren't any errors the output need to seem like this:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful


Finally, restart the Nginx provider through typing:

sudo systemctl restart nginx

Also Read:-How to get last executed query in PHP Codeigniter?
Verifying the Installation
Open your browser, type your domain and assuming the set up is a success, a display screen much like the subsequent will seem:
You can now go to the Magento Admin URI, log in because the admin user and begin customizing your new Magento set up.

Also Read:-How to Connect a MySQL Database in NodeJS

Conclusion
Congratulations, you've got efficiently installed Magento 2.3 for your Ubuntu 18.04 server. You can now begin customizing your save.

Magento 2.3 Developer Documentation is a superb beginning location to learn more about the way to manage your Magento installation.

If you've got questions, sense unfastened to go away a remark beneath.




CFG