How to Install Magento on Ubuntu 18.04

r00t June 23, 2018

Install Magento on Ubuntu 18.04

In this tutorial we are going to learn how to install Magento on Ubuntu 18.04. We will also install and configure its prerequisites. Magento open source is a flexible e-commerce platform for both developers and smaller businesses. The free open source edition includes all the functionality and features to fulfill the demands of the businesses of today. It’s the perfect platform for developing small company websites or anybody who wishes to understand and experiment with building an online shop.

I recommend to use a minimal Ubuntu server setup as a basis for the tutorial, that can be a virtual or a root server image with an Ubuntu 18.04 Bionic Beaver minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.

Install Magento on Ubuntu 18.04

Step 1. First, ensure your system and apt package lists are fully up-to-date by running the following:

apt-get update -y
apt-get upgrade -y

Step 2. Installing LAMP on Ubuntu 18.04.

You should check out this LAMP stack install tutorial for Ubuntu 18.04, if you haven’t installed LAMP yet. Once it’s installed, come back here and read on. We also will install the required packages for LAMP stack and the important PHP extension that Magento relies on:

apt-get install php7.2 libapache2-mod-php7.2 php7.2-common php7.2-mbstring php7.2-xmlrpc php7.2-soap php7.2-mysql php7.2-gd php7.2-xml php7.2-cli php7.2-zip

Step 3. Installing Magento on Ubuntu 18.04.

To install Magento, you must first register on the official Magento site. You will also need the login later to get access to the plug-ins. Once you’ve registered on, you will be taken to the “Products & Solutions” in the upper menu bar to” Products “-> “Community Edition” and then “Download Now”. For your servers you need the latest version of the “Full Release (ZIP with no sample data)”. For “Select your format”, I recommend the “Magento Community Edition 2.*.*.tar.gz”.

Unzip the file to the /var/www/magento/ directory:

tar -xzf magento-CE-2.*.*-****-**-**-**-**-**.tar.gz -C /var/www/

Afterwards, you just have to rename the folder you just created:

mv /var/www/ magento-CE-2.*.*-****-**-**-**-**-**.tar.gz /var/www/magento

Now just set the right permissions for the folders:

chown www-data:www-data –R /var/www/magento/*
cd /var/www/magento
find var vendor pub/static pub/media app/etc -type f -exec chmod g+w {} \;
find var vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} \;
chmod u+x bin/magento

Step 4. Create a database for Magento.

Next, we need to create a database for the Magento installation:

mysql -uroot -p

Run the following command to create a database for Magento:

MariaDB> CREATE USER 'cloud'@'localhost' IDENTIFIED BY 'magentopasswd';
MariaDB> GRANT ALL PRIVILEGES ON magento.* TO 'cloud'@'localhost';
MariaDB> exit

Step 5. Configure Apache web server for Magento.

For this you can take the default config as a template:

cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/magento.conf

Now edit the currently created Config as follows:

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

Modify the virtual host file for your Magento site to resemble the example below:

<VirtualHost my-domain.tld:80>

ServerName my-domain.tld
ServerAdmin webmaster@localhost
DocumentRoot /var/www/magento/

<Directory /var/www/magento/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All

ErrorLog ${APACHE_LOG_DIR}/error-magento.log
CustomLog ${APACHE_LOG_DIR}/access-magento.log combined

Now just activate the newly created Config, mod_rewrite and SSL:

sudo a2ensite magento.conf
sudo a2enmod rewrite

To load all the settings above, restart Apache2 by running the commands below:

sudo systemctl restart apache2.service

Step 6. Accessing Magento Web Installation.

Now you can access the Magento web install wizard in your browser by entering the domain name or http://your_ip/ to continue your Magento installation.

Congratulation’s! You have successfully install and configured Magento on your Ubuntu 18.04 LTS server. Thanks for using this tutorial for installing Magento open source e-commerce on Ubuntu 18.04 LTS (Bionic Beaver) system.


The Tags:

Leave a Comment

Comments are closed.