8 min read

Magento is an open-source eCommerce stack with smart features such as layered navigation, auto-complete search, multiple language support, multiple stores, smart browsing, RSS product feeds, tagging and reviewing products, reviewing search terms, reviewing customer tags, poll manager, currency exchange rates, Google sitemap integration, abandoned shopping cart report, catalog-wide product comparisons, product wish lists, and even zooming the product image. It was created by Varien, based on the top notch MVC framework—Zend Framework, on March 31, 2008. As with other MVC applications, Magento keeps the display logic separated from the application’s business logic. A dedicated team works on updating Magento regularly.

Magento Developer is a very hands-on role for both a novice and experienced software engineer who is interested in achieving high impact in a fast-paced development environment with an ambitious mission. Magento gives a very handy way to deal with its features faster than any other alternatives, whether you know a little or a lot about PHP programming. Let’s see how these things happen.

We will make our development platform ready to cook some mouth-watering recipes for Magento in this article. If you are a newbie, this is the right place to start. If you are a pro, this is still the right place to start as we have tried to follow some best practices for Magento development that you might not be aware of. Let’s get our hands dirty with Magento Development! Good luck!

Preparing the platform with a virtual host

Magento is built on the de facto PHP framework—Zend Framework. We need to set up our development environment properly to get most out of it. In this recipe, we will set up a Fully Qualifed Domain Name (FQDN) and a virtual host. We could use the domain as http://localhost/magento or something like this, but in that case accessing the admin panel might be cumbersome. In most cases, you have to access through the local IP address. Using a FQDN, you don’t have to worry about it. A FQDN will make the debugging process much easier also.

Getting Ready

We need to have the following things installed before kicking off the setup of a virtual host a.k.a. vhost:

  • Apache2
  • PHP5
  • MySQL server 5.0

If we want to install the previously mentioned tools from Ubuntu Linux CLI, we can easily do that by running the following commands. We will be using Linux commands based on Ubuntu.

The following command is a basic Apache installation command:

sudo aptitude install apache2 apache2.2-common apache2-mpm-prefork 
apache2-utils libexpat1 ssl-cert

The following command is a basic PHP5 installation command:

sudo aptitude install libapache2-mod-php5 php5 php5-common php5-curl 
php5-dev php5-gd php5-imagick php5-mcrypt php5-memcache php5-mhash php5-
mysql php5-pspell php5-snmp php5-sqlite php5-xmlrpc php5-xsl

Enter the following command to begin with a simple MySQL installation:

sudo aptitude install mysql-server mysql-client libmysqlclient15-dev

Note that we have installed the development libs and headers with the libmysqlclient15-dev package. You can leave that out but it has been found that they are useful in many situations.

Alternately, we can use an all-in-one package, such as the XAMPP, to get all the aforementioned tools in one click. The XAMPP package can be downloaded from http://www.apachefriends.org/en/xampp.html.

