Installing Magento on Ubuntu 17.04

Magento is a powerful eCommerce platform written in PHP. It enables individuals to setup eCommerce and online store in minutes. This brief tutorial is going to show students and users an easy way to get Magento working on Ubuntu 17.04

Magento is written in PHP but also requires web and database servers. This can be accomplished using the LAMP stack. LAMP is a synonym for Linux, Apache2, MySQL and PHP.

So, without wasting anymore of your time, let’s get started with installing Magento on Ubuntu. To do that, follow the steps below:

Step 1: Ubuntu 17.04

Since Ubuntu is easier to manage and maintain, lets use it as our Linux server. This post assumes you already have Ubuntu installed and is functioning properly. Before continuing with installing the server packages below, let’s update Ubuntu first. To do that, run the commands below:

sudo apt-get update && sudo apt-get dist-upgrade && sudo apt-get autoremove

Restart your server and login back in.

Step 2: Installing Apache2

Now that Ubuntu is updated and ready, run the commands below to install Apache2 web server.

sudo apt-get install apache2

After installing Apache2, the below commands show you how to stop, start and enable Apache2

sudo systemctl stop apache2.service
sudo systemctl start apache2.service
sudo systemctl enable apache2.service

Continue below to install MySQL.

Step 3: Installing MySQL

Now that Apache2 is installed, run the commands below to install MySQL database server

sudo apt-get update
sudo apt-get install mysql-server mysql-client

During the installation of MySQL, you’ll get a prompt to create and confirm a new password for the database root user. Please do.

After installing the database server, run the commands below to secure it.

sudo mysql_secure_installation

You’ll be prompted with series of questions, please follow the guide below to answer

Enter password for user root: ENTER PASSWORD
Press y|Y for Yes, any other key for No: n
Change the password for root ? ((Press y|Y for Yes, any other key for No) : n
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y

Continue below to configure Magento database and user.

Step 4: Configuring Magento Database and User

Magento uses databases to store its content. Database user accounts are used to manage and retrieve the stored content. Continue below to create a database called magentodb and a user called magentouser.

Run the commands below to logon to the database server

sudo mysql -u root -p

Then run the commands below to create a new database called magentodb

CREATE DATABASE magentodb;

Then run the commands below to create a new user account called magentouser and give the account full access to the newly created database

GRANT ALL ON magentodb.* TO 'magentouser'@'localhost' IDENTIFIED BY 'type_new_password_here';

After that, run the commands below to save your changes and exit

FLUSH PRIVILEGES;
exit;

Next, continue below to install PHP and other PHP modules

Step 5: Installing PHP and Modules

At this point, you should have Apache2 and MySQL installed and configured. The final packages to install are PHP and its modules. To do that, run the commands below.

sudo apt-get install php php-fpm libapache2-mod-php php-mysql php-curl php-mcrypt php-xml php-intl php-mbstring php-zip php-gd

Next, continue below to download Magento content

Step 6: Download Magento Content

After installing all the required packages, continue below to download Magento content. The content can be downloaded from the link below

[button-green url=”https://magento.com/tech-resources/download” target=”_self” position=”center”]Button text[/button-green]

You’ll probably want to download the community edition. After downloading, run the commands below to extract it to Apache2 default home directory.

sudo tar -zxvf ~/Downloads/Magento-CE-2.1.6-2017-03-29-01-08-05.tar.gz -C /var/www/html/

Next, run the commands below to set the appropriate files and folder permissions to the root directory

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

Make sure to remove Apache2 default index.html page.

sudo rm /var/www/html/index.html

Open apache2 default configuration file by running the commands below:

sudo nano /etc/apache2/sites-available/000-default.conf

Next add the highlighted lines, then save the file.

<VirtualHost>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

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

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

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

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

Next, enable Apache2 rewrite module.

sudo a2enmod rewrite

Restart Apache2 by running the commands below

sudo systemctl restart apache2.service

After that, open your web browser and browse to the server IP or hostname followed by setup.

http://localhost/setup/

You should see Magento setup wizard to complete. Please follow the wizard carefully.

magento ubuntu install

Continue with the wizard

magento ubuntu installation

Enter the database information

magento database connection

Create a new admin account to manage magento

magento admin account

Continue until you’re done.

magento install ubuntu

Enjoy!

You may also like the post below:

Installing MySQL Latest Versions on Ubuntu 17.04