Magento 2 is one of the most powerful and flexible open-source e-commerce platforms available today. Installing Magento 2 from scratch can seem intimidating, but with the right guidance, it’s easier than you think. This guide will walk you through each step to help you get your Magento 2 store up and running.
By the end of this tutorial, you’ll have a fully functional Magento 2 installation that you can start customizing and building your e-commerce store on.
Prerequisites
Before you start, make sure your system meets the following requirements:
-
Operating System: Linux-based OS (Ubuntu is highly recommended)
-
Disk Space: 2 GB for the Magento installation (recommended: 4 GB)
-
RAM: 2 GB minimum (recommended: 4 GB)
-
PHP: 7.4.x or 8.1.x (Magento 2.4.x supports both)
-
MySQL: 5.6, 5.7 or MariaDB 10.2 or higher
-
Composer: A PHP dependency manager (used to install Magento 2)
-
Git: Version control system (optional but useful)
Step 1: Set Up the Environment
Magento 2 can be installed on a local development environment (such as XAMPP, MAMP, or LAMP) or a live server. For this guide, we’ll assume you’re using Ubuntu.
-
Install Apache Web Server (if not already installed):
sudo apt-get update sudo apt-get install apache2 sudo systemctl start apache2 sudo systemctl enable apache2
-
Install PHP and Necessary Extensions:
sudo apt-get install php php-cli php-fpm php-mysql php-intl php-mbstring php-curl php-xml php-zip php-soap php-bcmath
-
Install MySQL:
sudo apt-get install mysql-server sudo systemctl start mysql sudo systemctl enable mysql
-
Install Composer (Dependency Manager):
curl -sS https://getcomposer.org/installer | php sudo mv composer.phar /usr/local/bin/composer
Step 2: Set Up the Database
-
Create a MySQL Database for Magento:
Log in to MySQL:
sudo mysql -u root -p
Create a new database and user for Magento:
CREATE DATABASE magento2; GRANT ALL PRIVILEGES ON magento2.* TO 'magento_user'@'localhost' IDENTIFIED BY 'password'; FLUSH PRIVILEGES;
-
Exit MySQL:
exit;
Step 3: Download and Install Magento 2
-
Navigate to the Directory Where You Want to Install Magento 2:
cd /var/www/html
-
Install Magento Using Composer:
Run the following command to install Magento 2 (replace
<your_magento_version>
with the desired version, such as2.4.5
):composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition <your_magento_version>
During this process, you’ll be prompted for Magento repository credentials. If you don’t have these, create an account at Magento Marketplace and retrieve the keys from the "Access Keys" section.
Step 4: Set File Permissions
After installing Magento, you need to set the correct file permissions to allow proper read and write access.
sudo chown -R www-data:www-data /var/www/html/magento2
sudo find /var/www/html/magento2 -type f -exec chmod 644 {} \;
sudo find /var/www/html/magento2 -type d -exec chmod 755 {} \;
sudo chmod -R 777 /var/www/html/magento2/var /pub /generated
Step 5: Set Up Apache Virtual Host
Create a new Apache configuration file for your Magento site:
sudo nano /etc/apache2/sites-available/magento2.conf
Add the following configuration (adjust paths and domain names as needed):
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/magento2/pub
ServerName magento2.local
<Directory /var/www/html/magento2>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Enable the site and the rewrite module:
sudo a2ensite magento2.conf
sudo a2enmod rewrite
sudo systemctl restart apache2
Step 6: Run the Magento 2 Installation Command
Now, it’s time to run the Magento 2 installation script using the command line interface.
Navigate to your Magento installation folder:
cd /var/www/html/magento2
Run the Magento setup command to install Magento:
php bin/magento setup:install \
--base-url=http://magento2.local \
--db-host=localhost \
--db-name=magento2 \
--db-user=magento_user \
--db-password=password \
--admin-firstname=Admin \
--admin-lastname=User \
--admin-email=admin@example.com \
--admin-user=admin \
--admin-password=admin123 \
--language=en_US \
--currency=USD \
--timezone=America/Chicago \
--use-rewrites=1
This command will:
-
Set up the store’s base URL
-
Configure the database
-
Create an admin user
-
Set default configurations for language, currency, and timezone
Step 7: Access Your Magento Store
-
Access the Frontend:
Open your browser and go to
http://magento2.local
. You should see the Magento 2 welcome page. -
Access the Admin Panel:
To access the admin panel, go to:
http://magento2.local/admin
Log in using the credentials you set during installation (e.g.,
admin
as the username andadmin123
as the password).
Step 8: Enable Developer Mode (Optional)
During development, it’s helpful to enable Magento’s developer mode to get more detailed error messages and reduce caching.
Run the following command:
php bin/magento deploy:mode:set developer
Step 9: Set Up Cron Jobs (Important for Background Tasks)
Magento uses cron jobs for various tasks like sending emails, indexing, and cleaning up logs. Set up cron jobs with the following commands:
sudo crontab -u www-data -e
Add the following line to the cron file:
* * * * * php /var/www/html/magento2/bin/magento cron:run >> /dev/null 2>&1
* * * * * php /var/www/html/magento2/update/cron.php >> /dev/null 2>&1
* * * * * php /var/www/html/magento2/bin/magento setup:cron:run >> /dev/null 2>&1
Step 10: Final Touches
-
Clean the Cache:
php bin/magento cache:flush
-
Reindex the Data:
php bin/magento indexer:reindex
This step-by-step guide simplifies the Magento 2 installation process, ensuring a smooth setup for your eCommerce platform. Businesses can save time and avoid technical issues when they Hire Magento Developers , ensuring expert configuration, performance optimization, and a seamless shopping experience for customers.
ReplyDelete