In Ecommerce Applications, Hosting Guides

Creating a Magento multi-store using symlinks

Posted by

Magento is a web application designed so that other users or developers can add to its capabilities. One of its popular features is the creation and management of multiple store fronts within a single Magento account. This is known as a Magento multi-store. This guide will demonstrate how to do this.

A new store would be known as the ‘child’ store, and you would be linking it to a ‘parent’ store, an existing Magento store you have, ensuring that the application is tightly integrated with your Plesk Panel.

You can do this by creating each child store as an individual subscription within the Plesk Panel, then linking each child store to the parent store, using what is known as a symbolic link. A symbolic link can be thought of as the Linux equivalent to a shortcut. This method requires each SSL Certificate is applied to a unique IP address, and though the setup is more complex, it is a more robust solution.

The requirements

You should note the guide assumes the following:

  • You are currently making use of the NuBlue Virtual Private Server (VPS), where root (administrator) access is provided. This is essential as you are required to create configuration files through the command line, and further administrate the Plesk Panel via the command line interface. If you are a NuBlue dedicated server customer then please contact us via our normal support channels and we can look to assist you directly.
  • Your VPS is running Plesk Panel 10 or higher. If you are currently running a lower version of the Plesk Panel and are looking to upgrade, as long as your existing web-applications are PHP 5.3 compatible, we can offer you a free upgrade to the latest version!
  • You have an existing Magento store running on your VPS or dedicated server hosting solution

Throughout the following guide we are using the following implementation:

  • Plesk Panel 11
  • PHP 5.3, MySQL 5.1, Apache, nginx
  • Magento 1.7.0.2 (released July 2012)

The scenario

We currently have an existing Magento store, www.tshirts-uk.co.uk, that sells t-shirts within the United Kingdom (NuBlue t-shirts are not yet available, sorry!). We are looking to expand our Magento store to sell t-shirts on an international scale, with plans to expand to the United States and then to parts of the EU should our first foray to foreign shores be successful.

Configure Magento

We first need to configure our existing Magento instance to integrate with our new child store. This can be done directly within your existing Magento Admin Panel. Browse to ‘System’ and ‘Manage Stores’.

1If you have a default Magento configuration, you should see the above store layout. Click on ‘Create Website’, ‘Create Store’ and ‘Create Store View’. As these are somewhat dependant on each other, once all three are created you can go back and link them to each other. E.g. you cannot select the ‘T-Shirts US Store View’ (our new child store) as the ‘Default Store View’ when creating your new store until the Store View has been created.

The following three screenshots should give you an idea on how to configure your new ‘Website’, ‘Store’ and ‘Store View’ correctly.

2

3

4

You should now have something that looks like the below screenshot.5Our final step for configuring Magento for use with your new child store is to edit the two base URL variables. This is done within your Magento Admin Panel under ‘System’ and ‘Configuration’. Browse to ‘Web’ and under ‘Unsecure’ and ‘Secure’ edit the current base URL, which should presently be set to your parent store, to that of your child store. It is imperative that you leave the trailing slash in place, and that you should note the differences between unsecure (http://) and secure (https://) within your configuration. Once these changes have been made, clear your Magento cache.

6

Create a symlink

Step one: create our child store

As Magento should already be configured using the instructions above, the next step is to configure the new child store domain within your Plesk Panel. This process involves creating a new subscription, before adjusting the document root.

To create a new subscription within your Plesk Panel browse to ‘Subscriptions’ and then click ‘Add New Subscription’, filling in the relevant text boxes as required.

7

Your configuration should now look something similar to the above.

Step two: configure our symbolic link

We now need to configure our new subscription, tshirts-us.com, to share the same document root as our parent store, tshirts-uk.co.uk. To do this, we will be creating a symbolic link that will point the document root for our child store to our parent store.

To do this, select ‘Manage hosting’ on the subscription of the child store, browse to ‘Websites & Domains’ and click on the hyperlink of our domain, tshirts-us.com, which is located directly under ‘Add New Domain’. You now need to adjust the field under ‘Document root’ to read ‘symlink’ as shown in the below screenshot, before scrolling down and confirming your changes by clicking ‘OK’.

8

Note that we use the name ‘symlink’ instead of ‘httpdocs’.

We now need to create our symbolic link. This action is performed through the command line, and requires you are logged in as the root user. If you or your developers are unable to gain root access to your system then please contact us directly via our normal support channels.

The first step is to check for the existence of the new document root to confirm our configuration. To do this, issue the following command, substituting the name of your child store where applicable, and confirm that the directory ‘symlink’ exists.

To create our symbolic link, we first need to remove this directory using the following command. Please note that the ‘rm -rf’ command is potentially destructive, as it will remove any file on the file system (when the command is issued as the root user) without confirmation. You should ensure you are using an absolute path as shown in the example below. An absolute path is a path that contains the root directory and all other sub directories that contain a file or folder.

Now create the symbolic link, substituting tshirts-us.com (child store) and tshirts-uk.co.uk (parent store) where appropriate.

Now set the correct ownership on the symbolic link (substituting tshirts-us for the FTP user of the child domain).

If you run the following command you should now see something like the below screenshot in place of the previous symlink directory.

9

Step three: configure PHP for the child domain

We now need to adjust the PHP configuration for your child domain so that it is allowed to open files outside of its own webspace. This is done by adjusting the PHP open_basedir directive, and can be done directly within your Plesk Panel by first selecting the subscription of the child domain, browsing to ‘Websites & Domains’, ‘Show Advanced Operations’, ‘Website Scripting and Security’ and then ‘PHP Settings’.

Scroll down to ‘open_basedir’ and enter the following into ‘Enter custom value’, substituting the domain name of your parent and child Magento stores where applicable (you will need to uncheck ‘Default’ adjacent to the text box in order to do this). Once done, simply scroll further down the screen and click ‘OK’ to apply your change.

10

The above screenshot demonstrates our example.

Step four: configure the index.php file of your parent store

The final step of method two is to configure your Magento store to display the child store when triggered by an event, which will be when a user enters your domain name into the address bar. This can be done by editing the index.php (the ‘skeleton’ of a website) file associated with your Magento store for the parent domain. This can be done by using the text editor FTP, or within your Plesk Panel using the File Manager tool. We will make use of File Manager, which can be found within your subscription (for the parent domain) under ‘Websites & Domains’ and ‘File Manager’

Within your index.php file you should append an adaptation of the following directly under ‘umask(0);’

11

The above screenshot shows how we have adapted the above code for our scenario. As you can see ‘child-store.com’ is replaced by ‘tshirts-us.com’.

That’s it! All that remains is for you to configure your new child store to meet your own requirements. A good place to start is usually choosing a different root category (remember, everything above the root category won’t be displayed on the site) with products applicable to your new store.

NuBlue provide professional, high quality UK Web Hosting on Shared, VPS and Dedicated platforms.

Stefan

Author Stefan

More posts by Stefan

Talk with one of our hosting experts today


Or call 0800 033 7074