Among many open-source platforms available, Magento 2 is indeed one of the most popular. It offers varying customization options and allows you to manage multiple stores from a single admin panel. However, many people find it challenging to install Magento 2 and start their business.
No worries; we'll cover everything you need to know! Our article discusses:
- Key requirements to meet before installing Magento 2
- Steps to install Magento 2
- Troubleshooting tips
- Alternative methods to install Magento 2
Let's wait no more and get right into it!
3 Requirements to Run A Magento 2 Store
Before starting your Magento installation, make sure you review and check all items on our checklist below!
#1. Meet All Server Requirements
Magento 2 cannot run smoothly on its managed cloud hosting if your server fails to meet the key requirements. In detail, here's our breakdown of Magento server requirements for your reference:
- Magento 2 supports Linux distributions like RHEL, Debian, Ubuntu, and CentOS. It isn't supported on macOS or Windows.
- For the best performance, you should have up to 2GB of RAM, especially when upgrading Magento extensions and applications! If your system has less than 2GB, we recommend making a swap file to prevent upgrade failures.
- Regarding web servers, Magento 2 is compatible with NGINX 1.x and Apache 2.4. It supports MySQL 5.6 & 5.7 databases and also works well with Percona 5.7, MySQL NDB Cluster 7.4., and MariaDB 10.0, 10.1, and 10.2.
- Applicable PHP versions for Magento 2 are PHP ~7.3, ~7.4, and ~8.1. Some compulsory PHP extensions are ctype, mbstring, hash, curl, JSON, and more. Check out the rest of the list here.
- A MTA (Mail Transfer Agent) or SMTP server is necessary for the mail server. You also need a proper security certificate for HTTPS connections, as self-signed certificates are not supported. repo.magento.com and Paypal require TLS (Transport Layer Security) 1.2 or higher.
- Magento 2 works well with the latest versions of browsers like Chrome, Microsoft Edge, and Firefox on any operating system. Safari is supported on iOS 12 (or higher) and macOS for devices like iPhones and iPads. Chrome (mobile version) works on Android 4 or higher.
- Magento 2.4+ requires Elasticsearch 7.6+ for search functionalities, as MySQL isn't applied for search anymore. RabbitMQ 3.8 is also required to handle messaging queues.
#2. Stack Up The Right Technologies
Aside from the system requirements, you should also pay attention to the recommended technology stack. Let's have a closer look!
- Magento 2 is built using the PHP programming language (currently supporting PHP 8.1. version).
- You must install Composer to work with the codebase or create extra Magento extensions.
- Magento 2 currently follows these coding standards: PSR-0, -1, -2, and -3. PSR-4 is not compulsory but highly recommended.
- Some involved front-end techs are CSS3, HTML5, RequireJS, KnockoutJS, and JQuery. Robust catching mechanisms like Varnish and Redis, object caching, and database catching also help improve performance.
#3. Get Authentication Keys
Last but not least, before installing Magento, you need authentication to access Adobe Commerce (plus the Composer package) stored inside repo.magento.com!
To get started, create a Commerce Marketplace profile and use it to generate two authentication keys (each with 32 characters). Ensure these keys are linked to a MAGEID (the primary contact's login credentials for your account) that has permission for the Adobe Commerce packages!
Let us break down the steps for you:
- First, go to the Commerce Marketplace and log in. Have no account yet? Click Register.
- Click on your account name (top corner on the right) > Choose My Profile.
- On the Marketplace tab, choose Access Keys. Click on Create New Access Key and enter the keys' names. Then, click OK.
- You will now see new private and public keys connected to your account. Click on these keys to copy them to the clipboard. That's it! We're now one step closer to our Magento 2 setup.
Need Help To Migrate Your Store?
If you are intending to upgrade Magento 1 to Magento 2, LitExtension offers a great migration service that helps you transfer your data from the current eCommerce platform to a new one accurately, painlessly with utmost security.
Why Should You Install Magento 2 via Composer?
At this point, you must be wondering why you should install Magento 2 Composer instead of any other method. With years of experience in the eCommerce market, we think these are the major advantages you shouldn't miss out on:
#1. Reusing 3rd-party libraries
First of all, you can leverage your existing PHP libraries and tools instead of duplicating code within the Magento installation. Plus, it's easy to include any library listed on Packagist (the PHP package repository) to ensure its versions are always up-to-date! This approach saves disk space and simplifies updates to a great extent.
#2. No more compatibility issues
And here's another significant advantage of Magento 2 installation: thanks to Composer's robust component-based architecture and dependency management, you will no longer struggle with complex Magento extensions!
Specifically, if multiple extensions require different versions of the same library, Composer will automatically manage these versions to prevent conflicts. This smart design reduces the likelihood of encountering “dependency hell.” You can now focus on writing the actual business logic for their extensions rather than worrying for days about compatibility issues.
#3. Adhering to PHP-FIG standards
Aside from the lack of complexity issues and duplicated codes, we are also impressed that Composer aligns Magento 2 with the PHP-FIG standards. PHP-FIG is short for PHP Framework Interoperability Group, which promotes best practices and interoperability between PHP frameworks and components.
Long story short, anyone familiar with these standards (such as PSR-0, PSR-1, PSR-2, PSR-3, and PSR-4) can understand and contribute to Magento's codebase. Better yet, components and libraries can be easily shared and integrated across different projects!
5 Steps to Install Magento 2 with Composer: A Detailed Magento Installation Guide
In the previous sections, we have already covered the key benefits of this installation method and some requirements you need to meet before starting. Now, let's go straight into the main process!
Step 1. Get the source code for Magento 2
First, you need to use Composer to download the source code! Open the command line, then run the command below:
composer create-project –repository-url=https://repo.magento.com/ magento/project-community-edition MAGENTO_LITEXTENSION_FOLDER
Remember to replace MAGENTO_LITEXTENSION_FOLDER with any directory where you want to install Magento!
Step 2. Establish the base URL
Next, create the store's base URL (or the website's primary address)! Run this command:
bin/magento setup:config:set –base-url=”http://LITEXTENSION_DOMAIN/”
Replace LITEXTENSION_DOMAIN with your desired domain name.
Step 3. Configure your admin address
This step is very important if you want access to the admin panel! Run the command below:
bin/magento setup:config:set –backend-frontname=”LITEXTENSION_PATH”
Replace LITEXTENSION_PATH with a secure, unique path to your own admin panel.
Step 4. Configure your database
We're very close to our final step already. But before reaching there, you must set up the database using this command:
bin/magento setup:config:set –db-host=”DATABASE_HOST” –db-name=”DATABASE_NAME” –db-user=”DATABASE_USER” –db-password=”DATABASE_PASSWORD”
Replace all these placeholders with your own database information, and you're all set.
Step 5. Finish your installation
Finally, run the last command to finish installing Magento 2 with Composer:
bin/magento setup:install –admin-firstname=”YOUR_FIRSTNAME” –admin-lastname=”YOUR_LASTNAME” –admin-email=”YOUR_GMAIL” –admin-user=”ADMIN_USERNAME” –admin-password=”ADMIN_PASSWORD” –language=en_US –currency=USD –timezone=America/Los_Angeles
Don't forget to change the placeholders in this code to your own preferred settings and personal details.
It's very simple, right? After Step 5, you can now access your store via the admin address and base URL set up earlier!
Extra Troubleshooting Tips to Install Magento 2 via Composer
Our Magento 2 installation guide above is very clear. However, things do not always go as smoothly as planned, and common issues might surface! In that case, you can consider some possible solutions here:
#1. “The requested PHP extension ext-mbstring * is missing from your system.”
What does this error mean? It indicates your PHP extension (‘mbstring' package) has not been installed. Just use the command below to install it now:
sudo apt-get install php-mbstring
#2. The requested PHP extension ext-iconv * is missing from your system.”
Just like issue #1, the message implies you have not yet installed the PHP extension (‘iconv' package). The following command can fix it for you:
sudo apt-get install php-iconv
#3. “Fatal error: Allowed memory size exhausted”
This time, you have likely set your PHP memory limit a bit too low. Add this code to increase the limit in the php.ini.file:
memory_limit = 2G
#4. “Class ‘Locale' not found”
The message popped up for a reason. Did you forget to install the PHP extension (‘intl' package)? No worries; there's still time to fix that mistake:
sudo apt-get install php-intl
#5. Permission Errors
Another frequent problem when installing Magento 2 is the permission errors. To fix these, you must set the correct directory permissions and file permissions! Remember that files must contain 644 permissions, and folders have 755. Also, make sure your website server user already owns all Magento directories and files.
#6. Missing Dependencies
Lastly, there's the issue of missing dependencies. Go to the root Magento 2 directory, then run composer update or composer install command!
4 Other Alternatives to Install Magento 2
So far, we have discussed steps to install Magento 2 via Composer and addressed some common issues you might encounter. However, if you'd rather not use Composer or prefer different methods, here are five alternatives to go for:
(note that these alternative methods might take less time but lack the above benefits that Composer offers)
Via Cloudways Platform
If using codes and commands (like our guides above) is not your strong suit, the Cloudways platform is a fantastic alternative! Just follow these six simple steps:
- Log into your Cloudways account or create one.
- Create a new server, then choose the Magento version from the Application dropdown. Provide application and server details.
- Choose your preferred Cloud Provider. Select the appropriate server size and bandwidth for your needs.
- Choose your desired server storage. And don't worry, this option is not fixed; you can always scale it up later if needed.
- Pick a server location. Click Launch Server. That's it!
- When the server preparation is completed, go to the Application Management section. Use Access Details to sign in to your store.
Via Zip Archive
Next on our list is Zip Archive, which does involve some codes and commands but is slightly easier than Composer. You need to keep three main steps in mind:
- Download the source code from this link.
- Upload the downloaded archive to your current server and extract it into your root Magento directory. Just use the extract/unzip function for your shared hosting. However, if you're operating on your own server, run these commands instead:
# File .tar.gz
tar zxf <yourfilename># File .zip
unzip <yourfilename> - Then, add a write permission to the pub, app/etc, var folders:
chmod 777 -R var
chmod 777 -R app/etc
chmod 777 -R pub - Launch the installation wizard, then follow the rest of its prompts to install Magento 2.
Via Github
Another popular option is to install via GitHub. Some think this method only works with sample data, but we've found that it works just fine on its own! Here's how:
Install Magento 2 via Github without sample data
- First, you need to get the Magento 2 files. You can either clone the Magento 2 repository (click here) or download the necessary release from here.
- Make a new, empty directory to store the Magento 2 files.
- Navigate to the new directory and run the command below:
git clone [email protected]:magento/magento2.git - Wait for the deployment to complete, then install the required dependencies by running:
composer install - Now, it's time to install Magento 2! Use the following command, making sure to replace the placeholders (base-url, db-password, db-name, admin-password, and admin-email) with your specific details:
php -f bin/magento setup:install –base-url=http://m2.loc/2.07/github/ –backend-frontname=admin
–db-host=localhost –db-name=m2git –db-user=root –db-password=inchoo –admin-firstname=Magento
–admin-lastname=User –[email protected] –admin-user=admin –admin-password=magento456
–language=en_US –currency=USD –timezone=America/California –use-rewrites=1 - Open your web browser and go to the local URL you set during installation. If the page loads correctly, congratulations!
Install Magento 2 via Github with sample data
We just told you how to install Magento 2 via GitHub without sample data. If you want to install the sample data in the setup as well, here's how:
- First, go to your web root directory. Make sure it's not the Magento 2 directory!
- Run the following command to clone the Magento 2 sample data repository:
git clone [email protected]:magento/magento2-sample-data.git - Go to this cloned Magento 2 directory, then run the command below to link the sample data to the Magento 2 installation:
php -f dev/tools/build-sample-data.php — –ce-source=”your Magento CE install dir” - For Linux users, set the correct permissions and ownership:
chown -R :your web server group name
find . -type d -exec chmod g+ws {} \; - Navigate to the var/ folder in your Magento 2 directory and clear the cache with the following command:
rm -rf cache/* page_cache/* generation/* - Finally, install the sample data using these commands:
php bin/magento setup:upgrade
php bin/magento setup:di:compile
Now, the sample data should be successfully installed on your Magento 2 setup!
With XAMPP on localhost
If none of the above options works for you, why not try XAMPP to install Magento 2? Let us guide you through the process:
- Install XAMPP, then download the package from this Magento website.
- Create a new folder named “Magento” in the xampp/htdocs directory.
- Extract your downloaded archive to that Magento folder, then open XAMPP Control Panel, go to Apache, and click Config.
- From the menu that appears, select PHP (php.ini).
- Locate these lines: extension=php_xsl.dll and extension=php_intl.dll, and Remove “;” at the beginning.
- Go back to the XAMPP Control Panel, then start both MySQL and Apache.
- Open your browser and go to localhost/magento2. Agree to the terms and proceed with the Magento setup.
FAQs
How do I install Magento 2?
There are only 5 simple steps to install Magento 2:
- First, install Composer
- Create a project directory for Magento 2
- Use Composer to download Magento 2
- Set up the database
- Run the installation script and verify the setup.
What are the prerequisites for Magento 2 installation?
Before installing Magento 2, make sure you meet all these requirements:
- Database: MySQL 5.6+
- PHP: 5.6+
- Web server: Nginx 1.7x or Apache 2.2x
- Operating system:s Cross-platform.
- Browsers: Firefox, Internet Explorer, Google Chrome, etc.
- SSL: A working security cert for the HTTPS.
What hardware is required for a Magento 2 server?
Your Magento 2 server must use Linux-based operating systems, and its memory should be at least 2GB of RAM.
Final Words
We've guided you through 5 easy steps to install Magento 2. While some coding is involved, the process is still quite straightforward!
However, if you're new to this and need to migrate from another platform to Magento as soon as possible, our experienced LitExtension Expert team is ready to help.
We have assisted over 200,000 customers worldwide from 100+ countries in migrating their stores to different platforms, with a satisfaction rate of up to 99%! You need zero technical knowledge during the entire process, and our 24/7 support team will be with you every step of the way.
Visit our LitExtension blog and join our eCommerce community for more support.