简体   繁体   中英

localhost/phpmyadmin can't access when setting virtualhost

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.

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM