5

Here is the situation :

I have a project which I want to run on localhost as http://www.coye.com/ for which I have setup a virtual host which is running perfectly like this:

F:\xampp\apache\conf\extra\httpd-vhosts.conf :

NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "F:/xampp/htdocs"
ServerName localhost
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "F:/xampp/htdocs/coye"
ServerName coye.com
ServerAlias www.coye.com
RewriteEngine on

#Added New by Sandeep - Start
RewriteCond %{HTTP_HOST} !^www.coye\.com$ [NC]
RewriteRule ^(.*)$ http://www.coye.com$1 [R=301,L]

RewriteCond %{REQUEST_URI} !^/images
RewriteCond %{REQUEST_URI} !^/css
RewriteCond %{REQUEST_URI} !^/js
RewriteCond %{REQUEST_URI} !^/fckeditor
RewriteCond %{REQUEST_URI} !^/securityimage
RewriteCond %{REQUEST_URI} !^/sitemap.txt
RewriteRule ^/(.*)$ /index.php?request=$1 [PT,QSA,L]
</VirtualHost>

C:\Windows\System32\drivers\etc\host

127.0.0.1 localhost
127.0.0.1 coye.com 
127.0.0.1 www.coye.com 
127.0.0.1 api.coye.com 
127.0.0.1 merchant.coye.com 
127.0.0.1 admin.coye.com

and now I want to run PHPMyadmim but it not accessible through localhost/phpmyadmin. What changes I have to do to get access PHPMyadmin ? Please guide me on this.

Please help me on this.

Rakesh Shetty
  • 4,548
  • 7
  • 40
  • 79

3 Answers3

13

Finally I found the solution for my problems, hope this will help to others you will face the similar problem :

I have to add this extra piece of code:

NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "F:/xampp/htdocs"
ServerName localhost
</VirtualHost>

So the final file will be -

httpd-vhosts.conf :

NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "F:/xampp/htdocs"
ServerName localhost
</VirtualHost>


<VirtualHost *:80>
DocumentRoot "F:/xampp/htdocs/coye"
ServerName coye.com
ServerAlias www.coye.com
RewriteEngine on

#Added New by Sandeep - Start
RewriteCond %{HTTP_HOST} !^www.coye\.com$ [NC]
RewriteRule ^(.*)$ http://www.coye.com$1 [R=301,L]

RewriteCond %{REQUEST_URI} !^/images
RewriteCond %{REQUEST_URI} !^/css
RewriteCond %{REQUEST_URI} !^/js
RewriteCond %{REQUEST_URI} !^/fckeditor
RewriteCond %{REQUEST_URI} !^/securityimage
RewriteCond %{REQUEST_URI} !^/sitemap.txt
RewriteRule ^/(.*)$ /index.php?request=$1 [PT,QSA,L]
</VirtualHost>

host file :

127.0.0.1 localhost
127.0.0.1 coye.com 
127.0.0.1 www.coye.com 
127.0.0.1 api.coye.com 
127.0.0.1 merchant.coye.com 
127.0.0.1 admin.coye.com

Thanks to everyone who try to help me.

Rakesh Shetty
  • 4,548
  • 7
  • 40
  • 79
1

See you have to keep the original config in hosts file

127.0.0.1 localhost

and to access phpmyadmin you need to go to phpmyadmin.local and not to localhost/phpmyadmin

Virtualhost Config

NameVirtualHost *:80

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot "/usr/local/zend/apache2/htdocs/l2/public"
    ServerName coye.com
    ErrorLog "logs/dummy-host2.example.com-error_log"
    CustomLog "logs/dummy-host2.example.com-access_log" common
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot ""
    ServerName **phpmyadmin.dev**
    ErrorLog "logs/dummy-host2.example.com-error_log"
    CustomLog "logs/dummy-host2.example.com-access_log" common
</VirtualHost>

let me know if it works.

Ayush Ghosh
  • 487
  • 2
  • 10
  • can you please edit your answer and tell me what changes I have to do in host and httpd-vhost.conf file – Rakesh Shetty Aug 04 '14 at 07:15
  • I want to run my project coye using www.coye.com on local thats why I setup a virtual host. From your code I will not able to run www.coye.com – Rakesh Shetty Aug 04 '14 at 07:26
0

Modify your host file as following:

127.0.0.1 localhost
127.0.0.1 coye.com 

then map your "subdomains" (including www) in your apache files and you should be fine

<VirtualHost 127.0.0.1:80>
  DocumentRoot "F:/xampp/htdocs"
  ServerName coye.com
  ServerAlias subdomain.coye.com
</VirtualHost>

The hosts file in windows works as a domain redirector, not a full name redirector, all your subdomains including www.domain.com must pe aliased in apache virtual hosts.