Setting up a Magento Site on Localhost
Recently, I wiped my main drive to do a completely fresh installation of OSX. I have a site that I work on for a client that uses Magento as the content management system (www.chouchoute.co.uk) and for development purposes, I set up a mirror of the site on my localhost. I use MAMP for local development, but WAMP (Windows) or LAMP (Linux) will do just as well. You need a working system to proceed…
This post is a much more comprehensive version of an earlier post on Setting up Magento on OSX.
Magento is a hugely-complex CMS, and for clients with a small product range, it may be a bit like buying a sportscar just to drive to the corner shops. It is however, extremely powerful and is the chosen CMS of many companies. Setting it up is a long way from WordPress’ Famous 5-Minute Install, a very long way and is not an easy thing for novices. That said, there are some incredibly helpful people who post a lot of sound advice in the Magento forums.
Before you get started, you may want to download and install the Magento Demo Store, just so you can see how everything is working, and also to use as a base template for building new skins for your site. Head over to the Magento site and download both the latest stable release (18.104.22.168 at the time of writing) and the sample store database (sample data). Move the downloaded folder to your htdocs or Sites folder and rename it to magento. You need to create a database (name it magento for simplicity) and import the sample data into it before installing the CMS itself. Using an FTP client, set the permissions on the downloaded magento site folder to 777. Now navigate in your browser to http://localhost/magento to start the installation by running the wizard. When you get to the Database connection panel, for the database name, make sure you call it magento, or whatever you named it earlier, adding any usernames and passwords you have set. Once the setup is complete, you can view the frontend store at http://localhost/magento or the backend at http://localhost/magento/admin where you can customise your site.
Once you have a working installation of Magento, you can proceed to setting up a local mirror of your live site. All the steps I explain here are based on your site running from the Sites folder. You may need to amend things to suit your environment.
- You will need FTP access to your remote site. Create a folder called mysite (change this for your own site name) in the Sites folder. Download the entire site from the root directory on the remote server to the mysite folder, and make sure the permissions on this are 777.
- Log in to the admin area on the remote site, and go to System > Tools > Backups to create a dump file of the live site. Download this and create a new database in phpMyAdmin on your localhost.
- Expand the .tar.bz2 file and import the sql dump into your database. If you have a lot of data in the file, you might find it easier to open the file as plain text and manually split the data across several files named dump1.sql, dump2.sql etc.
- I have found that to get a Magento site working on a local server, you need to use Virtual Hosts. Open your private/etc/hosts file and edit it to look something like this:##
# Host Database
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
# my websites
- You also need to edit the mysite > app > etc >local.xml file so it reflects your username/password and database name.
- Finally, go into phpMyAdmin and your site’s database, looking for the core_config_data table. There are a couple of fields you need to edit so the urls match your http://localhost/mysite/ but make sure you have the trailing slash on the site path.
These tell the database where to point your links between pages and content.
This should be all you need to view your local mirror site, just restart MAMP and enter the http://localhost/mysite address in your browser.
In some cases (if you are running PHP 5.3) you might see an error like this:
Fatal error: Method Varien_Object::__tostring() cannot take arguments in /magento/lib/Varien/Object.php
This post on the Learn Magento blog explains how to fix this.
As a parting tip, it is often useful when working on both live and local sites to use different favicons to identify which tab is which! You are welcome to download this one and put it in your root folder, and also in your skin > frontend >default > skinname folder:
Thanks – i followed this and i thought i had my local copy working – however when i click on nay other link i get a not found message (not even the Magento 404 page) I t only appears to be the home page thats working?
Have a look at your site in phpMyAdmin. Do a ‘%X%’ search on your magento config table and make sure your urls are all good. Also, make sure you are using virtual hosts.
Make sure that you hav mod_rewrite enabled in php.conf
Great tutorial but I just can’t get this site to work. Taking over from another developer and I’m just getting a blank screen at the frontend and backend.
If you are seeing the correct URL in the address bar, check that you have all of the tables in the database. There are a large number (well over 200). My default installation of Magento has 333 tables and I’ve found that importing a live site is tricky due to the large amount of data. Maybe try using your text editor to split the sql dump into smaller files and upload them separately. Someone probably has a script that can help automate this for you…
Hi. Very helpful article… I’m running my localhost:8888 on my Mac but when running Magento CMS and I want to do some changes the save page button does not do anything… do you have any suggestions? thanks
Hi Andrew, I wonder if it has anything to do with your localhost:8888 setting… You could either change the URL in the core config table, or better still, change your MySQL and HTML default ports. I use MAMP and to change it in there, open the MAMP control panel/dashboard widget and click the ports tab/button.Click the Set to default Apache and MySQL ports button to change the Apache port to 80 and the MySQL port to 3306. Restart your web server and try Magento again.
The only post i can find for what im look for. But still i cant get it working. Should the host file have the local ip address or my sites ip address…
Any help would appreciated…
This will be the local IP address as you are setting it up on your localhost on your Mac. If you add the remote IP you can view a domain that is being developed on a temporary URL, usually whilst transferring between domains.
Hi Stuart, thanks a lot for your post, I will try it later today. I have a preliminary question: what about certificates (and signed certificates in particular)? My shop needs signed certificates for HTTPS and because the payment gateway requires them.
If you are just testing, you can work around certificate problems by going to setting System > Configuration > Web > Use Secure URLs in Admin & set to “No”.
I transferred a live site to my local machine and all the pages in the application are being rendered properly. However, when I try to access some of the functionality, example registering a customer/sign-in a customer, etc., I am facing a Redirect Loop problem. I tried clearing the cache also but the problem is still there.
The message is a normal one given by the browser and it says “This webpage has a redirect loop” – “The webpage at http://local.xxxx.com/my-xxxx/ has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer.”
Can you please help me resolve this?
Sorry Naveen – I’m using Magento ver. 22.214.171.124 on local and haven’t updated. Not getting this issue and can’t advise.
Hi, when I open 127.0.0.1:8888/magento it will link to the live Site…
How can I change this problem?
Look at #4 on using virtual hosts.
Thanks! It’s really helped me.
NEVER do 777
Thanks Rokko, is this an issue on a local development server with a firewall too?
I am trying this with a version of Magento with multiple sites (2) on the installation – I keep getting a blank page – any ideas/thoughts would be amazing.
Sorry Atsawin, I only install single site instances.
I am trying to get an old version (1.4) site on wamp, because basically the person who created the new site did not export most of the data, but now the site is offline I just have a backup of all files.
I am wondering how I can get it to work with having to go through step #2, which is logging in to a site I cant.
If anyone here could help I would be most grateful.
i do same thing…all are set but skin image is not working…so help me!!!
Check that your path is correct and that you are working with the right store if you have more than one set up. (System > Configuration > Current configuration scope.)
but how to check image paths..give me detail answer..
Your theme files will be in skin > frontend > theme > default (or whatever you called the folder.) There you will have a css directory, images and js directories. In your css files, the paths to images will normally be something like this:
When you install Magento on Mamp, it’s looking for the sample database that’s specified on the install. I’ve imported sql file from my live site. I don’t understand how to magento to look at mu new folder not my sample date import? Do I dump that before make a new database and import?
2014 october last
stuart your gainful comment is precious for all
I have a running magento site, i copied the database and renamed it, made changes in the database config table, and local.xml too, but the default theme gets loaded whenever i run it, tried it a number of times. any help would be appreciated.
You could check the settings under web design tab in magento backend under system configuration to see what theme is set
In your post you said “Using an FTP client, set the permissions on the downloaded magento site folder to 777” is this setting the main folder only or after hitting get info and setting this also “apply to enclosed items”
And when I am ready to upload the local files, what permissions should I set the file and folders to. Is there now a security risk if it is left in “777” mode.
Where there specific permissions set by magento on the live site or permissions set for certain directories as “best practices”.
And what about the .httaccess file?
Set permissions on the main folder.
On a live site, yes, there will be a security risk with these permission settings. See here: Resetting Permissions for Magento.
You mentioned “Log in to the admin area on the remote site, and go to System > Tools > Backups to create a dump file of the live site. Download this and create a new database in phpMyAdmin on your localhost.”
There are three types of dumps, which one?
I am guessing database only.
Thank you for the answers you have given.