Magento 2 is a powerful open-source eCommerce platform. This guide will help you install Magento 2 on your local or live server using Composer. The steps are easy and suitable for beginners.
Requirements
- PHP 8.1 or 8.2 with required extensions
- Apache or Nginx
- MySQL or MariaDB
- Composer
- Elasticsearch (Magento 2.4+)
Step 1: Download Magento 2 Using Composer
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition magento2
Step 2: Set Proper File Permissions
cd magento2 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 {} + chmod u+x bin/magento
Step 3: Create a Blank Database
Create a database in MySQL named magento2
or anything you prefer.
Step 4: Install Magento
bin/magento setup:install \ --base-url=http://localhost/magento2 \ --db-host=localhost \ --db-name=magento2 \ --db-user=root \ --db-password=yourpassword \ --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
Step 5: Access the Admin Panel
Magento will generate a unique admin URL. Use it to log in with the admin credentials you just set up.
Troubleshooting Tips
- Run
php -v
to check your PHP version. - Make sure required extensions like intl, soap, xsl are enabled.
- Run
bin/magento setup:upgrade
if you face module or DB issues.