Can you run PHP webpages from any location? [duplicate] - php

I am installing the Wamp Server on another computer to run a mid-sized database and UI. I have been successful in blocking IIS and routing the server to Localhost:8080. But whenever I try to access on of my projects from the localhost homepage, in the www file; I get redirected to a Page not found error.
When I hover above the links the directory always comes up "http:// ProjectFolderNameHere /". when it's supposed to be "http:// LocalHost:8080 / ProjectFolderNameHere /". What can I do to get the links working properly?
My Machine runs on Windows 7 Home Edition 64-bits, and I already have Microsoft's IIS disabled.

How to create a Virtual Host in WampServer
WAMPServer 3 has made this process much easier!
You can do almost everything from a utility provided as part of WAMPServer.
Create a folder inside to contain your project.site. This can be under the C:\wamp\www\ directory or in a completely seperate folder like C:\websites.
Create a folder inside the location you have chosen EG C:\websites\project1\www or under the c:\wamp\www\project1\www
Now open localhost wampmanager->localhost and click on the link Add a Virtual Host under the TOOLS section on the homepage.
You will see a page like this:
Fill in the fields as specified by the instructions above each field
The Virtual Host config will have been created for you.
Now you must restart the DNS Cache. You can do this from the wampmanager menus like this right click wampmanager->Tools->Restart DNS. The DNS Cache will be restarted and then Apache will also be stopped and restarted. When the wampmanager icon goes green again all is completed.
Now you must create a simple index.php file or install your site into the folder you created above.
Assuming your VH was called project.dev You should see that name under the Your Virtual Hosts Section of the WAMPServer homepage.
You can launch the site from this menu, or just use the new Domain Name in the address bar EG project1.dev and the site shoudl launch.
Old WAMPServer 2.5 mechanism, or if you want to do it all manually
There has been a change of concept in WampServer 2.5 and above and there is a good reason for this change!
In WampServer it is now STRONGLY encouraged to create a Virtual Host for each of your projects, even if you hold them in a \wamp\www\subfolder structure.
Virtual Hosts Documentation
Virtual Host Examples
The WampServer home page ( \wamp\www\index.php ) now expects you to have created a Virtual Host for all your projects and will therefore work properly only if you do so.
History
In order to make life easier for beginners using WampServer to learn PHP Apache and MySQL it was suggested that you create subfolders under the \wamp\www\ folder.
wamp
|-- www
|-- Chapter1
|-- Chapter2
|-- etc
These subfolders would then show as links in the WampServer Homepage under a menu called 'Your Projects' and these links would contain a link to localhost/subfoldername.
Acceptable only for simple tutorials
This made life easy for the complete beginner, and was perfectly acceptable for example for those following tutorials to learn PHP coding.
However it was never intended for use when developing a real web site that you would later want to copy to your live hosted server.
In fact if you did use this mechanism it often caused problems as the live sites configuration would not match your development configuration.
The Problem for real website development.
The reason for this is of course that the default DocumentRoot setting for wamp is
DocumentRoot "c:/wamp/www/"
regardless of what your subfolder was called.
This ment that often used PHP code that queried the structure or your site received different information when running on your development WampServer to what it would receive when running on a live hosted server, where the DocumentRoot configuration points to the folder at the top of the website file hierarchy.
This kind of code exists in many frameworks and CMS's for example WordPress and Joomla etc.
For Example
Lets say we have a project called project1 held in wamp\www\project1 and run incorrectly as localhost/project1/index.php
This is what would be reported by some of the PHP command in question:
$_SERVER['HTTP_HOST'] = localhost
$_SERVER['SERVER_NAME'] = localhost
$_SERVER['DOCUMENT_ROOT'] = c:/wamp/www
Now if we had correctly defined that site using a Virtual Host definition and ran it as http://project1 the results on the WAMPServer devlopment site will match those received when on a live hosted environment.
$_SERVER['HTTP_HOST'] = project1
$_SERVER['SERVER_NAME'] = project1
$_SERVER['DOCUMENT_ROOT'] = c:/wamp/www/project1
Now this difference may seem trivial at first but if you were to use a framework like WordPress or one of the CMS's like Joomla for example, this can and does cause problems when you move your site to a live server.
How to create a Virtual Host in WampServer
Actually this should work basically the same for any wndows Apache server, with differences only in where you may find the Apache config files.
There are 3 steps to create your first Virtual Host in Apache, and only 2 if you already have one defined.
Create the Virtual Host definition(s)
Add your new domain name to the HOSTS file.
Uncomment the line in httpd.conf that includes the Virtual Hosts definition file.
Step 1, Create the Virtual Host definition(s)
Edit the file called httpd-hosts.conf which for WampServer lives in
\wamp\bin\apache\apache2.4.9\conf\extra\httpd-vhosts.conf
(Apache version numbers may differ, engage brain before continuing)
If this is the first time you edit this file, remove the default example code, it is of no use.
I am assuming we want to create a definition for a site called project1 that lives in
\wamp\www\project1
Very important, first we must make sure that localhost still works so that is the first VHOST definition we will put in this file.
<VirtualHost *:80>
DocumentRoot "c:/wamp/www"
ServerName localhost
ServerAlias localhost
<Directory "c:/wamp/www">
Options Indexes FollowSymLinks
AllowOverride All
Require local
</Directory>
</VirtualHost>
Now we define our project: and this of course you do for each of your projects as you start a new one.
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/project1"
ServerName project1
<Directory "c:/wamp/www/project1">
Options Indexes FollowSymLinks
AllowOverride All
Require local
</Directory>
</VirtualHost>
NOTE: That each Virtual Host as its own DocumentRoot defined. There are also many other parameters you can add to a Virtual Hosts definition, check the Apache documentation.
Small aside
The way virtual hosts work in Apache: The first definition in this file will also be the default site, so should the domain name used in the browser not match any actually defined virtually hosted domain, making localhost the first domain in the file will therefore make it the site that is loaded if a hack attempt just uses your IP Address.
So if we ensure that the Apache security for this domain is ALWAYS SET TO
Require local
any casual hack from an external address will receive an error and not get into your PC, but should you misspell a domain you will be shown the WampServer homepage, because you are on the same PC as WampServer and therfore local.
Step 2:
Add your new domain name to the HOSTS file.
Now we need to add the domain name that we have used in the Virtual Host definition to the HOSTS file so that windows knows where to find it. This is similiar to creating a DNS A record, but it is only visible in this case on this specific PC.
Edit C:\windows\system32\drivers\etc\hosts
The file has no extension and should remain that way. Watch out for notepad, as it may try and add a .txt extension if you have no better editor.
I suggest you download Notepad++, its free and a very good editor.
Also this is a protected file so you must edit it with administrator privileges, so launch you editor using the Run as Administrator menu option.
The hosts file should look like this when you have completed these edits
127.0.0.1 localhost
127.0.0.1 project1
::1 localhost
::1 project1
Note that you should have definitions in here for the IPV4 loopback address 127.0.0.1 and also the IPV6 loopback address ::1 as Apache is now IPV6 aware and the browser will use either IPV4 or IPV6 or both. I have no idea how it decides which to use, but it can use either if you have the IPV6 stack turned on, and most window OS's do as of XP SP3.
Now we must tell windows to refresh its domain name cache, so launch a command window again using the Run as Administrator menu option again, and do the following.
net stop dnscache
net start dnscache
This forces windows to clear its domain name cache and reload it, in reloading it will re-read the HOSTS file so now it knows about the domain project1.
Step 3: Uncomment the line in httpd.conf that includes the Virtual Hosts definition file.
Edit your httpd.conf, use the wampmanager.exe menus to make sure you edit the correct file.
Find this line in httpd.conf
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf
And just remove the # to uncomment that line.
To activate this change in you running Apache we must now stop and restart the Apache service.
wampmanager.exe -> Apache -> Service -> Restart Service
Now if the WAMP icon in the system tray does not go GREEN again, it means you have probably done something wrong in the \wamp\bin\apache\apache2.4.9\conf\extra\httpd-hosts.conf file.
If so here is a useful mechanism to find out what is wrong. It uses a feature of the Apache exe (httpd.exe) to check its config files and report errors by filename and line numbers.
Launch a command window.
cd \wamp\bin\apache\apache2.4.9\bin
httpd -t
So fix the errors and retest again until you get the output
Syntax OK
Now there is one more thing.
There are actually 2 new menu items on the wampmanager menu system. One called 'My Projects' which is turned on by default.
And a second one, called 'My Virtual Hosts', which is not activated by default.
'My Projects' will list any sub directory of the \wamp\www directory and provide a link to launch the site in that sub directory.
As I said earlier, it launches 'project1` and not 'localhost/project1' so to make the link work we must create a Virtual Host definition to make this link actually launch that site in your browser, without the Virtual Host definition it's likely to launch a web search for the site name as a keyword or just return a site not found condition.
The 'My Virtual Hosts' menu item is a little different. It searches the file that is used to define Virtual Hosts ( we will get to that in a minute ) and creates menu links for each ServerName parameter it finds and creates a menu item for each one.
This may seem a little confusing as once we create a Virtual Host definition for the sub directories of the \wamp\www folder some items will appear on both of the 'My Projects' menu and the 'My Virtual Hosts' menu's.
How do I turn this other 'My Virtual Hosts' menu on?
Make a backup of the \wamp\wampmanager.tpl file, just in case you make a mistake, its a very important file.
Edit the \wamp\wampmanager.tpl
Find this parameter ;WAMPPROJECTSUBMENU, its in the '[Menu.Left]' section.
Add this new parameter ;WAMPVHOSTSUBMENU either before or after the ;WAMPPROJECTSUBMENU parameter.
Save the file.
Now right click the wampmanager icon, and select 'Refresh'. If this does not add the menu, 'exit' and restart wampmanager.
Big Note
The new menu will only appear if you already have some Virtual Hosts defined! Otherwise you will see no difference until you define a VHOST.
Now if you take this to its logical extension
You can now move your web site code completely outside the \wamp\ folder structure simply by changing the DocumentRoot parameter in the VHOST definition. So for example you could do this:
Create a folder on the wamp disk or any other disk ( beware of network drive, they are a bit more complicated)
D:
MD websites
CD websites
MD example.com
CD example.com
MD www
You now copy your site code to, or start creating it in the \websites\example.com\www folder and define your VHOST like this:
<VirtualHost *:80>
DocumentRoot "d:/websites/example.com/www"
ServerName example.dev
ServerAlias www.example.dev
<Directory "d:/websites/example.com/www">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
php_flag display_errors Off
php_flag log_errors On
php_value max_upload_size 40M
php_value max_execution_time 60
php_value error_log "d:/wamp/logs/example_com_phperror.log"
</VirtualHost>
Then add this new development domain to the HOSTS file:
127.0.0.1 localhost
::1 localhost
127.0.0.1 project1
::1 project1
127.0.0.1 example.dev
::1 example.dev
NOTE: It is not a good idea to use a ServerName or ServerAlias that is the same as your live domain name, as if we had used example.com as the ServerName it would mean we could no longer get to the real live site from this PC as it would direct example.com to 127.0.0.1 i.e. this PC and not out onto the internet.
ALSO:
See that I have allowed this site to be accessed from the internet from within the VHOST definitions, this change will apply to only this site and no other. Very useful for allowing a client to view your changes for an hour or so without having to copy them to the live server.
This does mean that we have to edit this file manually to turn this access on and off rather than use the Put Online/Offline menu item on wampmanager.
Also I have added some modifications to the PHP config, again that will only apply to this one site.
Very useful when maintaining a site with specific requirement unlike all the other sites you maintain.
I guess we can assume from the parameters used that it has a long running page in it somewhere and it is very badly written and will not run with errors being displayed on the browser without making a horrible mess of the page. Believe me sites like this exist and people still want them maintained badly. But this mean we only have to change these parameters for this specific site and not globally to all Virtual sites running on WampServer.

