Installation Steps To Setup Magento On Ubuntu

1) To install Ubuntu, please follow the reference URL:
https://brb.nci.nih.gov/seqtools/installUbuntu.html
2) Once we are done with Ubuntu installation from above link, we have to install the Magento environment components as explained below.

To install Apache2, PHP and Required Extensions, we have to follow the
steps given:
2.1) Install Apache2 Server:
sudo apt update && sudo apt upgrade
sudo apt install apache2

To run apache automatically during startup, run the following command line:
sudo systemctl enable apache2.service
2.2) Configure Apache2 Virtual Host:
To declare Apache2 site configuration for Magento 2 store, you have to create a new
configuration file magento2.conf:
sudo nano /etc/apache2/sites-available/magento2.conf
Copy and paste the following content to above file. Remember, we are using localm2.com as our domain.

<VirtualHost *:80>
    ServerAdmin admin@localm2.com
    DocumentRoot /var/www/html/magento2/
    ServerName localm2.com
    ServerAlias www.localm2.com
    <Directory /var/www/html/magento2/>
        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>

You need to make local server entry in /etc/hosts file as following:
a) Edit host file: sudo vim /etc/hosts
b) Add the entry: 127.0.0.1 localm2.com
Enable Rewrite mod:
Make sure you enable rewrite mod to use site friendly URLs:
sudo a2ensite magento2.conf
sudo a2enmod rewrite

4.3) Install PHP 7.3 and extensions:
sudo apt-get install php7.3 libapache2-mod-php7.3 php7.3-cli php7.3-mysql php7.3-gd
php7.3-imagick php7.3-recode php7.3-tidy php7.3-xmlrpc
To install composer, please run following command:
sudo apt install composer

4.4) Update php.ini file:
sudo vim /etc/php/7.3/apache2/php.ini
Please change the following details and save the php.ini file:
file_uploads = On
allow_url_fopen = On
short_open_tag = On
memory_limit = 2048M
upload_max_filesize = 128M
max_execution_time = 3600


We can verify the php installation by command: php -v
After that, you should restart apache2 with this command:
sudo systemctl restart apache2.service

5) Install Database Server:
Magento preferred MariaDB Database Server to default MySQL Database Server, because of faster and better performance. To install MariaDB Server and Client, run this command line:
sudo apt-get install mariadb-server mariadb-client


Make sure it start and startup everytime you reboot server:
sudo systemctl restart mariadb.service
sudo systemctl enable mariadb.service

You’ve just installed MariaDB server, now you have to initially setup this database server.
sudo mysql_secure_installation

It prompts options and you choose the following option:
Enter current password for root (enter for none): Enter
Set root password? [Y/n]: Y
New password: Type your password
Re-enter new password: Type your password
Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y
Remove test database and access to it? [Y/n]: Y
Reload privilege tables now? [Y/n]: Y

6) Create MySQL User (Required):
From Magento 2.3.x, Magento requires a unique user for Magento installation, it cannot be default user as root

First of all, you have to login to MariaDB:
sudo mysql -u root -p
Create a new database for Magento 2:
CREATE DATABASE magento2;
Then create a new user name call: magento2
CREATE USER 'magento2'@'localhost' IDENTIFIED BY 'magento2';
Grant magento2 user to magento2 database:
GRANT ALL ON magento2.* TO 'magento2'@'localhost' IDENTIFIED BY 'magento2' WITH GRANT OPTION;
Now its time to flush privileges and exit.
FLUSH PRIVILEGES; EXIT;

7) Download Magento setup from reference URL :
https://github.com/magento/magento2/releases/tag/2.3.4-p2
After download, you should extract the pack to /var/www/html/. E.g you have a folder called magento2 in /var/www/html/
Set permissions: Run this command
sudo chown -R www-data:www-data /var/www/html/magento2/
sudo chmod -R 755 /var/www/html/magento2/

8) Install Magento 2:
Access to this address http://local m2 .com/magento2 , you will get this Magento Setup Wizard as the following:
If you face an error regarding composer install as following:
To enable extensions, verify that they are enabled in your .ini files:

/etc/php/7.3/cli/php.ini
/etc/php/7.3/cli/conf.d/10-opcache.ini
/etc/php/7.3/cli/conf.d/10-pdo.ini
Install all required extension:
sudo apt install php7.3-pdo

To install Magento via command line:
sudo php bin/magento setup:install --base-url=http://localm2.com/magento2/ --db-host=localhost --
db-name=magento2 --db-user=root --admin-firstname=Magento --admin-lastname=User --adminemail=
my@email.com --admin-user=admin --admin-password=admin123 --language=en_GB --
currency=GBP --timezone=Europe/London --use-rewrites=1 --backend-frontname=admin

Run following command to setup proper website flow:
sudo rm -rf generated/ var/view_preprocessed/ && sudo chmod -R 777 var/ pub/ generated/
php bin/magento s:up
php bin/magento s:di:compile
php bin/magento s:static-content:deploy -f
php bin/magento c:c && php bin/magento c:f
php bin/magento deploy:mode:set developer

If your base url is not working without /index.php, please add the following to .htaccess file which is on Magento root directory:
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Leave a Reply