WAMP - Remove localhost from project URL
You can also look at this answer specially if you are now using WAMPServer 3 or greater, for a simple clikc and go way to create Virtual hosts.
Actually this change was intended by the WAMPServer developers and for a good reason.
There is a problem using the localhost/project1
url and the default WAMPServer DocumentRoot in that it causes problems for some frameworks and WordPress type environments, as well as your own code if you are using code which depends on knowing anything about the server environment.
The correct solution is to create Virtual Hosts for all your projects even those that you store in the \wamp\www\project1
style folders.
When doing that the DocumentRoot is \wamp\www
and that is what causes these problems.
These tools expect the DocumentRoot to be the root of the site i.e. \wamp\www\project1
so that when they use PHP variables like
$_SERVER['HTTP_HOST']
$_SERVER['SERVER_NAME']
$_SERVER['DOCUMENT_ROOT']
they get the correct answer i.e. the answer they would get on a real live server hosting just that site.
So using the localhost\project1
style url would mean these variables would return
$_SERVER['HTTP_HOST'] = localhost
$_SERVER['SERVER_NAME'] = localhost
$_SERVER['DOCUMENT_ROOT'] = C:/wamp/www
When they should return
$_SERVER['HTTP_HOST'] = project1
$_SERVER['SERVER_NAME'] = project1
$_SERVER['DOCUMENT_ROOT'] = C:/wamp/www/project1
So what you should do to make the My Projects
menu work and reduce your pain in copying sites to live servers is:
Create an entry in the HOSTS file for each project like so and remember to create one for access via IPV4(127.0.0.1) and one for access via IPV6 (::1):-
127.0.0.1 localhost
127.0.0.1 project1
::1 localhost
::1 project1
Remember to refresh the Windows DNS Cache after any change to this file like so :-
Start a command window using Run as Administrator
and run :-
net stop Dnscache
net start Dnscache
Now you must create a Virtual Host definition, so edit the \wamp\bin\apache\apache2.4.9\conf\extra\httpd-vhost.conf
file ( apache versions may differ )
Delete the default stuff in there the first time you do this. And then create your Virtual Host definitions like so :-
#
# Use name-based virtual hosting.
# This next line is not required if you are using Apache 2.4.x and should be deleted
NameVirtualHost *:80
## should be first so the wamp menu page loads and is the default site
## should also never be changed from only allowing access from the local machine
## for a bit of extra security from casual ip address probing
<VirtualHost *:80>
DocumentRoot "C:/wamp/www"
ServerName localhost
ServerAlias localhost
<Directory "C:/wamp/www">
AllowOverride All
<IfDefine APACHE24>
Require local
</IfDefine>
<IfDefine !APACHE24>
Order Deny,Allow
Deny from all
Allow from 127.0.0.1 localhost ::1
</IfDefine>
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/wamp/www/project1"
ServerName project1
ServerAlias project1
<Directory "C:/wamp/www/project1">
AllowOverride All
<IfDefine APACHE24>
Require local
</IfDefine>
<IfDefine !APACHE24>
Order Deny,Allow
Deny from all
Allow from 127.0.0.1 localhost ::1
</IfDefine>
</Directory>
</VirtualHost>
Now you need one more change, you must uncomment the line in httpd.conf
that includes the above file we have just changed. So edit the httpd.conf
file, use the wampmanager menus to do this as it ensures you edit the correct file.
Find this line #Include conf/extra/httpd-vhosts.conf
and remove the comment #
symbol from the beginning of the line like so :-
Include conf/extra/httpd-vhosts.conf
Now of course you will need to restart Apache so that it picks up your configuration changes.
If Apache does not restart, you probably made a mistake in the config, to find out what is wrong try this.
Open a command window and CD
into the \wamp\bin\apache\apache2.4.9\bin
folder.
Then run this :-
httpd -t
If the error is in httpd.conf
or the httpd-vhost.conf
files it will tell you the error and also give you the line number to make finding the error very easy.
WAMP: Missing http://localhost/ in urls , wrong wamp projects links
After thorough research, I found out the solution which worked for me as well..
open wamp/www/index.php.
Change this line:
$suppress_localhost = true;
To :
$suppress_localhost = false;
How to change the URL from “localhost” to something else, on a local system using Flask?
You can perform this by modifying c:\windows\system32\drivers\etc\hosts
Simply replace localhost with ap-mispro it should look like :-
127.0.0.1 ap-mispro
Related Topics
Pdo Were Rows Affected During Execute Statement
Simple PHP Echo Code Not Working
Why Do I Get "Resource Id #4" When I Apply Print_R() to an Array in PHP
Programmatically Determine Whether to Describe an Object with "A" or "An"
How to Search Array for Multiple Values in PHP
How Does SQL-Injection Work and How to Protect Against It
Why Is My Number Value Changing Using Number_Format()
What Means Call to a Member Function on Boolean and How to Fix
Convert PHP Array String into an Array
Using Return in Ternary Operator
Multiple Http Get Parameters with the Same Identifier
PHP Script to Execute at Certain Times
Forbidden Error When Submitting Simple PHP Form
PHP Fatal Error: Call to a Member Function Format() on Boolean
Sending/Displaying a Base64 Encoded Image