I believe this is the best solution:
Open index.php in www folder and set
change line
30:$suppress_localhost = true;
to
$suppress_localhost = false;
This will ensure the project is prefixed with your local host IP/name

Open index.php in www folder and set
$suppress_localhost = false;
This will prepend http://localhost/ to your project links

In order to access project from the homepage you need to create a Virtual Host first.
Most easiest way to do this is to use Wamp's Add a Virtual Host Utility.
Just follow these steps:
Create a folder inside "C:\wamp\www\" directory and give it a name that you want to give to your site for eg. 'mysite'. So the path would be "C:\wamp\www\mysite".
Now open localhost's homepage in your browser, under Tools menu click on Add a Virtual Host link.
Enter the name of the virtual host, that name must be the name of the folder we created inside www directory i.e. 'mysite'.
Enter absolute path of the virtual host i.e. "C:\wamp\www\mysite\" without quotes and click the button below saying 'Start the creation of the VirtualHost'.
Virtual Host created, now you just need to 'Restart DNS'. To do this right click the wamp server's tray menu icon, click on Tools > Restart DNS and let the tray menu icon become green again.
All set! Now just create 'index.php' page inside "C:\wamp\www\mysite\" directory. Add some code in 'index.php' file, like
<?php
echo "<h1>Hello World</h1>";
?>
Now you can access the projects from the localhost's homepage. Just click the project link and you'll see 'Hello World' printed on your screen.

You can follow all steps by #RiggsFolly thats is really good answer, If you do not want to create virtual host and want to use like previous localhost/example/ or something like that you can use answer by #Arunu
But if you still face problem please use this method,
Locate your wamp folder (Eg. c:/Wamp/) where you have installed
Goto Wamp/www/
Open index.php file
find this code $projectContents .= '<li>'.$file.'</li>';
modify it add localhost after http:// $projectContents .= '<li>'.$file.'</li>';
Restart wamp server
open localhost see the updated links
Hope you got your url like previous version of wamp server.

How To Fix The Broken Icon Links (blank.gif, text.gif, etc.)
Unfortunately as previously mentioned, simply adding a virtual host to your project doesn't fix the broken icon links.
The Problem:
WAMP/Apache does not change the directory reference for the icons to your respective installation directory. It is statically set to "c:/Apache24/icons" and 99.9% of users Apache installation does not reside here. Especially with WAMP.
The Fix:
Find your Apache icons directory! Typically it will be located here: "c:/wamp/bin/apache/apache2.4.9/icons". However your mileage may vary depending on your installation and if your Apache version is different, then your path will be different as well.\
Open up httpd-autoindex.conf in your favorite editor. This file can usually be found here: "C:\wamp\bin\apache\apache2.4.9\conf\extra\httpd-autoindex.conf". Again, if your Apache version is different, then so will this path.
Find this definition (usually located near the top of the file):
Alias /icons/ "c:/Apache24/icons/"
<Directory "c:/Apache24/icons">
Options Indexes MultiViews
AllowOverride None
Require all granted
</Directory>
Replace the "c:/Apache24/icons/" directories with your own. IMPORTANT You MUST have a trailing forward slash in the first directory reference. The second directory reference must have no trailing slash. Your results should look similar to this. Again, your directory may differ:
Alias /icons/ "c:/wamp/bin/apache/apache2.4.9/icons/"
<Directory "c:/wamp/bin/apache/apache2.4.9/icons">
Options Indexes MultiViews
AllowOverride None
Require all granted
</Directory>
Restart your Apache server and enjoy your cool icons!

$suppress_localhost = false;
This did the trick for me.

This works on Wamp 3+.
Go to wamp folder (wamp/ or wamp64/)
Open wampmanager.conf
Find urlAddLocalhost param and set it on: urlAddLocalhost = "on"
There should not be the need to tweak the index.php in www folder.

