Install Magento 2 via Composer

# Navigate to the html folder.
cd /var/www/html
# Temporally move the git folder.
sudo mv local.magebootcamp.com/.git .git
# Now remove the local.magebootcamp.com folder
# because we are going to recreate it.
sudo rm -R local.magebootcamp.com/*
cd local.magebootcamp.com
# Make sure you also deleted the PHPStorm config.
rm -R .idea

Clean up files

The first step for installing a fresh Magento installation is making sure you have a clean folder. We have previously done some testing with git in the folder. The ‘composer create-project’ command needs an empty directory to create a new project.

So we are going to delete the files and move the git out of the folder. By doing this we can create the Magento project. After we created the project we will move the git folder back.

Download Magento

To download the Magento 2 project we are going to create a new composer project with the Magento 2 repository.

For the installation of Magento, you need an API key. To obtain the keys you need to go to the Magento Marketplace and press sign-in on the right top corner. Here you can register a new Magento account. After filling in your details, you need to go to the access keys

After filling in the correct key Magento will be installed in the local.magebootcamp.com folder. Now it’s time to grab a fresh cup of coffee because this can take some time. 

# Download Magento command
composer create-project --repository=https://repo.magento.com/ magento/project-community-edition .
# After installation we need to put back our git file
sudo mv ../.git .git
# You now need to access your database
mysql -u root -p
# now type in your password
# Now we are going to create the database
CREATE DATABASE magebootcamp;

Create a Database

We are simply going to create a database to store all the Magento tables. We are going to call the database magebootcamp. Make sure you use the same database name later on with the install script.

Install Magento

Ok, now we are going to install Magento. For the installation, we need a setup command. This command tells Magento which database we are going to use and what settings we want. Optionally, you can also use the GUI but I prefer the CLI because it is faster.

The installation can take a while so this is a great time to grab a cup of coffee.

# Let's first go to your home dir
# Now we want to configure the installation command
nano install-magento.txt
# Oke, now configure the installation command as you like:
m2 setup:install \
--base-url=https://local.magebootcamp.com/ \
--db-host=localhost \
--db-name=magebootcamp \
--db-user=root \
--db-password=MageBootcamp1! \
--admin-firstname=Daniel \
--admin-lastname=Donselaar \
[email protected] \
--admin-user=daniel \
--admin-password=admin123 \
--language=en_US \
--currency=USD \
--timezone=America/Chicago \
# Now press [ctrl] + [o] to save
# Press [ctrl] + [x] toexit
# Now go to your Magento root folder
cd /var/www/html/local.magebootcamp.com
# Past the setup script and press [enter]

The Magento Homepage

Great job! If everything went right you will see the Magento 2 homepage. Now it’s time to install the sample data. If you have any questions, please let me know.

Scroll to Top