How to install Magento on Ubuntu 18.04

Need a powerful and flexible e-commerce solution in your data center? Look no further than Magento.

magentohero.jpg
Image: Magento

Magento is one of the most powerful e-commerce platforms available. And if you use Linux in your data centers, you can install the community edition of this powerhouse shopping system with relative ease. Once installed, your customized online store can sell your company products and services.

I'm going to walk you through the process of installing Magento on Ubuntu Server 18.04. The only thing you need is your Ubuntu Server platform installed and a user with sudo privileges. With those two things in hand, let's install.

SEE: Quick glossary: Storage (Tech Pro Research)

Update/upgrade

First, update and upgrade your server. Do note that, should the kernel be updated in the process, a restart of the server will be required. Because of this, run the update/upgrade process during a time when an update is possible.

To run the update/upgrade process, log into your Ubuntu server and issue the following command:

sudo apt-update
sudo apt-get upgrade -y

Should your kernel be upgraded, reboot the server and get ready to install.

Apache

The first thing to do is install Apache. Log back into your server and issue the following command:

sudo apt-get install apache2

Once that completes, start and enable the web server with the commands:

sudo systemctl start apache2
sudo systemctl enable apache2

MariaDB

The next step is to install the database. We'll use MariaDB. Install the database with the command:

sudo apt-get install mariadb-server mariadb-client -y

Once that completes, start and enable the database server with the commands:

sudo systemctl start mariadb
sudo systemctl enable mariadb

Secure the database installation with the command:

sudo mysql_secure_installation

Answer the necessary questions, making sure to create a password for the admin user.

With MariaDB installed, let's create the database, the user, and give the user the necessary permissions. Gain access to the database shell with the command:

mysql -u root -p

Issue the following commands at the prompt:

CREATE DATABASE magento;
CREATE USER 'magentouser'@'localhost' IDENTIFIED BY 'password;
GRANT ALL ON magento.* TO 'magentouser'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit

Where password is a unique/strong password.

PHP

Magento requires either PHP 7.0 or 7.1. We'll install 7.1. To do this, we must first install a dependency and the necessary repository with the commands:

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php

Update apt and install PHP with the commands:

sudo apt-get update
sudo apt-get install php7.1 php7.1-common php7.1-mbstring php7.1-xmlrpc php7.1-soap php7.1-gd php7.1-xml php7.1-intl php7.1-mysql php7.1-cli php7.1-bcmath php7.1-mcrypt php7.1-ldap php7.1-zip php7.1-curl php7.1-bcmath -y

Download Magento

Now we need to download the Magento Community Edition. A word of warning, you need to sign up for a Magento account before you can do this. Head over to the Magento CE download page, select your version (.tar, .bz2, or .zip), click Download, and then (when prompted) either sign up or sign in. I'm going to assume you've downloaded the .zip version of the file.

Once you've downloaded the file, do the following:

sudo mkdir /var/www/html/magento/
sudo mv ~/Downloads/Magento*.zip /var/www/html/magento
cd /var/www/html/magento
sudo unzip Magento*.zip

Give the newly created folder the proper permissions with the commands:

sudo chown -R www-data:www-data /var/www/html/magento
sudo chmod -R 755 /var/www/html/magento

Configure Apache

Create a new configuration file with the command:

sudo nano /etc/apache2/sites-available/magento.conf

In that file, paste the following content:

<VirtualHost *:80>
     ServerAdmin admin@example.com
     DocumentRoot /var/www/html/magento/
     ServerName example.com
     ServerAlias www.example.com

     <Directory /var/www/html/magento/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
     </Directory>

     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Save and close the file.

Finally, enable the Magento site and the rewrite module with the commands:

sudo a2ensite magento.conf
sudo a2enmod rewrite

Restart Apache with the command:

sudo systemctl restart apache2

Finish installation

You can now point your browser to http://SERVER_IP/magento. Click the Agree and Setup Magento button, and then walk through the installation wizard (Figure A).

Figure A

Figure A

The Magento installation wizard.


At the Web Configuration stage of the installation, you will get a Magento Address that will be in the form of http://SERVER_ADDRESS/magento/admin_STRING (Where SERVER_ADDRESS is either the IP or the domain of your server and STRING is a random string of characters). Make sure to note (or bookmark) that address, as you'll need it. On the last stage, click Install and step away from the machine (as installation can take some time).

Once the installation completes, you can then log into the Magento Admin Address and start putting the pieces of your store into place. Congratulations, you now have a powerful and flexible e-commerce solution in your data center.

Also see

By Jack Wallen

Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website jackwallen.com.