Table of contents
Starting from Magento version 2.4.2 onwards, command line is the default (and only) method for installing Magento. And while you could technically download an archive of the Magento version that you want to install, this method is not really recommended and you should use Composer to download Magento instead, as it provides various more benefits including:
- Reuse third-party libraries without bundling them with source code
- Reduce extension conflicts and compatibility issues by using a component-based architecture with robust dependency management
- Adhere to PHP-Framework Interoperability Group (FIG) standards
- Repackage Magento Open Source with other components
- Use the Magento software in a production environment
Note: You may want to check Magento 2 System Requirements first before installing Magento using Composer.
Step 1: Install Composer
- Run the following command to check if Composer has already been installed:
composer --help composer list --help
- If nothing displays or you face any errors, please install Composer:
Create an empty directory on your Magento server and run the following commands:
curl -sS https://getcomposer.org/installer | php mv composer.phar /usr/local/bin/composer
- Run the following command to make your Composer globally available
mv composer.phar /usr/local/bin/composer
Step 2: Download Magento 2
Run the following command in the root directory.
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition .
For example, let’s say we want to download Magento 2.4.2 in our root directory.
composer create-project --repository-url=https://repo.magento.com/ magento/project-enterprise-edition=2.4.2 .
Step 3: Set Up Permissions
You should set correct permissions for the whole Magento 2 installation directory by running the below command:
find . -type f -exec chmod 644 {} \; find . -type d -exec chmod 755 {} \; chmod -Rf 777 var chmod -Rf 777 pub/static chmod -Rf 777 pub/media chmod 777 ./app/etc chmod 644 ./app/etc/*.xml chmod -Rf 775 bin
Step 4: Create The Database
Create an empty database to work with MySQL in case you have already have correct permissions:
echo "CREATE DATABASE magento2" | mysql -u[mysqluser] -p
Step 5: Install Magento 2
Run the following lines in Command Line to install your Magento 2:
php bin/magento setup:install --base-url="http://yoururl.com/" --db-host="localhost" --db-name="dbname" --db-user="dbuser" --db-password="dbpass" --admin-firstname="admin" --admin-lastname="admin" --admin-email="[email protected]" --admin-user="admin" --admin-password="admin123" --language="en_US" --currency="USD" --timezone="America/Chicago" --use-rewrites="1" --backend-frontname="admin"<b> </b>
base-url
: the path that your Magento directory is in, which follows the following format: http[s]://<host or ip>/<your Magento install dir>/
db-host
: the hostname or IP address of your hostdb-name
: change it to the name of the Magento database you just createddb-user
: a database user with full permission. We’ll be using the default root user.db-password
: the password of your database user. Leave it blank if you’re using ‘root’ database useradmin-firstname
: your first nameadmin-lastname
: your lastnameadmin-email
: your email addressadmin-user
: the username which you’ll be using to log into Admin Paneladmin-password
: the password which you’ll be using to log into Admin Panellanguage
: the language which you’ll be using in your Admin Panel and your storefront. Use language code likeen_US
.admin-email
: change it to your emailcurrency
: set the default currency to use in your storefront.Enterphp bin/magento info:currency:list
for a list of supported currencies along with their codestimezone
: change to the timezone that you’re in. Refer to the list of supported timezones for a better idea on what to fill.url-rewrites
: set to 1 to enable Web Server Rewrites. This will help with your site ranking.backend-frontname
: set your Admin URL. Omitting this parameter will result in a randomly generated URL for your Magento Admin path (e.g., admin_jkhgdfq)search-engine
: set the version of Elasticsearch that you want to use for this Magento installation. The default is elasticsearch7elasticsearch-host
: the hostname or IP address where Elasticsearch is running. The default is localhostelasticsearch-port
: the port number that Elasticsearch is listening to. The default is 9200
For more configurable options, please refer to the official guide by Magento.
Wait for a while and if you see this message:
Post installation file permissions check… For security, remove write permissions from these directories: 'C:/xampp/htdocs/magento24/app/etc' [Progress: 1270 / 1270] [SUCCESS]: Magento installation complete. [SUCCESS]: Admin Panel URI: /admin Nothing to import.
You have successfully installed Magento using Composer!
The above values are just examples, you definitely should change them according to your own info.
Hope this helps!
DON’T MISS:
How to Setup Magento 2.3 PWA Studio With Custom Theme
How to Install Magento 2 on Ubuntu 16 Using Nginx
How to Install Magento 2 on Localhost
How to Install Magento 2 on WAMP Server Localhost