How to Install New theme on Fresh Magento 2 Installation

Note: This tutorial is for fresh Magento 2 website, where there is no important data. You must have Running default Magento 2

In first step, create a new database and database username (same name) with strong password and grant all privileges to that user.

Now we need to login to Ubuntu SSH (Using ubuntu username)

First of all, remove all files from your magento root directory, here we have /var/www/html

sudo rm -rf /var/www/html/*

If you see permission error or access denied, then check ownership and su to that user or use sudo su command to remove it via root after that use exit to ubuntu user. Now move to your root directory

cd /var/www/html

Remember that, there are hidden files start with . (dot), you must delete them all. You can see list of all such file by using ls -la command and then remove them all one by one using e.g. rm -rf .htaccess

Now upload the .zip file of theme (it must be complete package along with magento 2.4.x + theme. (Some provide name it quickstart)

Now we need to unzip our theme directory. (you must install unzip if it is not installed, using ubuntu user, use command sudo apt install unzip)

unzip your-theme-folder-name.zip

After that, create a new user there with same name as your database, in this tutorial, we will use magento

sudo adduser magento

It will required a password, use same password you have used for your database to avoid multiple passwords. For information data like First Name etc, leave it Empty and keep pressing Enter and then Y and Enter

As www-data is the default web server group for ubuntu, so we will make it primary for this user using this command

sudo usermod -g www-data magento

Now we need to grant ownership and group permission for this new users for our magento room directory. The default is /var/www/html but you need to use as per your configuration

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

Note: Remember that, your composer must be installed, if not, then you can ask in comment.

Now login to magento user that you have created just now using this command

su magento

and use the password you have setup while created this user.

You will see your user name in the start line, Now move to your magento root directory:

cd /var/www/html

for verification, check the ownership and group by using ls -la command, it should be magento www-data

Now we need to set pre installation permission for all extracted files, use this command:

find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} + && find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} + && chown -R :www-data . && chmod u+x bin/magento

Note: if you see permission denied Error, then use exit command and rung again sudo chown -R magento:www-data /var/www/html/ command. And then back to su magento

Now check the sample data sql file within sample data or quick start or any kind of folder and import it within your database that you have created using this command (make sure, you can in the directory where the sample-data.sql file is location)

mysql -u magento_user -p magento_db < sample-data.sql

After this, you need to install magento using this:

bin/magento setup:install \ --base-url=https://yourdomain.com \ --db-host=localhost \ --db-name=magento \ --db-user=magento \ --db-password="U274eeGzNCqKJ2LpvtS@329" \ --admin-firstname=bob \ --admin-lastname=smith \ --admin-email=bob@example.com \ --admin-user=bob \ --admin-password=example@123 \ --language=en_US \ --currency=GBP \ --timezone=Europe/London \ --use-rewrites=1

in above example, edit the credential and details as per your own details.

After installation, copy your admin URL and save it. Now increase php memory limit to 2G. So use:

nano .htaccess

and find 756M and change it to 2G then Ctrl+X and Y then enter.

you must install cron tasks:

bin/magento cron:install

Magento login will ask Two Factor authentication, you can disable it.

nano app/etc/config.php

User Ctrl+W and type TwoFactor and hit Enter, you will seel value 1 for TwoFactor authentication, change it to 0 and save file. Then run following commands:

bin/magento setup:upgrade
bin/magento setup:static-content:deploy -f
chmod -R 777 pub
chmod -R 777 generated
chmod -R 777 var

If you see any link side issue or redirecting to anywhere else, then open phpmyadmin and find this table

core_config_data

Edit it and validate your base unsecure and secure url, it must be same (with https in case of SSL enabled site)

Leave a Reply

Your email address will not be published. Required fields are marked *