Developing for Magento
Prep Your Environment
Make sure you have themost up-to-date version ofMagento downloaded.
Start by downloading the latest release of Magento from
http://magentocommerce.com/.
LAMP/WAMP Platform
If you are on theWindows platformthe easiest way to install PHP, Apache andMySQL
is with the XAMPP family of packages from http://apachefriends.org. Install the
XAMPP-lite package anywhere on your drive and run the setup.bat file. There is a
version of XAMPP forMac OS X and Linux as well.
Subversion
For developing your own modules, it is recommended that you use Subversion
version control to keep track of all of your code changes. TortoiseSVN from
http://tortoisesvn.tigris.org is the recommended client and server for Windows
users. For Mac and Linux users, the command line svn program plus the PHP package
websvn is recommended. If you are not familiar with the Subversion system, you
can read more about it at the SubversionWeb site (http://subversion.tigris.org/).
MySQL Tools
Apart from the actual MySQL server, it is most useful to have a graphical client to
inspectMagento’s database tables from time to time. TheMySQL Query Browser tool
is the official client provided by MySQL AB and is available for all major operating
systems. Some users prefer mysqlcc or phpMyAdmin over MySQL Query Browser,
though.
Installation
Unzip Magento into your Web server’s document root (from here on, referenced as
{docroot}). You should see a directory layout like this:
{docroot}/magento/
app/
index.php
js/
lib/
LICENSE.txt
media/
pear
skin/
var/
Database Setup
Magento will not create its required database for you, even if your database user
has proper rights to create a database. Because of this, we will need to create the
database using one of the previously mentioned MySQL tools. A normal database
name, sometimes called a schema, can be “magento”, or “magento_dev”, or you can
even include the version number “magento_10”.
Magento Setup
You should now continue withMagento’s base installation by pointing your browser
to http://localhost/magento/. Here, you will see a basic step-by-step form for in
stalling most PHP Web applications. Follow the on-screen directions and your Magento
installation will be complete.
Sample Data
If this is your first time trying out Magento you should install the optional sample
data. The sample data is provided as a separate download as it is about 35 MB. The
sample data provides some sample products, categories, and product images. Once
you have downloaded the package, copy the media folder over your own media folder
under your Magento installation. Then run the provided SQL file with your MySQL
management tool.
As of the time of thiswriting, the sample data is distributed as a complete database
installation. Therefore, it needs to be inserted before you proceed with the regular
setup. The regular setup will actually upgrade the sample data to the latest version.
Initializing Subversion
Magento has three directories from which modules are executed: core, community,
and local. All the examples in this book assume that you are developing in the local
module directory. Under the local directory, you can group all of your modules together
under one package. This package is called Mage for all magento core modules,
but this book will use Company for all the examples. You can use any package name
besides Company for a package name that represents your company or organization.
Initializing subversion is a bit tricky. First, you need to initialize a repository. Then,
you need to create a folder or directory to import into this new repository. After that
you are not ready to start using subversion. The directory which was imported needs
to be removed, and then checked out of the repository in order for it to be connected
with subversion. Let’s look at the steps in detail.
Picking a subversion repository on the Linux platform is pretty easy. After
installing Subversion from RPM, there usually exists a directory similar to
/var/lib/subversion/repositories/. Initialize a new repository with the command:
svnadmin create /var/lib/subversion/repositories/magento_modules
If you are using TortoiseSVN underWindows, create a folder anywhere on your computer,
right-click that folder, and select Create repository here… from the TortoiseSVNmenu.
Our goal for setting up Subversion is to have a folder named Company under the
app/code/local directory of Magento. This will allow us to easily add new modules
and save our work to Subversion whenever we want. Create a new directory under
the app/code/local folder called svn_import. Under this temporary svn_import directory
create another folder called Company, or whichever name you’ve decided to use
for your packaging. If you are running on a Unix platform, run this command from
inside the svn_import directory (ignoring the shell prompt):
[svn_import]$ svn import . \
file:///var/lib/svn/repositories/magento_modules/
OnWindows, use TortoiseSVN by right-clicking on the svn_import folder and choosing
the Import… menu item. A new dialog will appear and ask you to input the
URL of the repository. Click the ellipses button and browse to the folder which you
designated as your repository in the previous step.
Delete the svn_import folder after successfully importing into your new repository.
Next, we need to checkout the folder we just imported to get a Subversion activated
directory. On Unix:
[local]$ svn checkout \
file:///var/lib/svn/repositories/magento_modules/Company
OnWindows, right click on the local folder and choose SVN Checkout…. Accept the
default settings in the dialog, and confirm Yes when it asks you if you really want to
overwrite the folder.
Covering all Subversion commands is beyond the scope of this book. But you are
now prepared to develop and save your custom Magento modules in a subversion
directory if you so choose.