Creating a Magento 2 Project with 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.
Now let’s download the project files:
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.
- Create account / login
- Go to My Account > Connect > Developers > Secure Keys
- 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:
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):
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:
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
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:installcommand if you wish to customize the installation a little more.
Now how about some sample data?
Magento provides a handy tool to install and uninstall the sample data that comes in the form of sample data modules.
To install them:
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:
Go here for more information on sample data deployment.
Let’s not lose our work though!
Inside our public_html run:
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
git commit -m 'Initial commit').
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.
Like this post? Share it :)