Book Image

Magento 1.8 Development Cookbook

By : Bart Delvaux, Nurul Ferdous
Book Image

Magento 1.8 Development Cookbook

By: Bart Delvaux, Nurul Ferdous

Overview of this book

<p>Magento is an open source e-commerce platform which has all the functionality to function from small to large online stores. Its architecture makes it possible to extend the functionalities with plugins where a lot of them are shared by the community. This is the reason why the platform is liked by developers and retailers.</p> <p>A practical developer guide packed with recipes that cover all the parts of Magento development. The recipes will start with the simple development exercises and get the more advanced as the book progresses. A good reference for every Magento developer!</p> <p>This book starts with the basics. The first thing is to create a test environment. Next, the architecture, tools, files and other basics are described to make you ready for the real work.</p> <p>The real work starts with the simple things like theming and catalog configuration. When you are familiar with this, we will move on to more complex features such as module and database development. When you have survived this, we will move on to the last part of making a shop ready for launch: performance optimization and testing. This book will guide you through all the development phases of Magento, covering the most common pitfalls through its recipes.</p>
Table of Contents (19 chapters)
Magento 1.8 Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preparing the development environment


We will set up a development environment with Magento. For this, we need to set up a LAMP (Linux, Apache, MySQL, PHP) environment. In that LAMP environment, we will create a Fully Qualified Domain Name (FQDN) and a virtual host.

Getting ready

We have to set up a development server that we will use to run Magento. When we have a Ubuntu desktop environment, we have to install the latest versions of the following software:

  • Apache2

  • PHP

  • MySQL server

  • Extra PHP libraries

We can install these software by running the following commands on a CLI interface. These commands are based on a Ubuntu-based Linux distribution. To run the commands on a desktop with Ubuntu OS, launch the Terminal program:

  • To install the web server Apache2, run the following command:

    sudo apt-get install apache2
    
  • To install PHP, run the following command:

    sudo apt-get install php5
    
  • To install the MySQl server, run the following command:

    sudo apt-get install mysql-server
    
  • To install the required PHP extensions that Magento uses, such as the MySQL bridge, run the following command:

    sudo apt-get install php5-mysql php5-curl php5-gd php-pear
    

How to do it...

When everything is installed, we will create a virtual host with an FQDN. We want our development environment to be available at http://magento-dev.local/. To do this, we have to create a virtual host with this domain name. This domain points to the IP of our previously created web server.

The following steps describe how you can create a virtual host with an FQDN:

  1. Create a magento-dev.local file in the /etc/apache2/sites-available/ directory.

  2. To create and edit the file, run the following command:

    sudo nano /etc/apache2/sites-available/magento-dev.local
    
  3. Paste the following content in that file:

    <VirtualHost *:80>
     # ServerName (domain) and admin email
     ServerAdmin [email protected]
     ServerName magento-dev.local
    
     DocumentRoot /var/www/magento-dev.local/public # Folder of the site. We have to create this
    
     # Log file locations
     LogLevel warn
     ErrorLog /var/log/apache2/magento-dev.error.log
     CustomLog /var/log/apache2/magento-dev.access.log combined
    </VirtualHost>
  4. Run the following commands in the terminal to create the www root folder:

    1. To create the site folder (document root), run the following command:

      sudo mkdir /var/www/magento-dev.local/public
      sudo chown -R www-data:www-data /var/www/magento-dev.local/
      
    2. To enable the site, run the following command:

      sudo a2ensite magento-dev.local
      
    3. To reload the Apache server, run the following command:

      sudo service apache2 reload
      
    4. To test the site, we have to add the following line in our host's file (/etc/hosts):

      127.0.0.1 magento-dev.local
      

      This will point the domain magento-dev.local to the IP address 127.0.0.1. This is the IP address of the local web server (localhost), so a request to this URL doesn't go to the Internet but goes to the local web server.

How it works...

This recipe describes how to install a web server from a CLI interface. If you already have a web server with a specific domain, you can skip this chapter.

The Magento files will be installed in the public directory. When a request is made to the domain, the www-data user will execute the request. So, it is best that all files and folders have the www-data user and group to avoid permission problems.

On a Linux server, every file and folder has three types of permissions. These permissions are read, write, and execute (rwx). You can set these permissions in three scopes: for owners, groups, and others. On every file request, Linux decides, based on the permissions, whether a user can read, write, or execute a certain file.

For an HTTP request, the www-data user will be used to execute a request. So, it is important to ensure that the www-data user has enough file permissions to run the application. To change file permissions, you can use the chmod command. To change the owner and group, you can use the chown command.

There's more…

It is also possible to run Magento and the web server on other operating systems. To run a web server, we need Apache, MySQL, and PHP. It is possible to install these software on a Windows or Mac device.

The variant for Windows operating systems is WAMP (Windows, Apache, MySQL, and PHP). You can find more information about this variant on the WAMP website at http://www.wampserver.com.

For Mac OS, the alternative is MAMP. More information on MAMP is available at http://www.mamp.info.

A cross-platform web server is XAMP. You can download the installer for Linux, Windows, or Mac from their website at http://www.apachefriends.org/en/xampp.html.