Copied....

Magento Installation and Setup: A Step-by-Step Guide

authorimage
Akshaya MathoorellipsAug 5, 2024ellips4 min read
logoimage

Setting up a powerful eCommerce store requires robust software, and Magento is one of the best options available. This guide will walk you through the entire process of Magento installation and setup, ensuring that you can get your online store up and running smoothly.

Step 1: Prepare Your Server

Before installing Magento, you need to ensure your server meets the necessary requirements. Here are the server specifications you need:

  • Operating system (Linux recommended)
  • Web server (Apache or Nginx) - In this guide we are using Nginx
  • Database (MySQL or MariaDB)
  • PHP (version 8.1 or higher)

Additionally, make sure you have SSH access to your server and that you can install necessary software.

Step 2: Update Operating System

It ensures your system is equipped with the latest package versions.

apt update && sudo apt upgrade -y

Step 3: Setting up Nginx web server

Start Nginx with this command:

systemctl start nginx

Ensure Nginx starts automatically on boot with the following command:

systemctl enable nginx

Nginx is now running, and configured to start on boot.

Step 4: Set Up the Database

Start the MySQL database server and enable it to start automatically on boot:

systemctl start mysql

systemctl enable mysql

After starting MySQL, access the MySQL prompt:

mysql -u root -p

Within the MySQL prompt, execute the following commands to create a database, database user, and grant all privileges to the user.

Note: Customize 'magentodb,' 'magentouser,' and 'MyPassword' as needed:

mysql> CREATE DATABASE magentodb;

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

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

mysql> FLUSH PRIVILEGES;

mysql> EXIT

Step 5: Installing Elasticsearch

1.Import the Elasticsearch GPG key:

wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /usr/share/keyrings/elasticsearch-keyring.gpg

2. Add the Elasticsearch repository:

echo "deb [signed-by=/usr/share/keyrings/elasticsearch-keyring.gpg] https://artifacts.elastic.co/packages/8.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-8.x.list

3. Update the apt package manager and install Elasticsearch:

apt update && apt install elasticsearch

4. Start and enable the Elasticsearch service:

systemctl start elasticsearch

systemctl enable elasticsearch

5. Restart the Elasticsearch service to apply the configuration:

systemctl restart elasticsearch.service

Step 7: Install Magento Using Composer
  1. Installing Magento using the Marketplace by creating an access key is recommended.
  2. Generate Access keys by navigating to: My profile > Marketplace > My products > Access Keys.
  3. Navigate to your Magento directory and run the following command to install Magento:

composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.4.x

Step 8: Set Up Permissions

Magento requires specific directory permissions. Set the correct permissions using these commands:

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

Change the ownership of the Magento directory to the webserver user and adjust permissions:

chown -R www-data:www-data /var/www/magento2

chmod -R 755 /var/www/magento2

Step 9: Install Magento 2 using the built-in Magento CLI

Command to trigger the Magento installation process. Customize the parameters according to your environment:

bin/magento setup:install \

--base-url=http://your-domain.com \

--db-host=localhost \

--db-name=magentodb \

--db-user=magentouser \

--db-password=MyPassword \

--admin-firstname=Admin \

--admin-lastname=User \

--admin-email=admin@your-domain.com \

--admin-user=admin \

--admin-password=admin123 \

--language=en_US \

--currency=USD \

--timezone=America/Chicago \

--use-rewrites=1

Step 10: Configure Nginx Web Server for Magento 2
  1. Navigate to the Nginx configuration directory:

cd /etc/nginx/conf.d

  1. Create a configuration file for your Magento installation:

nano /etc/nginx/conf.d/magento2.conf

  1. Add the following content to the file, customizing it as needed (replace your-domain.com with your actual domain):

upstream fastcgi_backend {

  server unix:/run/php/php8.1-fpm.sock;

}

server {

  listen 80;

  server_name your-domain.com www.your-domain.com;

  set $MAGE_ROOT /var/www/magento2;

  include /var/www/magento2/nginx.conf.sample;

}

  1. Save the file and exit the text editor.
  2. Restart the Nginx web server to apply the configuration changes:

systemctl restart nginx

Step 11: Finalize Configuration

After configuring Nginx Web Server, there are a few final steps:

  1. Deploy static content:

bin/magento setup:static-content:deploy -f

  1. Reindex and cache clean:

    bin/magento indexer:reindex

bin/magento cache:clean

Step 12: Upload Magento to Your Server

Once you have downloaded Magento, you need to upload the files to your server. You can use an FTP client like FileZilla, or you can use SSH commands.

For SSH, use the following commands:

scp (Secure Copy):

scp -r /path-to-your-magento-files user@your-server:/path-to-your-server-directory

Conclusion

By following this Magento Installation and Setup: A Step-by-Step Guide, you should now have a fully functional Magento store ready to go live. Remember, a well-set-up Magento store can handle a large volume of products and customers, providing a seamless shopping experience.

Subscribe to our Blog

Stay up to date on the latest trends, emerging tech, launches and much more