You must have imagined launching your online store with the power and flexibility to scale as your business grows. Once you install Magento 2, you are beginning to build this sturdy but flexible platform that can handle small inventories and large product catalogs. Have you ever felt saturated by how complicated the technical aspect of setting up such a system would be? You’re not the only one. Many fellows, ranging from new entrepreneurs to old-time developers, are seeking as clear as possible detailed guidance on how to install Magento 2 avoiding common poor experiences.
This comprehensive guide will easily simplify the whole process of how to install Magento 2 into small, digestible steps anyone can follow. From how to install Magento to specifically how to install Magento 2 using Composer, we have it covered. The guide will feature the important system requirements, pre-installation preparations, and everything.
Let’s install Magento 2 together!
What is Magento 2?
Before jumping to installation, it is important to understand what Magento 2 is all about: Magento 2 is an open-source e-commerce platform, boasting flexibility, scalability, and endless customization options. It is enriched with features such as sophisticated SEO, responsive design, multiple payment gateways, and strong security. Magento 2 is indeed the perfect e-commerce platform for any company, whether a small start-up or a large enterprise, planning to create a unique online shopping experience.
How Magneto is the first choice:
- Flexibility and Customization: Magento 2 has a modular architecture that helps developers easily customize and extend functionalities.
- Performance Enhancement- Better caching, indexing, and overall performance with faster and more efficient than previous versions.
- SEO-Friendly: In-built SEO capabilities enable your store to do the best ranking in search engines and result in more organic traffic.
- Responsive Design: Look great on every single gadget to improve proficiency with customers.
- Robust Community Support: Large communities, developers, and users provide many valuable resources, plugins, and extensions.
System Requirements to Install Magento 2
This first part of the process is ensuring that your server meets the necessary system requirements. It is quite important because, without these, the installation of Magento 2 would be a huge hassle. All of the requirements are just:
Server Requirements
Get exclusive access to all things tech-savvy, and be the first to receive
the latest updates directly in your inbox.
- Operating Systems: Linux x86-64
- Web Servers: Apache 2.4 or Nginx 1.x
- Databases: MySQL 8.0, MariaDB 10.4
- PHP: 7.4, 8.1, or 8.2
- RAM: Minimum 2GB
PHP Extensions
Ensure the following PHP extensions are all available in your web server environment:
- bc-math
- ctype
- curl
- dom
- gd, ImageMagick 6.3.7 (or later) having PNG support
- intl
- mbstring
- openssl
- PDO/MySQL
- SimpleXML
- soap
- xsl
- zip
- json
- iconv
And a few more requirements:
- Composer: Dependency management through Composer in Magento 2.
- SSH Access: It will allow you to run command-line operations.
- SSL Certificate: Say, it is recommended for secure transactions.
Checking System Requirements To Install Magento 2
The version of PHP and the extensions installed can be checked using this command:
php -v
Output:
PHP 8.1.12 (cli) (built: Nov 18 2023 10:20:30) ( NTS )
Make sure that the output matches the required version of PHP, and that all extensions required are listed below it.
Pre-Installation Steps
You must do the following preliminary steps before installing Magento 2:
1. Setting Up the Server Environment
Your server environment must satisfy the system requirements of Magento 2. Install the following needed software: Apache/Nginx, PHP, MySQL/MariaDB, and Composer.
2. Create Dedicated MySQL Database for Magento 2
Make MySQL Database and User for Magento 2.
Command:
CREATE DATABASE magento2;
CREATE USER 'magentouser'@'localhost' IDENTIFIED BY 'secure_password';
GRANT ALL PRIVILEGES ON magento2.* TO 'magentouser'@'localhost';
FLUSH PRIVILEGES;
Query OK, 1 row affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
3. Set File Permissions
Set the file permissions for Magento 2 to read/write the necessary files.
Commands:
sudo find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +
sudo find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +
sudo chmod u+x bin/magento
4. Install Composer
If Composer is not installed, it can be installed using the following commands:
Commands:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer
Output:
All settings correct for using Composer
Downloading...<br><br>Composer successfully installed to: /usr/local/bin/composer
Use it: composer
These pre-installation steps are complete and are ready to install Magento 2.
Download and Install Magento 2 Using Composer
Installing Magento 2 through Composer will ensure that the latest updates and dependencies will be applied in an effective manner. For “Magento composer install”, do the following:
Step 1: Get the Access Keys for Magento 2
To download Magento 2 from the Composer repository, you need to collect access keys from your Magento Marketplace account.
- Sign into your Magento Marketplace account.
- Click My Profile > Access Keys.
- If you do not have one, create a new access key. Write down the Public Key and Private Key.
Step 2: Set Up Composer Authentication
Setup Composer with your Magento Marketplace access keys.
Command:
<strong>composer config --global http-basic.repo.magento.com abcd1234 efgh5678</strong>
Step 3: Generate a Project Directory
Now navigate your way around the root directory of your web server, then create a new project directory.
Commands:
cd /var/www/html
mkdir magento2
cd magento2
Step 4: Install Magento 2 via Composer
Next, you would apply Composer to create a new Magento 2 project.
Command:
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.4.6 .
Output:
Installing magento/project-community-edition (2.4.6)
- Installing magento/project-community-edition (2.4.6): Downloading (100%)
Created project in /var/www/html/magento2<br><br>Loading composer repositories with package information
...
Note: This could take a while to complete depending on your server’s performance and bandwidth.
Step 5: Set File Permissions
The Magento 2 installation process has been completed via Composer and is ready to set up the database and application for configuration.
Commands:
sudo find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +
sudo find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +
sudo chmod u+x bin/magento
Making sure that the files have the required permissions on Magento 2 installation is easy enough.
Establish the Magento 2 Database
The functionality of Magento 2 relies heavily on the correct setup of the database. Here are the steps needed in configuring your Magento 2 database.
Step 1: Make a Database
Create a MySQL database if you have not done so so far.
Commands:
CREATE DATABASE magento2;
CREATE USER 'magentouser'@'localhost' IDENTIFIED BY 'secure_password';
GRANT ALL PRIVILEGES ON magento2.* TO 'magentouser'@'localhost';
FLUSH PRIVILEGES;
Query OK, 1 row affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Output:
Step 2: Configure Database Connection
Open the app/etc/env.php file, and update the database connection details.
Example env.php:
<?php
return [
'backend' => [
'frontName' => 'admin'
],
'db' => [
'connection' => [
'default' => [
'host' => 'localhost',
'dbname' => 'magento2',
'username' => 'magentouser',
'password' => 'secure_password',
'active' => '1',
]
]
],
// ... other configurations ...
];
Step 3: Confirm Database Connection
Run the command given below to test the connection to the database.
Command:
<strong>bin/magento setup:db:status</strong>
Output:
[OK] Connection to database magento2 is successful
In case you run into some issues while connecting, check once again for the username and password used for database access, along with checking if the MySQL service is up and running.
Configuring Magento 2
After setting up the database and then you have to set up the configuration for Magento 2 after running the installation wizard or running from the command line.
Option 1: Using the Magento Setup Wizard
Access the Web Installer: Open your web browser and navigate to http://your-domain.com/setup.
Step-by-Step Roadmap:
- Readiness Check: Meet all the system requirements.
- Add a Database: Enter your database credentials.
- Web Configuration: Set the base URL and configure the admin user.
- Customize your store: Locale, currency, and timezone.
- Create Admin Account: Create the admin username and password.
Once all these steps are done, you’ll get your success message with your admin panel URL.
Output:
<strong>Magento 2 has been successfully installed.</strong>
You can access the Admin panel at: http://your-domain.com/admin_1a2b3c
Option 2: Command Line
It’s easier to install using Magento CLI.
Command:
bin/magento setup:install \
--base-url=http://your-domain.com/ \
--db-host=localhost \
--db-name=magento2 \
--db-user=magentouser \
--db-password=secure_password \
--admin-firstname=Admin \
--admin-lastname=User \
[email protected] \
--admin-user=admin \
--admin-password=Admin123! \
--language=en_US \
--currency=USD \
--timezone=America/Chicago \
--use-rewrites=1
Output:
[INFO] Starting Magento installation:
[INFO] Creating Magento directory structure...
[INFO] Setting application modes...
[INFO] Creating database schema...
[INFO] Importing data...
[INFO] Installing sample data...
[INFO] Deployment finished successfully.
Magento installation complete.
Once the setup is complete, you can access your Magento admin panel from http://your-domain.com/admin.
Validating the Installation
To verify the installation of Magento 2, you can complete the following:
1. Access the Frontend
Browse http://your-domain.com/ from your web browser. The output should display the Magento storefront.
2. Log in to Admin
Go to http://your-domain.com/admin and use admin users’ credentials to sign in.
tail -f var/log/system.log
Output:
[2024-04-27 12:34:56] main.INFO: Cache cleared successfully [] []
[2024-04-27 12:35:01] main.INFO: Customer login: admin [] []
3. Investigate Error Checking
Check var/log/ for error logs of Magento.
Command:
<strong>tail -f var/log/system.log</strong>
Output:
[2024-04-27 12:34:56] main.INFO: Cache cleared successfully [] []
[2024-04-27 12:35:01] main.INFO: Customer login: admin [] []
4. Test the functionality.
Add a product, configure settings, and travel through different areas to make sure it works.
Example:
- Introduce a new product under Catalog > Products.
- Set up the payment methods under Stores > Configuration > Sales > Payment Methods.
Output:
Product added successfully.
Payment methods configured.
Common Installation Issues and Troubleshooting
Even with an all-encompassing installation guide, you can be faced with some issues while installing Magento 2. Here are some of the common issues and their related fixes.
1. PHP Memory Limit Errors
Error Message:
Allowed memory size of 134217728 bytes exhausted
Solution: Increase PHP memory limit in php.ini file.
Command:
sudo nano /etc/php/8.1/apache2/php.ini
Update:
memory_limit = 2G
Output: (No output; restart Apache)
Restart Command:
sudo systemctl restart apache2
2. Composer Does Not Install
Error Message:
[InvalidArgumentException] Could not find a matching version of package ...
Solution: Make sure that your Composer is updated and that the repository of Magento is correctly setup.
Commands:
composer self-update
composer clear-cache
Output:
All settings correct for using Composer
Cleared cache.
3. File Permission issues
Error Message:
Error: Unable to create directory ...
Solution: Set right file permissions as provided in the Pre-Installation steps.
Commands:
sudo find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +
sudo find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +
sudo chmod u+x bin/magento
Output: (No output if successful)
4. Database Connection Error
Error Message:
Cannot connect to database: SQLSTATE[HY000] [1045] Access denied for user 'magentouser'@'localhost'
Solution: Verify your database credentials in app/etc/env.php and make sure that the MySQL user has all possible privileges.
Commands:
GRANT ALL PRIVILEGES ON magento2.* TO 'magentouser'@'localhost';
FLUSH PRIVILEGES;
Output: –
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Post-Installation Recommendations
1. Enable Caching
Caching is a feature that improves performance on your Magento store.
Command:
bin/magento cache:enable
Output:
Enabled cache types:
- config
- layout
- block_html
- collections
- reflection
- db_ddl
- compiled_config
- eav
- config_integration
- config_integration_api
- full_page
- translate
- vertex
2. Set up the Cron
Most of the Magento 2 functions can use cron jobs – they are used by indexing and emailing.
Command:
crontab -u www-data -e
Add The Following Lines:
* * * * * /usr/bin/php /var/www/html/magento2/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/www/html/magento2/var/log/magento.cron.log
* * * * * /usr/bin/php /var/www/html/magento2/update/cron.php >> /var/www/html/magento2/var/log/update.cron.log
* * * * * /usr/bin/php /var/www/html/magento2/bin/magento setup:cron:run >> /var/www/html/magento2/var/log/setup.cron.log
3. Install SSL Certificate
An SSL certificate is meant to secure the store against data leakage while enhancing information trust.
Commands:
sudo apt-get install certbot python3-certbot-apache
sudo certbot --apache -d your-domain.com -d www.your-domain.com
Output
Congratulations! You have successfully enabled https://your-domain.com
4. Performance Optimization
Enable flat catalogs, merge JavaScript and CSS files, and implement the CDN to further boost performance.
Commands:
bin/magento config:set catalog/frontend/flat_catalog_category 1
bin/magento config:set catalog/frontend/flat_catalog_product 1
bin/magento config:set dev/js/merge_files 1
bin/magento config:set dev/css/merge_css_files 1
Output:
Configuration updated successfully.
5. Regular Backup
Create regular backups that save the data on your store.
Command:
bin/magento maintenance:enable
tar -czvf magento2_backup_$(date +%F).tar.gz /var/www/html/magento2
bin/magento maintenance:disable
Output:
Enabled maintenance mode
Disabled maintenance mode
Installing Magento 2 with CyberPanel
Installing Magento 2 on a server is a great deal easier with a server management tool. CyberPanel is an open-source web hosting control panel that uses LiteSpeed and OpenLiteSpeed web servers to run the application. This is a graphical interface to manage the server in many aspects including websites, databases, email accounts, etc. However, by using CyberPanel, you shouldn’t find the server management pretty easy and better but moreover, focus on your e-commerce business rather than the infrastructure.
To install Magento 2 with CyberPanel, follow these simple steps:
- Log in to your CyberPanel Dashboard: Use your credentials to log in to your CyberPanel dashboard.
- Create a New Site: In the Sites section, create a new website by entering all the details such as domain, email, and PHP version.
- Create a MySQL Database: Create a new MySQL database and user for Magento 2.
- Install using Magento 2: Select and install it using CyberPanel’s app installer. Enter the database credentials when prompted.
- SSL Configuration: Secure your Magento 2 store with an SSL certificate from CyberPanel SSL Management.
- Complete the process: After completing the installation, visit the Magento 2 storefront and admin panel to customize your store.
FAQs: Install Magento 2
1. Is it possible to Install Magento 2 in Shared Hosting?
Yes, this is indeed possible, but not meant for it as:
Performance Constraints: Sharing has unsatisfactory performance, which results in slow operations of your store.
Risk: There are also very high risks in increases over shared environments.
Less Control: This has restrictions on server configuration.
Hurdles in Scaling: It is difficult to handle the growth of traffic.
So proper installation of Magento 2 is done with VPS or dedicated hosting.
2. How to Get “Access Keys” for Installing Magento 2?
The access keys from the Magento marketplace are required to install Magento 2 using Composer:
Sign up/Login: Go to Magento Marketplace and sign in.
Access Keys: My Profile > Access Keys.
Generate your keys: Make a new access key pair (Public and Private).
Use it with Composer: Set Composer up with these keys to authenticate your installation.
3. What to Do When You Encounter a Memory Limit Exhausted Error During Installation?
A Memory Limit Exhausted error is an indication that PHP requires some more memory:
Edit php.ini: Locate and open your php.ini file.
Increase Memory Limit: Set memory_limit = 2G.
Restart Web Server: Changes require either Apache or Nginx to be restarted.
Verify: Run php -v to verify the new memory limit set.
4. How do I secure “My Magento 2 Store” after installation?
In this regard, you’ll be enhancing the security of your Magento 2 store using the following:
Enabling SSL: Install an SSL certificate that can protect data through encryption.
Changing Admin URL: Change the default admin path to something other than the default.
Set Proper Permissions: Follow the recommended file permissions set by Magento.
Regular Updates: Always-on-date Excel with the updates of each Magento and extensions.
Strong Passwords: A strong password must be used for all accounts.
Two-Factor Authentication (2FA): Add an extra layer to the admin logins so that it would be more secure.
Security Extensions: Use reputable security plugins to add more protection.
5. How Do I Optimize Magento 2 for Better Performance After Installation?
Boost your Performance Magento 2 Store with these tips:
Enable Caching: Activate Magento caches.
Use a CDN: Distribute content globally to reduce load times.
Optimize Images: Compress images without quality loss.
Enable flat catalogs: Speed up database query performance.
Merge/Minify CSS and JS: Combine files and minify them to reduce HTTP requests. Full Page Caching: This will load the page faster.
Database optimization: Clean and maintain your database on a routine basis.
Use Redis or Varnish: Improve caching sessions and content delivery.
Keep it Updated: Very often, performance is enhanced with the use of the Update Patch and Security Patch.
Moreover, applying these tactics makes your Magento 2 store faster and more efficient, which in turn improves the experience of the users and the SEO rank.
Final Thoughts: Empower Your E-Commerce Journey with Magento 2
This is the time when the installation of Magento 2 opens the vast doors to powerful e-commerce functionalities for your business needs. We have gone through many lengthy steps associated with the setting up of Magento 2-from understanding the system requirements, preparing the server environment, and configuring the essential settings to even resolving some common issues that might pop up along. By deploying some powerful tools such as CyberPanel, using an automated way, the entire installation has been a lot easier ensuring that your online store is functional yet optimized both in the performance as well as security aspects.
Remember, a well-installed and configured Magento 2 store lays a solid foundation on which to build great shopping experiences, increase sales, and create customer loyalty.
Ready to Start Your Magento 2 Store?
You shouldn’t allow the technical side of things to keep your business from becoming successful in e-commerce. Whether you are a newbie or trying to upgrade your existing e-commerce platform, our expert team is always available to help.
So why wait any longer?
Contact Us for personalized assistance with your Magento 2 installation. Take the next step towards building a powerful store!