I'm using get_headers() to see if sites are up or not, and it's all fine, but when I try and check my local sites, I get a 'response timed out' error. The 'local' URLs are not on a 'real' domain, but are something like:
http://steve-emachine/WEBSITES_PHP/Sites/HOGSMILL/index.php
...where 'steve-emachine' is my machine name. Is there any way to use get_headers() on this kind of URL? The URLs work fine in a browser, so it's obviously just my ignorance of how HTTP works that is the problem.
Though for me, the url formats you mentioned is working, make sure that you have entry in hosts file of your operating system for that particular domain which you are using (steve-emachine in your case).
To use get_headers() on local site, you can do this:
Add virtual-host on your server, with some name like local.mysite.com
Make host entry in your operating system for that domain
127.0.0.1 local.mysite.com
Restart your server
use $url = http://local.mysite.com in get_headers(), it will work fine.
Make sure you use the full address with the http:// prefixed to it in your php code. Like this
http://local.mysite.com
the hosts file is in /etc/hosts on linux and looks something like
127.0.0.1 localhost
127.0.1.1 drew-ThinkPad-T410
127.0.0.1 local.mysite.com
Related
I'm trying to create a copy of an existing Magento website on my localhost for developing purposes.
I followed all the steps listed here: Copy ec2 files to local
I also created a fake domain for my localhost so that there’s a “.” in it as I read somewhere this is required by magento. So now my localhost fake URL is something like: www.mysite.local
I have XAMPP installed on OS X 10.9.1 and I placed the magento filesystem as follows:
/Applications/XAMPP/xamppfiles/htdocs/magento/
In the database I added the local URL as follows:
update core_config_data
set value = ‘http://www.mysite.local/’
where config_id = 6;
and on local.xml I entered the following parameters:
<host><![CDATA[localhost]]></host>
<username><![CDATA[myusername]]></username>
<password><![CDATA[mypassword]]></password>
<dbname><![CDATA[mydatabase]]></dbname>
where localhost is just localhost, myusername is the username for the db I restored on my local XAMPP server, mypassword is the password for that same db, mydatabase is the name of the same db.
Still, when I browse to www.mysite.local/magento/ or www.mysite.local I don’t see anything appear.
What am I doing wrong?
Thank you so much!
If you're using a local server, here's some basic trouble shooting to help you debug:
Firstly, is the local server active? Can you visit http://localhost without it displaying server not found? If you can't, your local server is most not running. Try firing up xampp and launching Apache.
Secondly, it seems you're trying to create a virtual host for your local server. That's great! Virtual hosts allow you to create individual URLs for projects on the same server. E.g. http://myproject.dev.
However, you first need to make sure that the server understands what you're doing.
You will need to create a virtual host in your server if you haven't already.
I see you're using xampp. What you need to do is navigate to your xampp install, and edit your apache/conf/extra/httpd-vhosts.conf file, which is the file xampp recommends you use solely for virtual hosts.
Reading: Setting Up Virtual Hosts for XAMPP
For example, in Apache, a hosts config file may look like this:
# Base
<VirtualHost *:80>
DocumentRoot "X:/"
ServerName localhost
</VirtualHost>
# Project - Some Project of Mine
<VirtualHost *:80>
DocumentRoot "X:/projects/myproject/public"
ServerName myproject.dev
ErrorLog X:/projects/myproject/logs/apache.error.log
CustomLog X:/projects/myproject/logs/apache.access.log common
php_value error_log X:/projects/myproject/logs/php.error.log
</VirtualHost>
(navigating to myproject.dev displays the files in my X:/projects/myproject/public directory)
This answer is not to explain virtual hosts to you however. There are plenty of amazing resources online to help you get started with setting up your own.
Don't forget to restart your server when you add a virtual host!
If this is already set up, is your computer's hosts file set up to point to your server?
Your hosts file on your computer is used to tell it to do certain actions when you enter a matching url in your browser.
Reading: The Hosts File and what it can do for you
Reading: How to Edit Your Hosts File
For example, using the apache conf file settings above, my hosts file must also include:
# My project - Localhost
127.0.0.1 myproject.dev
It tells my computer to send the request to my local server (at localhost) when I use the URL myproject.dev. The local server then picks up the request, sees that you're accessing myproject.dev and checks if it has any virtual hosts matching that name. Well, whaddya know, it does! It then looks at the DocumentRoot setting for the location of the server files, and continues the process. Think of your hosts file as a local DNS of sorts.
If you've just added the site to your hosts file, it may take a few minutes to start resolving correctly. Wait a little, clear your browser cache and try again.
Finally, if these steps are done, and you're receiving nothing, it may be a server configuration problem, or a .htaccess issue.
If you're running on windows, you can check your event log for apache server errors. If you have set up logging on the virtual host, you can check those files to see if it's picking up your requests, and what it's doing with them if it is.
Most issues after that point will at least yield a visible error in your browser (or a blank page).
I hope this helps!
Also checking the magento error logs could tell you what the issue is, assuming it's actually hitting magento at all at this point.
As Sean mentioned above, one of the most common problems I've seen when copying a magento site is accidentally omitting the .htaccess file - make sure it's present in your site root.
If you tested your site before making the change to core_config_data, then you can also try deleting everything in var/cache and var/session. Also make sure that the web user has write permissions on var.
Regards
Hans
I want to be able to have one way of creating dynamic URL's that works in development and production. Right now I'm building the URL's like this:
header("Location: http://".$_SERVER["HTTP_HOST"]."/contact.php?failed");
but the problem with this is that I currently run the site like this off my WAMP server:
http://localhost/vdname/contact.php
and so that line of code doesn't generate the right URL in development - it builds:
http://localhost/contact.php?failed
instead and thus I get an expected 404. How can I build the URL's properly so that they work in both development and production?
EDIT
Per a number of suggestions, it would better to leverage VirtualHost entries in the httpd.conf file for this so I could use a normal domain name locally. So, I'm trying to get that to work and it's not working like I want, consider this code from the conf:
#Listen 12.34.56.78:80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /www/example
ServerName local.example.com
</VirtualHost>
and the associated hosts file configuration:
127.0.0.1 local.example.com
but when I navigate to http://local.example.com/contact.php I get a 403 Forbidden and when I run an nslookup local.example.com I don't get 127.0.0.1 either.
For my stuff I use $_SERVER['SERVER_NAME'] instead of $_SERVER['HTTP_HOST']. Because the HTTP_HOST is pulled from the HTTP request header and it is client set. If someone hits your site from www.yoursite.com and yoursite.com you might actually have two different results for HTTP_HOST in the same session. This can play havoc with cookies and redirects, not to mention with your site in terms of SEO and traffic patterns.
To stay on the same site, rather than populating the header() location command with an offsite URL (containing HTTP), you can use this instead:
header("Location: /contact.php?failed");
Also in your form you can use this:
<form action="/gdform.php" method="post" style="float: left;">
By using that style of links the browser will stay on the same site without performing a look-up (DNS) and it will stay in the same SubDNS.
You would need to make sure that $_SERVER['SERVER_NAME'] was properly configured in Apache, assuming that's what you're running.
I have a website that works fine when deployed on a remote development server. However, when I move it to my local machine, all the images paths' are now not pointed to the right directory.
Where as <img src="/images/breadicon.png" /> used to work, I now get a 404 file not found.
When I update that to <img src="./images/breadicon.png" />, the image is found, but I don't want to have to revert back all my links when I re-deploy this site - and of course I don't want to have to work from the remote server.
The issue is, without the ., the path is perceived as http://localhost/images/breadicon.png instead of http://localhost/sitename/images/breadicon.php
What can I do to resolve all the links and have my links without ruining the code for redeployment?
Your best option is probably to set up a web host on your local machine.
For example, if your live/remote site was http://www.example.com/, you could set up a local web host as http://example/.
I'm assuming you're on Windows and using Apache. You'd need to edit your hosts file (using notepad, running as administrator, usually found here: C:\Windows\System32\drivers\etc) to contain:
127.0.0.1 example
Then create an Apache host config file, for example:
<VirtualHost *:80>
ServerName example
DocumentRoot C:/Path/To/Site/example
</VirtualHost>
Then restart Apache and go to http://example/. Assuming you follow a standard convention for links etc, this should do the trick.
Configure your webserver such that the site can be accessed under http://localhost/ instead of http://localhost/sitename.
If that name is already used for a different purpose, create a virtual host named e.g. sitename in the webserver and edit your hosts file so that sitename points to 127.0.0.1.
I apologize for the bad formatting.
i am stuck at a point regarding the domain name or webservice.
when we call the webservice on the local server it is working but when we call the service from some remote location it is giving "404 not found error".
Thanks in advance
I agree with Night2, this sounds like it could only be a VirtualHost situation.
In short, if you can ping the server with a domain name from another machine then dns-wise you're fine as the name resolves correctly. Getting a 404 means you are hitting your web server - apache or whatever you're using as that's an HTTP error, it doesn't sound like a port problem. If it works locally and you're using the same name from another machine it's not a ServerAlias problem.
The syntax for setting up the VirtualHost (in apache) you can get from here.
In short what that means it that you have something that looks like this:
<VirtualHost 10.1.2.3:80>
The IP means that's what IP and port that VirtualHost is listening on. If you have only an internal IP there then you'll only be able to hit it interally and you'd have to use *:80 or specify IP as is applicable so apache will track with which VirtualHost to route the request to.
I want a way to create subdomain using htaccess or any thing to do that.
I can create subdomain with change some codes in httpd.conf, but the problem I have only a host now and I can't edit httpd.conf!
You can't. The DNS name server must resolve the subdomain to the correct IP, and Apache (or whatever HTTP server you're using) must set the correct DocumentRoot for the subdomain.
Unless those two are configured properly, the request won't get to you and the htaccess would have no effect.