Log in
Let’s talk business

Install Magento 2 ubuntu 18.04

Avatar image of Maarten Maarten
November 7, 2022
Magento is a popular open-source e-commerce platform based on the Zend framework and written in PHP. This guide will walk you through the steps to install and configure Magento on your Linux/Ubuntu 18.04 server.

Magento is a popular open-source e-commerce platform based on the Zend framework and written in PHP. This guide will walk you through the steps to install and configure Magento on your Linux/Ubuntu 18.04 server.


PHP 5.6.19 + + + + + + + + + + + + + +

+ MySQL 5.6


2 GB RAM is recommended.


The first step is to set up Apache2.

Use the following commands to install and configure Apache:

$ sudo apt install apache2

$ sudo systemctl start apache2

$ sudo systemctl enable apache2

Step 2: Create and configure a new Apache virtual host.

Make a new magento.conf configuration file.

$ sudo vim /etc/apache2/sites-available/magento.conf

In the newly created config file, paste the following code.

<VirtualHost *:80>

     ServerAdmin admin@domain.com

     DocumentRoot /var/www/html/magento/

     ServerName domain.com

     ServerAlias www.domain.com

     <Directory /var/www/html/magento/>

        Options Indexes FollowSymLinks MultiViews

        AllowOverride All

        Order allow,deny

        allow from all


     ErrorLog ${APACHE_LOG_DIR}/magento_error.log

     CustomLog ${APACHE_LOG_DIR}/magento_access.log combined


You can now debug all Magento setup-related errors in the magento error.log and magento access.log files.

Step 3: Turn on the Rewrite mod.

$ sudo a2ensite magento.conf

$ sudo a2enmod rewrite

Step 4:

Installing PHP and its dependencies

To install the required PHP dependencies, use the following command:

$ sudo apt install php7.2 libapache2-mod-php7.2 php7.2-common php7.2-gmp php7.2-curl php7.2-soap php7.2-bcmath php7.2-intl php7.2-mbstring php7.2-xmlrpc php7.2-mcrypt php7.2-mysql php7.2-gd php7.2-xml php7.2-cli php7.2-zip

Open the php.ini configuration file.

$ sudo vim /etc/php/7.2/apache2/php.ini

Change the credentials as follows:

file_uploads = On

allow_url_fopen = On

short_open_tag = On

memory_limit = 512M

upload_max_filesize = 128M

max_execution_time = 3600

Restart the Apache web server.

$ sudo systemctl restart apache2

Step 5: Install MySQL Server

Set up a MySQL server

$ sudo apt install mysql-server

Create a root password for MySQL.

– Following the installation, a temporary password will be produced in the mysqld.log file, which you can view using the command below.

$ sudo grep 'temporary password' /var/log/mysqld.log

– You will now receive a notice similar to this.

[Note] For root@localhost, a temporary password is generated: b*-rkuIR4Zasd

– For the following step, copy this password.

– Type the following command.

$ sudo mysql_secure_installation

– When prompted to confirm your password, select Y.

– You will then be prompted to set the strength of your password. Choose from the following options: LOW, MEDIUM, or STRONG.

– Type in a new password

– You can accept all of the prompts that follow this one.

– You’ll be asked a series of questions on how to set up the MySQL installation. All of the prompts can be set to Y.

– You will be able to log in as root with a blank password.

Connect to MySQL.

$ sudo mysql -u root -p

Create a Magento database and populate it with users.

mysql > create database magento;

mysql > CREATE USER 'magentouser'@'localhost' IDENTIFIED BY 'password';

mysql > GRANT ALL PRIVILEGES ON * . * TO 'magentouser'@'localhost';


mysql > exit;

Install composer as the sixth step.

To install Magento and its dependencies, you’ll need Composer.

To install composer globally on your Ubuntu machine, run the following command:

$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

$ sudo php composer-setup.php --install-dir=/usr/bin/ --filename=composer

Use the following command to check the composer installation:

$ composer -v

Step 7: Use your Magento marketplace user account to obtain / generate secret keys. (Only required for composer installation.)

You’ll need to enter Public and Private keys from your Magento market-place account in order to install Magento in the next step. You can register here if you haven’t already.

Here is where you can access Magento Marketplace.

Select your username from the dropdown menu in the top navbar > My Personal Information

Select [Access Keys] from the drop-down menu.

