This is a short but weird one.
I had a problem where the site worked perfectly up to the checkout button. Which would do nothing. Nothing at all.
After pulling my hair out, I realised the cause.
In the database, in table "core_config_data", the secure website url had a single carriage return after it.
Would have saved me hours of work if someone had posted that online. So here I am, posting it.
Enjoy!
Wednesday, 20 March 2013
Using magento on a dev or test server, with proper domain names instead of IP addresses. Virtual Host setup guide.
There are times when you need to run magento on a local dev server or WAMP installation or just anywhere, and you don't want an IP address, but instead you want to use a proper domain name.
For example I came across a particularly ridiculous problem with a module's licence; the module would only work on the root domain, and any subdomains of that. For example it worked on www.rubbishmodule.com and shop.rubbishmodule.com but if you moved your site to a dev server, eg 192.168.1.100/rubbishmodule/ it no longer worked.
Something had to be done. And it was easier than I thought. The process is:
1) Set up apache to use "Name based virtual hosting"
2) Edit the necessary files on magento
3) Setup hosts file on pc, or a trick, the router
Apache is a cleverpants. You can use two types of routing to "fake" a web domain on a dev server or any other server running apache. I won't go into it, because you're likely to only ever need Name Based variety.
So - easy peasy. Open up your httpd.conf. On CentOS, it's probably in /etc/httpd/conf/httpd.conf. Remember you need to be superuser or you'll be frustrated when you can't save the file ;)
Scroll to the bottom.
Find and uncomment:
# Use name-based virtual hosting.
NameVirtualHost *.80
Add below somewhere:
<VirtualHost *.80>
DocumentRoot /var/www/html/ <- this is the absolute path to your dev website root
ServerName test.rubbishmodule.com <- this is the web domain you want to "fake"
ErrorLog /var/www/rubbishmodule_error_log <- this can be anywhere
CustomLog /var/www/rubbismodule_access_log <- likewise.
</VirtualHost>
That's that. You can add as many entries as you like, thats how name based works, apache will just route to the right DocumentRoot for the ServerName you've given. Genius.
Oh. You need to restart apache too. Usually
service httpd restart
will do the trick. Google it if you're stuck here.
But it won't work until you do steps 2 and 3...
You need to go into phpmyadmin and browse the core_config_data table. Find the entry for web/unsecure/base_url
It's a big table, but its there.
Change the data to http://test.rubbishmodule.com/
DONT forget the trailing forward slash. If you do, all manner of naughty breaks loose
Now clear /var/cache and /var/session folders in your magento root
Now you need to tell your PC where to find this server. This is by editing your hosts file. Plenty on this if you google it, but the basics are in Windows:
open c:\windows\system32\drivers\etc\hosts
Go to the bottom
Add in
192.168.1.100 test.rubbishmodule.com <- ip of your dev server, your fake domain
Bingo. All works.
Now, as an extra, if you have a dd-wrt router, you can do this on the router, so every PC can see the test site!
For example I came across a particularly ridiculous problem with a module's licence; the module would only work on the root domain, and any subdomains of that. For example it worked on www.rubbishmodule.com and shop.rubbishmodule.com but if you moved your site to a dev server, eg 192.168.1.100/rubbishmodule/ it no longer worked.
Something had to be done. And it was easier than I thought. The process is:
1) Set up apache to use "Name based virtual hosting"
2) Edit the necessary files on magento
3) Setup hosts file on pc, or a trick, the router
1. Apache
Apache is a cleverpants. You can use two types of routing to "fake" a web domain on a dev server or any other server running apache. I won't go into it, because you're likely to only ever need Name Based variety.
So - easy peasy. Open up your httpd.conf. On CentOS, it's probably in /etc/httpd/conf/httpd.conf. Remember you need to be superuser or you'll be frustrated when you can't save the file ;)
Scroll to the bottom.
Find and uncomment:
# Use name-based virtual hosting.
NameVirtualHost *.80
Add below somewhere:
<VirtualHost *.80>
DocumentRoot /var/www/html/ <- this is the absolute path to your dev website root
ServerName test.rubbishmodule.com <- this is the web domain you want to "fake"
ErrorLog /var/www/rubbishmodule_error_log <- this can be anywhere
CustomLog /var/www/rubbismodule_access_log <- likewise.
</VirtualHost>
That's that. You can add as many entries as you like, thats how name based works, apache will just route to the right DocumentRoot for the ServerName you've given. Genius.
Oh. You need to restart apache too. Usually
service httpd restart
will do the trick. Google it if you're stuck here.
But it won't work until you do steps 2 and 3...
2. Magento
You need to go into phpmyadmin and browse the core_config_data table. Find the entry for web/unsecure/base_url
It's a big table, but its there.
Change the data to http://test.rubbishmodule.com/
DONT forget the trailing forward slash. If you do, all manner of naughty breaks loose
Now clear /var/cache and /var/session folders in your magento root
3. Hosts
Now you need to tell your PC where to find this server. This is by editing your hosts file. Plenty on this if you google it, but the basics are in Windows:
open c:\windows\system32\drivers\etc\hosts
Go to the bottom
Add in
192.168.1.100 test.rubbishmodule.com <- ip of your dev server, your fake domain
Bingo. All works.
Now, as an extra, if you have a dd-wrt router, you can do this on the router, so every PC can see the test site!
Go to
Services -> Services -> DNSMasq: http://192.168.1.1/Services.asp
address=/test.rubbishmodule.com/192.168.1.100
Subscribe to:
Comments (Atom)