Patrick Ward words, code, and music

Setting Up Magento From Within the Shell

Setting up Magento can be a pain sometimes, so when I’m starting a new extension or working on a new client site, I like to minimize that pain.

Because I’m a sucker for the command line shell, I also try to do as much as possible from within that environment. Thankfully, Magento provides the ability to install from the command line. I find installing from the shell to be less error prone and, in most cases, quicker.

So, these are the basic steps I take each time I need to install a Magento system. I’m assuming you’ve already created a new database in MySQL.

Sample Data

I keep a copy of the latest Magento sample data on hand. But, if you don’t have a copy, you’ll find it on their website in the community downloads section. Sample data is great for building new extensions as it provides you with a working store complete with products, categories, etc. However, it may not be appropriate if you’re working on a new client store.

If you are going to use sample data, it’s important that you install this into a new database before you run the Magento installation itself.

So, from the command line, I do a simple MySQL import:

mysql -uusername -p magento_dev \
< magento_sample_data_for_1.6.1.0.sql

Installing Magento

Next, I’ll tackle the installing of Magento. For that, Magento has several command line options that can be passed to the install.php file. Because I sometimes make mistakes and have to redo the installation, I’ll often just write the commands into a single install.sh file. This let’s me double-check the parameters and have a handly install script that can be used multiple times.

I tend to use all of the installation command line parameters with the exception of the database table prefix command. So, my install.sh file usually looks like this:

#!/bin/sh

php -f install.php -- \
--license_agreement_accepted yes \
--locale en_US \
--timezone "America/New_York" \
--default_currency USD \
--db_host localhost \
--db_name magento_dev \
--db_user root --db_pass root \
--url "http://mage.dev/" \
--use_rewrites yes \
--use_secure yes \
--secure_base_url "http://mage.dev/" \
--use_secure_admin yes \
--admin_lastname Admin \
--admin_firstname Magento \
--admin_email "magento@localhost" \
--admin_username admin \
--admin_password password101

I place this above the actual document root for the webserver, which makes installing Magento as simple as:

../install.sh

Indexing

Magento also has an indexer tool you can use from the command line. So, after I run the installation, I’ll immediately index the tables before I open the web interface. From within the Magento root directory, the following command will cd into the shell folder, index the tables, and return you to the root directory.

cd shell && php -f indexer.php reindexall && cd ..

That’s it!

I find this simple process to be the best way to install Magento, whether I’m in development or production. It’s simple, reproducible, and quick.