Before we begin… System Requirements and don’t have composer? Get Composer

… and GO!

Note: The following is based on my current Magento 2 experience and is really my preferred way of working with the platform to date. You may or may not find it useful.

If you haven’t already, create a directory you want to install Magento 2.

I put all my sites in ~/Sites.

mkdir -p ~/Sites/<projectName> && cd ~/Sites/<projectName>

Now let’s download the project files:

composer create-project \
    --no-install \
    --repository-url=https://repo.magento.com/ \
    magento/project-community-edition \
    public_html

Why the –no-install flag?

When i am first creating a project i like it to be as quick as possible. –no-install only downloads the basic project files ready to be installed at your convenience later on.

Authentication required (repo.magento.com):?

To install magento this way you need to have an account over at https://magento.com.

  1. Create account / login
  2. Go to My Account > Connect > Developers > Secure Keys
  3. Generate a new key (call it what you like)

The public key is your username and therefore your password is the private key.

It will ask you if you wish to store your details. Choose an option then continue on.

…Wait (for the modules to be download)…

Next thing to do is to use composer to download all of Magento’s dependencies.

Inside the public_html (cd public_html) folder run:

composer install

Note: This may take a little while.

The first time you run a composer install on a system it will take a little bit of time because it has to download all of the files. The next time it can use the cached versions (unless you specify otherwise).

Create a database with your favourite editor.

Then run (replacing the details with your own):

php bin/magento setup:install \
    --db-host=127.0.0.1 \
    --db-name=magento2 \
    --db-user=root \
    --db-password=password123 \
    --base-url=http://www.example.com/ \
    --admin-user=admin \
    --admin-firstname=Smartie \
    --admin-lastname=Woo \
    --admin-email=[email protected] \
    --admin-password=password123

Note: If you use a blank password (perhaps for local development) you need to omit the –db-password parameter completely.

On the screen will appear something like:

...
Module 'Magento_Translation':
[Progress: 289 / 305]
Module 'Magento_Shipping':
[Progress: 290 / 305]
...

This is effectively your progress bar.

After those have finished you should see [SUCCESS]: Magento installation complete.

You will also see a URL to your admin area. If you do not specify the installation option --backend_frontname Magento will create a (more secure) URL for you that will look something similar to /admin_[randomBitsHere].

Visit your base url (http://www.example.com/).

There are a number of other options you can add to the setup:install command if you wish to customize the installation a little more.

BOOM!

Now how about some sample data?

Simple.

Magento provides a handy tool to install and uninstall the sample data that comes in the form of sample data modules.

To install them:

php -d memory_limit=2G bin/magento sampledata:deploy

Again, this may take a little time to run.

bin/magento can be run without the php prefix if you make it executable like so:

chmod +x bin/magento

Go here for more information on sample data deployment.

Done

Let’s not lose our work though!

Inside our public_html run:

git init && git add . && git commit -m 'Initial commit'

WOAH! That’s a lot of commands, what am i doing?

Well simply we are turning it in to a git repo (with git init), adding all the files (with git add .) and committing all the files (with git commit -m 'Initial commit').

The end.

Edit

I have wrapped some of the above commands in to a shell script leaving out the actual install as you will need to modify quite a few of the variables.

  • magento2
  • composer

Like this post? Share it :)


Related Posts

Back