How to do it…

  1. To test the domain without creating a DNS zone and record(s) on some Internet nameserver(s), let’s modify the /etc/hosts file on our local computer to include some entries mapping the magento.local.com, and so on to the local machine’s public IP address (in most cases, 127.0.0.1). Open the /etc/hosts file with any text editor or run the following command in terminal:
    sudo nano /etc/hosts
  2. Add the following line as a similar entry in /etc/hosts file:
    127.0.0.1       magento.local.com

    The location of the host file depends on the OS loaded. If it’s a Windows OS it should be c:windowssystem32driversetchosts.

  3. Now let’s create the layout for our domain. Open terminal and change your location to the WEBROOT directory by running the following command:
    cd /var/www/

    If you are using XAMPP, it would be c:xampphtdocs.

  4. Now for our domain, we want to host/create a folder with a standard set of subfolders:
    mkdir -p magento.local.com/{public,private,log,cgi-bin,backup}
  5. Let’s create an index.html file for our domain:
    sudo nano /var/www/magento.local.com/public/index.html
  6. It’s time to put some content in our index file:
    <html>
      <head>
        <title>Welcome to magento.local.com</title>
      </head>
      <body>
        <h1>Welcome to magento.local.com</h1>
      </body>
    </html>
  7. We’ve set up the basics and now we’re ready to add our own virtual hosts, so that we can start to serve our domain. Let’s go ahead and create the vhost file for magento.local.com:
    sudo nano /etc/apache2/sites-available/magento.local.com
  8. The contents should look like this:
    # Place any notes or comments you have here
    # It will make any customization easier to understand in the weeks 
    to come
    # domain: magento.local.com
    # public: /var/www/magento.local.com/public
    <VirtualHost *:80>
      # Admin email, Server Name (domain name) and any aliases
      ServerAdmin [email protected]
      ServerName  magento.local.com
      # Index file and Document Root (where the public files are 
    located)
      DirectoryIndex index.php index.html
      DocumentRoot /var/www/magento.local.com/public
      # Custom log file locations
      LogLevel warn
      ErrorLog  /var/www/magento.local.com/log/error.log
      CustomLog /var/www/magento.local.com/log/access.log combined
    </VirtualHost>
  9. Now we have the site available, we need to enable it:
    sudo a2ensite magento.local.com
  10. It seems like good advice to reload the apache:
    sudo /etc/init.d/apache2 reload
  11. With such changes made, we can now navigate to our site in a web browser on our local computer, as seen in the following screenshot:

Tada! We now have the contents of public/index.html being shown.

How it works…

The Getting ready recipe describes the installation process of Apache, PHP, and MySQL from Linux command line. If you have already installed those, you can skip it and start confguring the layout and vhost directly.

The Magento source files will be put in the public directory. Other directories represent as their name suggest. Usually in production server, we don’t have to write the domain name manually as we wrote here, as the DNS zone is there. The rest of this recipe is the same as the production server. The virtual host contents has some inline comments starting with # to describe the purpose.

Setting up a Subversion/SVN

A Subversion is a popular version control system initiated in 2000 by CollabNet Inc. Its goal is to be a mostly-compatible successor to the widely used Concurrent Versions System (CVS).

Getting Ready

If you are a Windows user, please download the TortoiseSVN client from here: http://tortoisesvn.tigris.org/ and if you are a Linux user, fre up your terminal.

How to do it…

  1. Execute the following command in the terminal to install Subversion:
    sudo apt-get install subversion

    Make sure you have an active Internet connection as aptitude will install the package from Ubuntu repository.

    If you are using windows and intended to use TortoiseSVN you may get a Windows binary from http://tortoisesvn.tigris.org.

  2. After downloading the TortoiseSVN installer file, double-click on the TortoiseSVN installer file and follow the on screen instructions.
  3. Now let’s add a new group called Subversion to our system and add current username to Subversion group.
    sudo addgroup subversion
    sudo adduser <your_username_here> subversion

    If you don’t a have a clue about your current username, issue the command whoami in your terminal.

  4. Once the Subversion installation is completed, let’s create our repository for Magento project. Now issue the following command in the terminal:
    sudo mkdir /home/svn
    cd /home/svn
    sudo mkdir magento
    sudo chown -R www-data:subversion magento
    sudo chmod -R g+rws magento
  5. Now initiate an SVN repository with the following command:
    sudo svnadmin create /home/svn/magento
  6. In the case of TortoiseSVN, open the folder where you want to put your Magento repository and right-click and find create repository here… from the context menu TortoiseSVN. Enter a name for your repository, in this case the repository name would be magento.
  7. It’s time to change your current working directory in terminal to:
    cd /var/www/magento.local.com
  8. We will checkout the Magento project by issuing the following command in the terminal:
    svn co file:///home/svn/magento public

How it works…

When we execute any apt-get command, the aptitude will take care of the installation process. The aptitude will look for the package from Ubuntu central repository—and download it if necessary—and perform the necessary tasks.

After completion of the installation process, we’ve created a new group named subversion and added the username to the newly created group subversion. Then we’ve created a directory under /home/location to hold all repositories. After that, we’ve created a new repository for our Magento project named magento. Finally, we’ve checked out the repository in our site location in the public directory.

LEAVE A REPLY

Please enter your comment!
Please enter your name here