Re: Wampserver LocalHost links not working correctly
This is as of June 2014 with Wampserver2.5 (maybe they'll fix this in later builds).
Note: to use LocalHost:8080 instead of LocalHost just make the appropriate changes in the edits mentioned below.
There are 2 aspects of this issue -
The first is to be able to access items under "Your Projects" from the Wamp localhost homepage.
The second is to be able to correctly access items listed in the Wampserver Icon Taskbar's "My Projects" list.
To fix the first (to be able to access items under "Your Projects" from the Wamp localhost homepage) you will need to do the following...
There are 2 edits that you must make in the index.php file located in your wamp\www folder (usually C:\wamp\www)
1) on Line 30 change
$suppress_localhost = true;
to
$suppress_localhost = false;
2) on line 338 change
$projectContents .= '<li>'.$file.'</li>';
to
$projectContents .= '<li>'.$file.'</li>';
After you've made the above edits - if the Wampserver is running just refresh the local host page and the changes become immediately effective.
To fix the 2nd item (the Wampserver Icon Taskbar's "My Projects" list):
You need to edit C:\wamp\scripts\refresh.php
Locate line 651 and change the section of the line that reads
Parameters: "http://'.$projectContents[$i].'/"; Glyph: 5
to
Parameters: "http://localhost//'.$projectContents[$i].'/"; Glyph: 5
After you make these 2nd set of changes you may have to force Wampserver to refresh the "My Projects" list by toggling the Put Online/Offline option at the bottom of the Wamp Icon Tray App.

check wamp server icon is green or not if it is green then it is working if not then you have to follow these steps to do
a. all the programs should be closed before running the wamp because most of the cases some softwares like skype takes the same port (80) which is using by wamp.
b. you can change the port of skype : Tool-s->oprions->advanced->connection untick use port 80
restart the wamp it will work.
SECOND case
when you click on the project in loalhost it does not show the localhost infront of the project name and because of that it looks like wamp is not working then you have to one thing on only
. go to wamp index.php file and change $suppress_localhost = false; from $suppress_localhost = true; or try vice versa it will work

Navigate to your www directory (if you are using wamp server) htdocs (if on XAMPP). Open your admin.php and search on project contents/ or just go directly to line number 339 and change the link, inserting 'local host to the link .
That should work ,,

I find it's a lot easier (than accepted answer) to create a local subdomain by project and tell Apache to serve multiple sites by name.
For example, let's say you created a project under c:/wamp64/www/sites/mysite, to be able to access it at http://mysite.localhost you simply need to do the following:
1. Tell your machine to answer to different names
Add 127.0.0.1 mysite.localhost to C:\windows\system32\drivers\etc\hosts
2. Flush your DNS cache
Open a Command Prompt as administrator and type net stop dnscache, then net start dnscache.
3. Tell Apache where to look
Click on Wamp's icon in tray, go to Apache -> httpd.conf, and add this at the end:
# Tells Apache to identify which site by name
NameVirtualHost *:80
# Tells Apache to serve the default WAMP Server page to "localhost"
<VirtualHost 127.0.0.1>
ServerName localhost
DocumentRoot "C:/wamp/www"
</VirtualHost>
# Tells Apache to serve Client 1's pages to "client1.localhost"
# Duplicate and modify this block to add another client
<VirtualHost 127.0.0.1>
# The name to respond to
ServerName client1.localhost
# Folder where the files live
DocumentRoot "C:/wamp64/www/sites/mysite"
# A few helpful settings...
<Directory "C:/wamp64/www/sites/mysite">
allow from all
order allow,deny
# Enables .htaccess files for this site
AllowOverride All
</Directory>
# Apache will look for these two files, in this order, if no file is specified in the URL
DirectoryIndex index.html index.php
</VirtualHost>
(source)
4. Restart Apache
Click on Wamp's icon in tray, select "restart"
5. Define a base url
Go to your project folder, add <base href="http://mysite.localhost" /> to your <head> section to prevent /links to server root from being broken.
Personally, I inject this html code dynamically into my template using PHP (something like $site_root = (IS_LOCALHOST) ? '<base href="http://mysite.localhost" />' : null;) so I don't have to bother removing that once on production.

Hello you need to open the index.php from the wamp server and change $suppress_localhost = false; from $suppress_localhost = true; then your wamp will working fine

Related

WampServer: The requested URL was not found on this server [duplicate]

I am installing the Wamp Server on another computer to run a mid-sized database and UI. I have been successful in blocking IIS and routing the server to Localhost:8080. But whenever I try to access on of my projects from the localhost homepage, in the www file; I get redirected to a Page not found error.
When I hover above the links the directory always comes up "http:// ProjectFolderNameHere /". when it's supposed to be "http:// LocalHost:8080 / ProjectFolderNameHere /". What can I do to get the links working properly?
My Machine runs on Windows 7 Home Edition 64-bits, and I already have Microsoft's IIS disabled.
How to create a Virtual Host in WampServer
WAMPServer 3 has made this process much easier!
You can do almost everything from a utility provided as part of WAMPServer.
Create a folder inside to contain your project.site. This can be under the C:\wamp\www\ directory or in a completely seperate folder like C:\websites.
Create a folder inside the location you have chosen EG C:\websites\project1\www or under the c:\wamp\www\project1\www
Now open localhost wampmanager->localhost and click on the link Add a Virtual Host under the TOOLS section on the homepage.
You will see a page like this:
Fill in the fields as specified by the instructions above each field
The Virtual Host config will have been created for you.
Now you must restart the DNS Cache. You can do this from the wampmanager menus like this right click wampmanager->Tools->Restart DNS. The DNS Cache will be restarted and then Apache will also be stopped and restarted. When the wampmanager icon goes green again all is completed.
Now you must create a simple index.php file or install your site into the folder you created above.
Assuming your VH was called project.dev You should see that name under the Your Virtual Hosts Section of the WAMPServer homepage.
You can launch the site from this menu, or just use the new Domain Name in the address bar EG project1.dev and the site shoudl launch.
Old WAMPServer 2.5 mechanism, or if you want to do it all manually
There has been a change of concept in WampServer 2.5 and above and there is a good reason for this change!
In WampServer it is now STRONGLY encouraged to create a Virtual Host for each of your projects, even if you hold them in a \wamp\www\subfolder structure.
Virtual Hosts Documentation
Virtual Host Examples
The WampServer home page ( \wamp\www\index.php ) now expects you to have created a Virtual Host for all your projects and will therefore work properly only if you do so.
History
In order to make life easier for beginners using WampServer to learn PHP Apache and MySQL it was suggested that you create subfolders under the \wamp\www\ folder.
wamp
|-- www
|-- Chapter1
|-- Chapter2
|-- etc
These subfolders would then show as links in the WampServer Homepage under a menu called 'Your Projects' and these links would contain a link to localhost/subfoldername.
Acceptable only for simple tutorials
This made life easy for the complete beginner, and was perfectly acceptable for example for those following tutorials to learn PHP coding.
However it was never intended for use when developing a real web site that you would later want to copy to your live hosted server.
In fact if you did use this mechanism it often caused problems as the live sites configuration would not match your development configuration.
The Problem for real website development.
The reason for this is of course that the default DocumentRoot setting for wamp is
DocumentRoot "c:/wamp/www/"
regardless of what your subfolder was called.
This ment that often used PHP code that queried the structure or your site received different information when running on your development WampServer to what it would receive when running on a live hosted server, where the DocumentRoot configuration points to the folder at the top of the website file hierarchy.
This kind of code exists in many frameworks and CMS's for example WordPress and Joomla etc.
For Example
Lets say we have a project called project1 held in wamp\www\project1 and run incorrectly as localhost/project1/index.php
This is what would be reported by some of the PHP command in question:
$_SERVER['HTTP_HOST'] = localhost
$_SERVER['SERVER_NAME'] = localhost
$_SERVER['DOCUMENT_ROOT'] = c:/wamp/www
Now if we had correctly defined that site using a Virtual Host definition and ran it as http://project1 the results on the WAMPServer devlopment site will match those received when on a live hosted environment.
$_SERVER['HTTP_HOST'] = project1
$_SERVER['SERVER_NAME'] = project1
$_SERVER['DOCUMENT_ROOT'] = c:/wamp/www/project1
Now this difference may seem trivial at first but if you were to use a framework like WordPress or one of the CMS's like Joomla for example, this can and does cause problems when you move your site to a live server.
How to create a Virtual Host in WampServer
Actually this should work basically the same for any wndows Apache server, with differences only in where you may find the Apache config files.
There are 3 steps to create your first Virtual Host in Apache, and only 2 if you already have one defined.
Create the Virtual Host definition(s)
Add your new domain name to the HOSTS file.
Uncomment the line in httpd.conf that includes the Virtual Hosts definition file.
Step 1, Create the Virtual Host definition(s)
Edit the file called httpd-hosts.conf which for WampServer lives in
\wamp\bin\apache\apache2.4.9\conf\extra\httpd-vhosts.conf
(Apache version numbers may differ, engage brain before continuing)
If this is the first time you edit this file, remove the default example code, it is of no use.
I am assuming we want to create a definition for a site called project1 that lives in
\wamp\www\project1
Very important, first we must make sure that localhost still works so that is the first VHOST definition we will put in this file.
<VirtualHost *:80>
DocumentRoot "c:/wamp/www"
ServerName localhost
ServerAlias localhost
<Directory "c:/wamp/www">
Options Indexes FollowSymLinks
AllowOverride All
Require local
</Directory>
</VirtualHost>
Now we define our project: and this of course you do for each of your projects as you start a new one.
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/project1"
ServerName project1
<Directory "c:/wamp/www/project1">
Options Indexes FollowSymLinks
AllowOverride All
Require local
</Directory>
</VirtualHost>
NOTE: That each Virtual Host as its own DocumentRoot defined. There are also many other parameters you can add to a Virtual Hosts definition, check the Apache documentation.
Small aside
The way virtual hosts work in Apache: The first definition in this file will also be the default site, so should the domain name used in the browser not match any actually defined virtually hosted domain, making localhost the first domain in the file will therefore make it the site that is loaded if a hack attempt just uses your IP Address.
So if we ensure that the Apache security for this domain is ALWAYS SET TO
Require local
any casual hack from an external address will receive an error and not get into your PC, but should you misspell a domain you will be shown the WampServer homepage, because you are on the same PC as WampServer and therfore local.
Step 2:
Add your new domain name to the HOSTS file.
Now we need to add the domain name that we have used in the Virtual Host definition to the HOSTS file so that windows knows where to find it. This is similiar to creating a DNS A record, but it is only visible in this case on this specific PC.
Edit C:\windows\system32\drivers\etc\hosts
The file has no extension and should remain that way. Watch out for notepad, as it may try and add a .txt extension if you have no better editor.
I suggest you download Notepad++, its free and a very good editor.
Also this is a protected file so you must edit it with administrator privileges, so launch you editor using the Run as Administrator menu option.
The hosts file should look like this when you have completed these edits
127.0.0.1 localhost
127.0.0.1 project1
::1 localhost
::1 project1
Note that you should have definitions in here for the IPV4 loopback address 127.0.0.1 and also the IPV6 loopback address ::1 as Apache is now IPV6 aware and the browser will use either IPV4 or IPV6 or both. I have no idea how it decides which to use, but it can use either if you have the IPV6 stack turned on, and most window OS's do as of XP SP3.
Now we must tell windows to refresh its domain name cache, so launch a command window again using the Run as Administrator menu option again, and do the following.
net stop dnscache
net start dnscache
This forces windows to clear its domain name cache and reload it, in reloading it will re-read the HOSTS file so now it knows about the domain project1.
Step 3: Uncomment the line in httpd.conf that includes the Virtual Hosts definition file.
Edit your httpd.conf, use the wampmanager.exe menus to make sure you edit the correct file.
Find this line in httpd.conf
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf
And just remove the # to uncomment that line.
To activate this change in you running Apache we must now stop and restart the Apache service.
wampmanager.exe -> Apache -> Service -> Restart Service
Now if the WAMP icon in the system tray does not go GREEN again, it means you have probably done something wrong in the \wamp\bin\apache\apache2.4.9\conf\extra\httpd-hosts.conf file.
If so here is a useful mechanism to find out what is wrong. It uses a feature of the Apache exe (httpd.exe) to check its config files and report errors by filename and line numbers.
Launch a command window.
cd \wamp\bin\apache\apache2.4.9\bin
httpd -t
So fix the errors and retest again until you get the output
Syntax OK
Now there is one more thing.
There are actually 2 new menu items on the wampmanager menu system. One called 'My Projects' which is turned on by default.
And a second one, called 'My Virtual Hosts', which is not activated by default.
'My Projects' will list any sub directory of the \wamp\www directory and provide a link to launch the site in that sub directory.
As I said earlier, it launches 'project1` and not 'localhost/project1' so to make the link work we must create a Virtual Host definition to make this link actually launch that site in your browser, without the Virtual Host definition it's likely to launch a web search for the site name as a keyword or just return a site not found condition.
The 'My Virtual Hosts' menu item is a little different. It searches the file that is used to define Virtual Hosts ( we will get to that in a minute ) and creates menu links for each ServerName parameter it finds and creates a menu item for each one.
This may seem a little confusing as once we create a Virtual Host definition for the sub directories of the \wamp\www folder some items will appear on both of the 'My Projects' menu and the 'My Virtual Hosts' menu's.
How do I turn this other 'My Virtual Hosts' menu on?
Make a backup of the \wamp\wampmanager.tpl file, just in case you make a mistake, its a very important file.
Edit the \wamp\wampmanager.tpl
Find this parameter ;WAMPPROJECTSUBMENU, its in the '[Menu.Left]' section.
Add this new parameter ;WAMPVHOSTSUBMENU either before or after the ;WAMPPROJECTSUBMENU parameter.
Save the file.
Now right click the wampmanager icon, and select 'Refresh'. If this does not add the menu, 'exit' and restart wampmanager.
Big Note
The new menu will only appear if you already have some Virtual Hosts defined! Otherwise you will see no difference until you define a VHOST.
Now if you take this to its logical extension
You can now move your web site code completely outside the \wamp\ folder structure simply by changing the DocumentRoot parameter in the VHOST definition. So for example you could do this:
Create a folder on the wamp disk or any other disk ( beware of network drive, they are a bit more complicated)
D:
MD websites
CD websites
MD example.com
CD example.com
MD www
You now copy your site code to, or start creating it in the \websites\example.com\www folder and define your VHOST like this:
<VirtualHost *:80>
DocumentRoot "d:/websites/example.com/www"
ServerName example.dev
ServerAlias www.example.dev
<Directory "d:/websites/example.com/www">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
php_flag display_errors Off
php_flag log_errors On
php_value max_upload_size 40M
php_value max_execution_time 60
php_value error_log "d:/wamp/logs/example_com_phperror.log"
</VirtualHost>
Then add this new development domain to the HOSTS file:
127.0.0.1 localhost
::1 localhost
127.0.0.1 project1
::1 project1
127.0.0.1 example.dev
::1 example.dev
NOTE: It is not a good idea to use a ServerName or ServerAlias that is the same as your live domain name, as if we had used example.com as the ServerName it would mean we could no longer get to the real live site from this PC as it would direct example.com to 127.0.0.1 i.e. this PC and not out onto the internet.
ALSO:
See that I have allowed this site to be accessed from the internet from within the VHOST definitions, this change will apply to only this site and no other. Very useful for allowing a client to view your changes for an hour or so without having to copy them to the live server.
This does mean that we have to edit this file manually to turn this access on and off rather than use the Put Online/Offline menu item on wampmanager.
Also I have added some modifications to the PHP config, again that will only apply to this one site.
Very useful when maintaining a site with specific requirement unlike all the other sites you maintain.
I guess we can assume from the parameters used that it has a long running page in it somewhere and it is very badly written and will not run with errors being displayed on the browser without making a horrible mess of the page. Believe me sites like this exist and people still want them maintained badly. But this mean we only have to change these parameters for this specific site and not globally to all Virtual sites running on WampServer.
I believe this is the best solution:
Open index.php in www folder and set
change line
30:$suppress_localhost = true;
to
$suppress_localhost = false;
This will ensure the project is prefixed with your local host IP/name
Open index.php in www folder and set
$suppress_localhost = false;
This will prepend http://localhost/ to your project links
In order to access project from the homepage you need to create a Virtual Host first.
Most easiest way to do this is to use Wamp's Add a Virtual Host Utility.
Just follow these steps:
Create a folder inside "C:\wamp\www\" directory and give it a name that you want to give to your site for eg. 'mysite'. So the path would be "C:\wamp\www\mysite".
Now open localhost's homepage in your browser, under Tools menu click on Add a Virtual Host link.
Enter the name of the virtual host, that name must be the name of the folder we created inside www directory i.e. 'mysite'.
Enter absolute path of the virtual host i.e. "C:\wamp\www\mysite\" without quotes and click the button below saying 'Start the creation of the VirtualHost'.
Virtual Host created, now you just need to 'Restart DNS'. To do this right click the wamp server's tray menu icon, click on Tools > Restart DNS and let the tray menu icon become green again.
All set! Now just create 'index.php' page inside "C:\wamp\www\mysite\" directory. Add some code in 'index.php' file, like
<?php
echo "<h1>Hello World</h1>";
?>
Now you can access the projects from the localhost's homepage. Just click the project link and you'll see 'Hello World' printed on your screen.
You can follow all steps by #RiggsFolly thats is really good answer, If you do not want to create virtual host and want to use like previous localhost/example/ or something like that you can use answer by #Arunu
But if you still face problem please use this method,
Locate your wamp folder (Eg. c:/Wamp/) where you have installed
Goto Wamp/www/
Open index.php file
find this code $projectContents .= '<li>'.$file.'</li>';
modify it add localhost after http:// $projectContents .= '<li>'.$file.'</li>';
Restart wamp server
open localhost see the updated links
Hope you got your url like previous version of wamp server.
How To Fix The Broken Icon Links (blank.gif, text.gif, etc.)
Unfortunately as previously mentioned, simply adding a virtual host to your project doesn't fix the broken icon links.
The Problem:
WAMP/Apache does not change the directory reference for the icons to your respective installation directory. It is statically set to "c:/Apache24/icons" and 99.9% of users Apache installation does not reside here. Especially with WAMP.
The Fix:
Find your Apache icons directory! Typically it will be located here: "c:/wamp/bin/apache/apache2.4.9/icons". However your mileage may vary depending on your installation and if your Apache version is different, then your path will be different as well.\
Open up httpd-autoindex.conf in your favorite editor. This file can usually be found here: "C:\wamp\bin\apache\apache2.4.9\conf\extra\httpd-autoindex.conf". Again, if your Apache version is different, then so will this path.
Find this definition (usually located near the top of the file):
Alias /icons/ "c:/Apache24/icons/"
<Directory "c:/Apache24/icons">
Options Indexes MultiViews
AllowOverride None
Require all granted
</Directory>
Replace the "c:/Apache24/icons/" directories with your own. IMPORTANT You MUST have a trailing forward slash in the first directory reference. The second directory reference must have no trailing slash. Your results should look similar to this. Again, your directory may differ:
Alias /icons/ "c:/wamp/bin/apache/apache2.4.9/icons/"
<Directory "c:/wamp/bin/apache/apache2.4.9/icons">
Options Indexes MultiViews
AllowOverride None
Require all granted
</Directory>
Restart your Apache server and enjoy your cool icons!
$suppress_localhost = false;
This did the trick for me.
This works on Wamp 3+.
Go to wamp folder (wamp/ or wamp64/)
Open wampmanager.conf
Find urlAddLocalhost param and set it on: urlAddLocalhost = "on"
There should not be the need to tweak the index.php in www folder.
Re: Wampserver LocalHost links not working correctly
This is as of June 2014 with Wampserver2.5 (maybe they'll fix this in later builds).
Note: to use LocalHost:8080 instead of LocalHost just make the appropriate changes in the edits mentioned below.
There are 2 aspects of this issue -
The first is to be able to access items under "Your Projects" from the Wamp localhost homepage.
The second is to be able to correctly access items listed in the Wampserver Icon Taskbar's "My Projects" list.
To fix the first (to be able to access items under "Your Projects" from the Wamp localhost homepage) you will need to do the following...
There are 2 edits that you must make in the index.php file located in your wamp\www folder (usually C:\wamp\www)
1) on Line 30 change
$suppress_localhost = true;
to
$suppress_localhost = false;
2) on line 338 change
$projectContents .= '<li>'.$file.'</li>';
to
$projectContents .= '<li>'.$file.'</li>';
After you've made the above edits - if the Wampserver is running just refresh the local host page and the changes become immediately effective.
To fix the 2nd item (the Wampserver Icon Taskbar's "My Projects" list):
You need to edit C:\wamp\scripts\refresh.php
Locate line 651 and change the section of the line that reads
Parameters: "http://'.$projectContents[$i].'/"; Glyph: 5
to
Parameters: "http://localhost//'.$projectContents[$i].'/"; Glyph: 5
After you make these 2nd set of changes you may have to force Wampserver to refresh the "My Projects" list by toggling the Put Online/Offline option at the bottom of the Wamp Icon Tray App.
check wamp server icon is green or not if it is green then it is working if not then you have to follow these steps to do
a. all the programs should be closed before running the wamp because most of the cases some softwares like skype takes the same port (80) which is using by wamp.
b. you can change the port of skype : Tool-s->oprions->advanced->connection untick use port 80
restart the wamp it will work.
SECOND case
when you click on the project in loalhost it does not show the localhost infront of the project name and because of that it looks like wamp is not working then you have to one thing on only
. go to wamp index.php file and change $suppress_localhost = false; from $suppress_localhost = true; or try vice versa it will work
Navigate to your www directory (if you are using wamp server) htdocs (if on XAMPP). Open your admin.php and search on project contents/ or just go directly to line number 339 and change the link, inserting 'local host to the link .
That should work ,,
I find it's a lot easier (than accepted answer) to create a local subdomain by project and tell Apache to serve multiple sites by name.
For example, let's say you created a project under c:/wamp64/www/sites/mysite, to be able to access it at http://mysite.localhost you simply need to do the following:
1. Tell your machine to answer to different names
Add 127.0.0.1 mysite.localhost to C:\windows\system32\drivers\etc\hosts
2. Flush your DNS cache
Open a Command Prompt as administrator and type net stop dnscache, then net start dnscache.
3. Tell Apache where to look
Click on Wamp's icon in tray, go to Apache -> httpd.conf, and add this at the end:
# Tells Apache to identify which site by name
NameVirtualHost *:80
# Tells Apache to serve the default WAMP Server page to "localhost"
<VirtualHost 127.0.0.1>
ServerName localhost
DocumentRoot "C:/wamp/www"
</VirtualHost>
# Tells Apache to serve Client 1's pages to "client1.localhost"
# Duplicate and modify this block to add another client
<VirtualHost 127.0.0.1>
# The name to respond to
ServerName client1.localhost
# Folder where the files live
DocumentRoot "C:/wamp64/www/sites/mysite"
# A few helpful settings...
<Directory "C:/wamp64/www/sites/mysite">
allow from all
order allow,deny
# Enables .htaccess files for this site
AllowOverride All
</Directory>
# Apache will look for these two files, in this order, if no file is specified in the URL
DirectoryIndex index.html index.php
</VirtualHost>
(source)
4. Restart Apache
Click on Wamp's icon in tray, select "restart"
5. Define a base url
Go to your project folder, add <base href="http://mysite.localhost" /> to your <head> section to prevent /links to server root from being broken.
Personally, I inject this html code dynamically into my template using PHP (something like $site_root = (IS_LOCALHOST) ? '<base href="http://mysite.localhost" />' : null;) so I don't have to bother removing that once on production.
Hello you need to open the index.php from the wamp server and change $suppress_localhost = false; from $suppress_localhost = true; then your wamp will working fine

Project Links do not work on Wamp Server

I am installing the Wamp Server on another computer to run a mid-sized database and UI. I have been successful in blocking IIS and routing the server to Localhost:8080. But whenever I try to access on of my projects from the localhost homepage, in the www file; I get redirected to a Page not found error.
When I hover above the links the directory always comes up "http:// ProjectFolderNameHere /". when it's supposed to be "http:// LocalHost:8080 / ProjectFolderNameHere /". What can I do to get the links working properly?
My Machine runs on Windows 7 Home Edition 64-bits, and I already have Microsoft's IIS disabled.
How to create a Virtual Host in WampServer
WAMPServer 3 has made this process much easier!
You can do almost everything from a utility provided as part of WAMPServer.
Create a folder inside to contain your project.site. This can be under the C:\wamp\www\ directory or in a completely seperate folder like C:\websites.
Create a folder inside the location you have chosen EG C:\websites\project1\www or under the c:\wamp\www\project1\www
Now open localhost wampmanager->localhost and click on the link Add a Virtual Host under the TOOLS section on the homepage.
You will see a page like this:
Fill in the fields as specified by the instructions above each field
The Virtual Host config will have been created for you.
Now you must restart the DNS Cache. You can do this from the wampmanager menus like this right click wampmanager->Tools->Restart DNS. The DNS Cache will be restarted and then Apache will also be stopped and restarted. When the wampmanager icon goes green again all is completed.
Now you must create a simple index.php file or install your site into the folder you created above.
Assuming your VH was called project.dev You should see that name under the Your Virtual Hosts Section of the WAMPServer homepage.
You can launch the site from this menu, or just use the new Domain Name in the address bar EG project1.dev and the site shoudl launch.
Old WAMPServer 2.5 mechanism, or if you want to do it all manually
There has been a change of concept in WampServer 2.5 and above and there is a good reason for this change!
In WampServer it is now STRONGLY encouraged to create a Virtual Host for each of your projects, even if you hold them in a \wamp\www\subfolder structure.
Virtual Hosts Documentation
Virtual Host Examples
The WampServer home page ( \wamp\www\index.php ) now expects you to have created a Virtual Host for all your projects and will therefore work properly only if you do so.
History
In order to make life easier for beginners using WampServer to learn PHP Apache and MySQL it was suggested that you create subfolders under the \wamp\www\ folder.
wamp
|-- www
|-- Chapter1
|-- Chapter2
|-- etc
These subfolders would then show as links in the WampServer Homepage under a menu called 'Your Projects' and these links would contain a link to localhost/subfoldername.
Acceptable only for simple tutorials
This made life easy for the complete beginner, and was perfectly acceptable for example for those following tutorials to learn PHP coding.
However it was never intended for use when developing a real web site that you would later want to copy to your live hosted server.
In fact if you did use this mechanism it often caused problems as the live sites configuration would not match your development configuration.
The Problem for real website development.
The reason for this is of course that the default DocumentRoot setting for wamp is
DocumentRoot "c:/wamp/www/"
regardless of what your subfolder was called.
This ment that often used PHP code that queried the structure or your site received different information when running on your development WampServer to what it would receive when running on a live hosted server, where the DocumentRoot configuration points to the folder at the top of the website file hierarchy.
This kind of code exists in many frameworks and CMS's for example WordPress and Joomla etc.
For Example
Lets say we have a project called project1 held in wamp\www\project1 and run incorrectly as localhost/project1/index.php
This is what would be reported by some of the PHP command in question:
$_SERVER['HTTP_HOST'] = localhost
$_SERVER['SERVER_NAME'] = localhost
$_SERVER['DOCUMENT_ROOT'] = c:/wamp/www
Now if we had correctly defined that site using a Virtual Host definition and ran it as http://project1 the results on the WAMPServer devlopment site will match those received when on a live hosted environment.
$_SERVER['HTTP_HOST'] = project1
$_SERVER['SERVER_NAME'] = project1
$_SERVER['DOCUMENT_ROOT'] = c:/wamp/www/project1
Now this difference may seem trivial at first but if you were to use a framework like WordPress or one of the CMS's like Joomla for example, this can and does cause problems when you move your site to a live server.
How to create a Virtual Host in WampServer
Actually this should work basically the same for any wndows Apache server, with differences only in where you may find the Apache config files.
There are 3 steps to create your first Virtual Host in Apache, and only 2 if you already have one defined.
Create the Virtual Host definition(s)
Add your new domain name to the HOSTS file.
Uncomment the line in httpd.conf that includes the Virtual Hosts definition file.
Step 1, Create the Virtual Host definition(s)
Edit the file called httpd-hosts.conf which for WampServer lives in
\wamp\bin\apache\apache2.4.9\conf\extra\httpd-vhosts.conf
(Apache version numbers may differ, engage brain before continuing)
If this is the first time you edit this file, remove the default example code, it is of no use.
I am assuming we want to create a definition for a site called project1 that lives in
\wamp\www\project1
Very important, first we must make sure that localhost still works so that is the first VHOST definition we will put in this file.
<VirtualHost *:80>
DocumentRoot "c:/wamp/www"
ServerName localhost
ServerAlias localhost
<Directory "c:/wamp/www">
Options Indexes FollowSymLinks
AllowOverride All
Require local
</Directory>
</VirtualHost>
Now we define our project: and this of course you do for each of your projects as you start a new one.
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/project1"
ServerName project1
<Directory "c:/wamp/www/project1">
Options Indexes FollowSymLinks
AllowOverride All
Require local
</Directory>
</VirtualHost>
NOTE: That each Virtual Host as its own DocumentRoot defined. There are also many other parameters you can add to a Virtual Hosts definition, check the Apache documentation.
Small aside
The way virtual hosts work in Apache: The first definition in this file will also be the default site, so should the domain name used in the browser not match any actually defined virtually hosted domain, making localhost the first domain in the file will therefore make it the site that is loaded if a hack attempt just uses your IP Address.
So if we ensure that the Apache security for this domain is ALWAYS SET TO
Require local
any casual hack from an external address will receive an error and not get into your PC, but should you misspell a domain you will be shown the WampServer homepage, because you are on the same PC as WampServer and therfore local.
Step 2:
Add your new domain name to the HOSTS file.
Now we need to add the domain name that we have used in the Virtual Host definition to the HOSTS file so that windows knows where to find it. This is similiar to creating a DNS A record, but it is only visible in this case on this specific PC.
Edit C:\windows\system32\drivers\etc\hosts
The file has no extension and should remain that way. Watch out for notepad, as it may try and add a .txt extension if you have no better editor.
I suggest you download Notepad++, its free and a very good editor.
Also this is a protected file so you must edit it with administrator privileges, so launch you editor using the Run as Administrator menu option.
The hosts file should look like this when you have completed these edits
127.0.0.1 localhost
127.0.0.1 project1
::1 localhost
::1 project1
Note that you should have definitions in here for the IPV4 loopback address 127.0.0.1 and also the IPV6 loopback address ::1 as Apache is now IPV6 aware and the browser will use either IPV4 or IPV6 or both. I have no idea how it decides which to use, but it can use either if you have the IPV6 stack turned on, and most window OS's do as of XP SP3.
Now we must tell windows to refresh its domain name cache, so launch a command window again using the Run as Administrator menu option again, and do the following.
net stop dnscache
net start dnscache
This forces windows to clear its domain name cache and reload it, in reloading it will re-read the HOSTS file so now it knows about the domain project1.
Step 3: Uncomment the line in httpd.conf that includes the Virtual Hosts definition file.
Edit your httpd.conf, use the wampmanager.exe menus to make sure you edit the correct file.
Find this line in httpd.conf
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf
And just remove the # to uncomment that line.
To activate this change in you running Apache we must now stop and restart the Apache service.
wampmanager.exe -> Apache -> Service -> Restart Service
Now if the WAMP icon in the system tray does not go GREEN again, it means you have probably done something wrong in the \wamp\bin\apache\apache2.4.9\conf\extra\httpd-hosts.conf file.
If so here is a useful mechanism to find out what is wrong. It uses a feature of the Apache exe (httpd.exe) to check its config files and report errors by filename and line numbers.
Launch a command window.
cd \wamp\bin\apache\apache2.4.9\bin
httpd -t
So fix the errors and retest again until you get the output
Syntax OK
Now there is one more thing.
There are actually 2 new menu items on the wampmanager menu system. One called 'My Projects' which is turned on by default.
And a second one, called 'My Virtual Hosts', which is not activated by default.
'My Projects' will list any sub directory of the \wamp\www directory and provide a link to launch the site in that sub directory.
As I said earlier, it launches 'project1` and not 'localhost/project1' so to make the link work we must create a Virtual Host definition to make this link actually launch that site in your browser, without the Virtual Host definition it's likely to launch a web search for the site name as a keyword or just return a site not found condition.
The 'My Virtual Hosts' menu item is a little different. It searches the file that is used to define Virtual Hosts ( we will get to that in a minute ) and creates menu links for each ServerName parameter it finds and creates a menu item for each one.
This may seem a little confusing as once we create a Virtual Host definition for the sub directories of the \wamp\www folder some items will appear on both of the 'My Projects' menu and the 'My Virtual Hosts' menu's.
How do I turn this other 'My Virtual Hosts' menu on?
Make a backup of the \wamp\wampmanager.tpl file, just in case you make a mistake, its a very important file.
Edit the \wamp\wampmanager.tpl
Find this parameter ;WAMPPROJECTSUBMENU, its in the '[Menu.Left]' section.
Add this new parameter ;WAMPVHOSTSUBMENU either before or after the ;WAMPPROJECTSUBMENU parameter.
Save the file.
Now right click the wampmanager icon, and select 'Refresh'. If this does not add the menu, 'exit' and restart wampmanager.
Big Note
The new menu will only appear if you already have some Virtual Hosts defined! Otherwise you will see no difference until you define a VHOST.
Now if you take this to its logical extension
You can now move your web site code completely outside the \wamp\ folder structure simply by changing the DocumentRoot parameter in the VHOST definition. So for example you could do this:
Create a folder on the wamp disk or any other disk ( beware of network drive, they are a bit more complicated)
D:
MD websites
CD websites
MD example.com
CD example.com
MD www
You now copy your site code to, or start creating it in the \websites\example.com\www folder and define your VHOST like this:
<VirtualHost *:80>
DocumentRoot "d:/websites/example.com/www"
ServerName example.dev
ServerAlias www.example.dev
<Directory "d:/websites/example.com/www">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
php_flag display_errors Off
php_flag log_errors On
php_value max_upload_size 40M
php_value max_execution_time 60
php_value error_log "d:/wamp/logs/example_com_phperror.log"
</VirtualHost>
Then add this new development domain to the HOSTS file:
127.0.0.1 localhost
::1 localhost
127.0.0.1 project1
::1 project1
127.0.0.1 example.dev
::1 example.dev
NOTE: It is not a good idea to use a ServerName or ServerAlias that is the same as your live domain name, as if we had used example.com as the ServerName it would mean we could no longer get to the real live site from this PC as it would direct example.com to 127.0.0.1 i.e. this PC and not out onto the internet.
ALSO:
See that I have allowed this site to be accessed from the internet from within the VHOST definitions, this change will apply to only this site and no other. Very useful for allowing a client to view your changes for an hour or so without having to copy them to the live server.
This does mean that we have to edit this file manually to turn this access on and off rather than use the Put Online/Offline menu item on wampmanager.
Also I have added some modifications to the PHP config, again that will only apply to this one site.
Very useful when maintaining a site with specific requirement unlike all the other sites you maintain.
I guess we can assume from the parameters used that it has a long running page in it somewhere and it is very badly written and will not run with errors being displayed on the browser without making a horrible mess of the page. Believe me sites like this exist and people still want them maintained badly. But this mean we only have to change these parameters for this specific site and not globally to all Virtual sites running on WampServer.
I believe this is the best solution:
Open index.php in www folder and set
change line
30:$suppress_localhost = true;
to
$suppress_localhost = false;
This will ensure the project is prefixed with your local host IP/name
Open index.php in www folder and set
$suppress_localhost = false;
This will prepend http://localhost/ to your project links
In order to access project from the homepage you need to create a Virtual Host first.
Most easiest way to do this is to use Wamp's Add a Virtual Host Utility.
Just follow these steps:
Create a folder inside "C:\wamp\www\" directory and give it a name that you want to give to your site for eg. 'mysite'. So the path would be "C:\wamp\www\mysite".
Now open localhost's homepage in your browser, under Tools menu click on Add a Virtual Host link.
Enter the name of the virtual host, that name must be the name of the folder we created inside www directory i.e. 'mysite'.
Enter absolute path of the virtual host i.e. "C:\wamp\www\mysite\" without quotes and click the button below saying 'Start the creation of the VirtualHost'.
Virtual Host created, now you just need to 'Restart DNS'. To do this right click the wamp server's tray menu icon, click on Tools > Restart DNS and let the tray menu icon become green again.
All set! Now just create 'index.php' page inside "C:\wamp\www\mysite\" directory. Add some code in 'index.php' file, like
<?php
echo "<h1>Hello World</h1>";
?>
Now you can access the projects from the localhost's homepage. Just click the project link and you'll see 'Hello World' printed on your screen.
You can follow all steps by #RiggsFolly thats is really good answer, If you do not want to create virtual host and want to use like previous localhost/example/ or something like that you can use answer by #Arunu
But if you still face problem please use this method,
Locate your wamp folder (Eg. c:/Wamp/) where you have installed
Goto Wamp/www/
Open index.php file
find this code $projectContents .= '<li>'.$file.'</li>';
modify it add localhost after http:// $projectContents .= '<li>'.$file.'</li>';
Restart wamp server
open localhost see the updated links
Hope you got your url like previous version of wamp server.
How To Fix The Broken Icon Links (blank.gif, text.gif, etc.)
Unfortunately as previously mentioned, simply adding a virtual host to your project doesn't fix the broken icon links.
The Problem:
WAMP/Apache does not change the directory reference for the icons to your respective installation directory. It is statically set to "c:/Apache24/icons" and 99.9% of users Apache installation does not reside here. Especially with WAMP.
The Fix:
Find your Apache icons directory! Typically it will be located here: "c:/wamp/bin/apache/apache2.4.9/icons". However your mileage may vary depending on your installation and if your Apache version is different, then your path will be different as well.\
Open up httpd-autoindex.conf in your favorite editor. This file can usually be found here: "C:\wamp\bin\apache\apache2.4.9\conf\extra\httpd-autoindex.conf". Again, if your Apache version is different, then so will this path.
Find this definition (usually located near the top of the file):
Alias /icons/ "c:/Apache24/icons/"
<Directory "c:/Apache24/icons">
Options Indexes MultiViews
AllowOverride None
Require all granted
</Directory>
Replace the "c:/Apache24/icons/" directories with your own. IMPORTANT You MUST have a trailing forward slash in the first directory reference. The second directory reference must have no trailing slash. Your results should look similar to this. Again, your directory may differ:
Alias /icons/ "c:/wamp/bin/apache/apache2.4.9/icons/"
<Directory "c:/wamp/bin/apache/apache2.4.9/icons">
Options Indexes MultiViews
AllowOverride None
Require all granted
</Directory>
Restart your Apache server and enjoy your cool icons!
$suppress_localhost = false;
This did the trick for me.
This works on Wamp 3+.
Go to wamp folder (wamp/ or wamp64/)
Open wampmanager.conf
Find urlAddLocalhost param and set it on: urlAddLocalhost = "on"
There should not be the need to tweak the index.php in www folder.
Re: Wampserver LocalHost links not working correctly
This is as of June 2014 with Wampserver2.5 (maybe they'll fix this in later builds).
Note: to use LocalHost:8080 instead of LocalHost just make the appropriate changes in the edits mentioned below.
There are 2 aspects of this issue -
The first is to be able to access items under "Your Projects" from the Wamp localhost homepage.
The second is to be able to correctly access items listed in the Wampserver Icon Taskbar's "My Projects" list.
To fix the first (to be able to access items under "Your Projects" from the Wamp localhost homepage) you will need to do the following...
There are 2 edits that you must make in the index.php file located in your wamp\www folder (usually C:\wamp\www)
1) on Line 30 change
$suppress_localhost = true;
to
$suppress_localhost = false;
2) on line 338 change
$projectContents .= '<li>'.$file.'</li>';
to
$projectContents .= '<li>'.$file.'</li>';
After you've made the above edits - if the Wampserver is running just refresh the local host page and the changes become immediately effective.
To fix the 2nd item (the Wampserver Icon Taskbar's "My Projects" list):
You need to edit C:\wamp\scripts\refresh.php
Locate line 651 and change the section of the line that reads
Parameters: "http://'.$projectContents[$i].'/"; Glyph: 5
to
Parameters: "http://localhost//'.$projectContents[$i].'/"; Glyph: 5
After you make these 2nd set of changes you may have to force Wampserver to refresh the "My Projects" list by toggling the Put Online/Offline option at the bottom of the Wamp Icon Tray App.
check wamp server icon is green or not if it is green then it is working if not then you have to follow these steps to do
a. all the programs should be closed before running the wamp because most of the cases some softwares like skype takes the same port (80) which is using by wamp.
b. you can change the port of skype : Tool-s->oprions->advanced->connection untick use port 80
restart the wamp it will work.
SECOND case
when you click on the project in loalhost it does not show the localhost infront of the project name and because of that it looks like wamp is not working then you have to one thing on only
. go to wamp index.php file and change $suppress_localhost = false; from $suppress_localhost = true; or try vice versa it will work
Navigate to your www directory (if you are using wamp server) htdocs (if on XAMPP). Open your admin.php and search on project contents/ or just go directly to line number 339 and change the link, inserting 'local host to the link .
That should work ,,
I find it's a lot easier (than accepted answer) to create a local subdomain by project and tell Apache to serve multiple sites by name.
For example, let's say you created a project under c:/wamp64/www/sites/mysite, to be able to access it at http://mysite.localhost you simply need to do the following:
1. Tell your machine to answer to different names
Add 127.0.0.1 mysite.localhost to C:\windows\system32\drivers\etc\hosts
2. Flush your DNS cache
Open a Command Prompt as administrator and type net stop dnscache, then net start dnscache.
3. Tell Apache where to look
Click on Wamp's icon in tray, go to Apache -> httpd.conf, and add this at the end:
# Tells Apache to identify which site by name
NameVirtualHost *:80
# Tells Apache to serve the default WAMP Server page to "localhost"
<VirtualHost 127.0.0.1>
ServerName localhost
DocumentRoot "C:/wamp/www"
</VirtualHost>
# Tells Apache to serve Client 1's pages to "client1.localhost"
# Duplicate and modify this block to add another client
<VirtualHost 127.0.0.1>
# The name to respond to
ServerName client1.localhost
# Folder where the files live
DocumentRoot "C:/wamp64/www/sites/mysite"
# A few helpful settings...
<Directory "C:/wamp64/www/sites/mysite">
allow from all
order allow,deny
# Enables .htaccess files for this site
AllowOverride All
</Directory>
# Apache will look for these two files, in this order, if no file is specified in the URL
DirectoryIndex index.html index.php
</VirtualHost>
(source)
4. Restart Apache
Click on Wamp's icon in tray, select "restart"
5. Define a base url
Go to your project folder, add <base href="http://mysite.localhost" /> to your <head> section to prevent /links to server root from being broken.
Personally, I inject this html code dynamically into my template using PHP (something like $site_root = (IS_LOCALHOST) ? '<base href="http://mysite.localhost" />' : null;) so I don't have to bother removing that once on production.
Hello you need to open the index.php from the wamp server and change $suppress_localhost = false; from $suppress_localhost = true; then your wamp will working fine

WAMP - Remove localhost from project URL

The URLs of my projects in WAMP are not resolving as I'd expect. For example, I'd expect the project in the folder c:\wamp\www\project1 to have the URL http://project1/, but it actually has the URL http://localhost/project1/.
This can cause problems when accessing server variables. How do I fix this?
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.
in your www folder open index.php
at line 30 change:
$suppress_localhost to be false
this is should look:
$suppress_localhost = false;
In your www folder open index.php at line 30. Here, change $suppress_localhost to be false. So, it is should look:
$suppress_localhost = false;
That was the quickest and easiest fix for me. I'm using 64 bit Wamp.
Okay, I had this problem. So, I troubleshooted the problem and traced it to an actual solution, NOT A HACK.
The SOLUTION :
Right-Click WAMP-server icon
Select WAMP Settings,
Select (enable) option Add localhost in URL
DONE. The remainder is FYI of how and why.
Note: localhost/myproject.php or myproject.php. Although the solution was already accepted, I saw some posts that got me confused. The accepted solution is based on a single project wrt different server applications, based on the OP's specific question, and how to influence that single project in question. But all the other solutions are hacks and don't really answer the solution to the OP's question, but do bring up a good point about the URL. So, according to the other "solutions", here is how to toggle the localhost reference in the URL. Hence my additional solution added to the mix.
This is a toggle switch.
Troubleshooting Process (no hacking involved):
Let's peek at the index.php
Let's look at the config file. Note the variables and Array?
Here is the array. A variable used earlier. Let's see... Oh, it tells us where and what to do.
As noted in the SOLUTION:
Your wamp seems to be configured to run a website on the normally non-existant domain helloworld.
add:
127.0.0.1 helloworld
inside this file: c:\windows\system32\drivers\etc\hosts
Make sure you start your text editor with administrator privileges to be able to edit that file.
This will tell your computer that the otherwise non-existant domain helloworld should be resolved to your loop back address.
For me was the easiest way go to http://localhost and in wampserver homepage use Add a Virtual Host (Tools section). There is nice and easy form to create alias without any problem (instead console when you using tray icon to create alias). No source edit, just using what wamp offers. Remember refresh DNS after creating of alias. Tested on Win10, WampServer 3.0.6 64bit.
Create a virtualhost like RiggsFolly said.
And try to uncomment LoadModule rewrite_module modules/mod_rewrite.so in httpd.conf
HostnameLookups ON not OFF in httpd.conf with DocumentRoot changed or not.
tested in browser for
$_SERVER['HTTP_HOST']
$_SERVER['SERVER_NAME']
$_SERVER['DOCUMENT_ROOT']
C:\wamp\www
In index.php
line 338
($suppress_localhost ? 'http://' : '')
change http:// to http://localhost/
To do this you can create a virtual host using Add a virtual Host utility under Tools menu on localhost's homepage.
For more info on how to create a virtual host visit : Step by step instructions
I think that the easiest and quickest way is to:
Open index.php in your www folder >>> change: $suppress_localhost to
be false / no.
This isn't really an answer per se. It seems that the quickest way of removing a Virtual Host using WAMP is either not create one in the first place or be prepared to uninstall/reinstall it. What is the path to the config file to correct a errant and otherwise not malfunctioning WAMP Server?
If your "Your Projects" folder exists in "wamp/www/" and if you can see the localhost home page after starting wampserever correctly, and still you can't access your projects, then simply go to "wamp/www/" folder, open index.php and search for $suppress_localhost and set its value to false. Restart wampserver, go to localhost and try to access your project.
i also faced same problem after installing new wamp setup on window 7, 64bit.
just change line no. 30
$suppress_localhost = false;
Its work for me.
Open index.php in www folder and set
$suppress_localhost = True;===>$suppress_localhost = false;
that is work.
You can update "urlAddLocalhost" variable in "wamp64/wampmanager.conf" file to on/off. By default it is "off".
My wamp version is 3.0.6.
urlAddLocalhost = "off"

Cannot create local copy of Magento

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

PHP image path changes when I move to local server

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.

Categories