Select [Create A New Access Key] from the drop-down menu.

Enter a name for the key and click “Generate.”

Your Public and Private keys will be generated after that. Use them for the following step’s installation.

Step 8: Download and install Magento

Composer is used during installation.

Enter the root directory of your server.

cd /var/www/html

To install Magento, use the composer command.

$ sudo composer create-project --repository=https://repo.magento.com/ magento/project-community-edition magento

For this, you will be asked to provide a username and password. Put your private key as the password and your public key as the username. Please be patient while the Composer downloads and install all of the essential dependencies.

Using the zip file for installation

Take a look at this link. Select your favorite version from the download menu and click the download button.

Follow the instructions below.

$ sudo mkdir /var/www/html/magento/

$ sudo tar -zxvf ~/Downloads/Magento-CE*.tar.gz -C /var/www/html/magento/

Copying from a local machine to a remote machine

# On local machine

$ scp -r magento2-ce.zip user@<your-domain-name/ip-address>:/var/www/html/magento/magento.zip

# On remote machine

$ cd /var/www/html

$ mkdir magento

$ sudo tar -zxvf magento.zip -C magento/

Using composer, install dependencies.

$ cd /var/www/html/magento/

$ composer install

install composer

We may now open the Magento setup in your desired domain name or server IP address after completing the installation procedures.

Typical Errors and Exceptions

If you receive a 500 error after installation, please take the following steps:

This issue is most likely caused by directory access issues. Use the following instructions to address the problem:

$ sudo chown -R www-data:www-data /var/www/html/magento

$ sudo chmod -R 755/var/www/html/magento

You must configure the user group in accordance with your setup.

Your user group will be determined by the Http server instance you are using. It was www-data in our case, however depending on the architecture, it may be nginx or apache by default. These commands can be used to verify this.

$ ps aux | grep apache

$ groups <apache-user>

If you’re still experiencing issues, look over the logs below to see what’s going on.

$ tail -f /var/log/apache2/magento_error.log $ tail -f /var/log/apache2/magento_access.log

Step 9: Magento Configuration

This screen will appear after you access your URL.

Select Agree and Install Magento from the drop-down menu.

On the following screen, select Start Readiness Check.

Check that all of the checks are positive; if any dependencies are missing, a red cross will appear, indicating that you should install them and try again. Proceed to the next step after confirmation.

Click next after entering the Magento database credentials you created earlier in this guide.

The site configuration details can then be set according to your needs in the next stage.

The following step is to set your time zone, language, and currency. In advanced setup, you can choose or deselect the modules you desire from the list.

You’ll set your admin login credentials in the next step.

Your Magento configuration is now ready to be installed, so click the Install Now option after hitting the Next button.

Now all you have to do is wait for the installation to finish.

After a successful installation, you’ll see all of your Magento setup details, which you may take note of before clicking Launch Magento Admin.

This will access the Magento login window, where you can log in using your administrator credentials.

Cron Jobs Configuration

Cronjob is a scheduler that executes a specified file path at a predetermined period. Magento requires the setup of certain of these Cron Jobs in order to function effectively.

Follow this command to add these Crons.

$ cd /var/www/html/magento $ sudo php bin/magento cron:install

This command can be used to inspect the Magento Cron Jobs that have been installed.

$ sudo crontab -l

You should be able to find these options in your Cron

.* * * * * /usr/bin/php /var/www/html/magento/bin/magento cron:run 2>&1 | grep -v "Ran jobs by schedule" >> /var/www/html/magento/var/log/magento.cron.log  * * * * * /usr/bin/php /var/www/html/magento/update/cron.php >> /var/www/html/magento/var/log/update.cron.log  * * * * * /usr/bin/php /var/www/html/magento/bin/magento setup:cron:run >> /var/www/html/magento/var/log/setup.cron.log

With that, your Magento installation is complete and ready for use on your e-commerce site.

Industry news straight to your inbox

Get the latest commerce news, trends, and strategies to grow your business
Subscribe to the newsletter
By submitting this form, you agree to receive promotional messages from Magstack. Unsubscribe any time by clicking the link in our emails.
Select location and language

Contact Our Sales Team

Learn more about our products, features, and pricing options.
By submitting this form, you agree to receive promotional messages from Shopify about its products and services. You can unsubscribe at any time by clicking on the link at the bottom of our emails.
Use cases
Log in
Start a free trial