Welcome to Kishan Savaliya's Magento 2 Blog. Today I will provide you guidence how to install Magento 2 using Composer ?
Note :
- Before installing Magento 2 you need Composer pre-installed, if you want to installed it via composer. You can check here how you can install composer.
- After composer installation, Check Magento 2 Basic System requirements. You can check Magneto 2 Official documentation here for detailed information, Here I'll show you basic steps to install Magento 2 using composer.
- Supported PHP versions.
- ~7.2.0
- ~7.3.0
- Supported PHP versions.
Steps : How to install Magento 2 using Composer ?
Step - 1. Go to your Magento 2 Root directory and run below command in terminal.
In your terminal, Go to your Magento 2 root directory path and run below command inside that directory to install Magento 2 via composer.
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition .
Here "." is your current directory. If you're running above command from another directory then try to set installation directory path there like below..
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition /var/www/html/magento2/
Here "/var/www/html/magento2/" is Magento 2 installation directory path. You can change it based on your requirements. Using this command, you can download latest Magento 2 version.
Step - 2. Set Magento 2 file and directory permissions.
Before Magento 2 installation, you must have to set read/write permissions for your webserver group. Go to your Magento 2 installation directory and run below commands one by one.
cd /var/www/html/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 {} +
chown -R :www-data .
chmod u+x bin/magento
Step - 3. Install Magento 2 via Command line
Before running Magento 2 installation command, you need one empty database. So run below command to create new empty database via command.
echo "CREATE DATABASE magento2" | mysql -u[mysqluser] -p
Here you can use your database name instead of magento2 word in above command, instead of mysqluser, you can use your mysql username without brackets. Whenever you will run above command it'll ask you to add password, so you need to add your mysql password there and above command will create your empty database.
After creating an empty DB, you can run below command to install Magento 2.
bin/magento setup:install \
--base-url=http://localhost/magento2 \
--db-host=localhost \
--db-name=magento2 \
--db-user=magento2 \
--db-password=magento2 \
--admin-firstname=admin \
--admin-lastname=admin \
--admin-email=username@example.com \
--admin-user=admin \
--admin-password=admin123 \
--language=en_US \
--currency=USD \
--timezone=America/Chicago \
--use-rewrites=1
Here you can use your Base URL instead of http://localhost/magento2 and you can use your DB host, name, username and password. Also you can set your first and last name, email, password for Magento 2 backend.
Hope you may like this article and can understand this easily. You can add comments below in case if you have any questions regarding this article or if I missed anything here. I will check and get back to you with proper solution.
If you enjoyed this blog post, share it with friends!