2 Virtual Hosts on Mac - mysql

Hi to everyone I have two different sites and I want to two different host:
movie.local
music.local
These are my files:
#
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
127.0.0.1 movie.local
127.0.0.1 music.local
And
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
ServerName movie.local
ServerAlias www.movie.local
DocumentRoot "/Users/Me/Sites/movie"
ErrorLog "/private/var/log/apache2/site-error_log"
CustomLog "/private/var/log/apache2/site-access_log" common
ServerAdmin neilgee#coolestguidesontheplanet.com
<Directory "/Users/Me/Sites/movie">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName music.local
ServerAlias www.music.local
DocumentRoot "/Users/Me/Sites/music"
ErrorLog "/private/var/log/apache2/site-error_log"
CustomLog "/private/var/log/apache2/site-access_log" common
ServerAdmin neilgee#coolestguidesontheplanet.com
<Directory "/Users/Me/Sites/music">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
But now if I go to movie.local that's ok, but if i go to music.local my browser will load the content of movie.local, why?

if i go to music.local my browser will load the content of movie.local, why?
You can create a subdomain on your localhost like this.
First create a virtual host:
<VirtualHost *:80>
ServerName music.localhost
DocumentRoot "C:/Users/Me/Sites/music"
<Directory "C:/Users/Me/Sites/music">
/....../
/....../
</Directory>
</VirtualHost>
And in your hosts file add this line:
127.0.0.1 music.localhost

Related

Can't acces phpmyadmin after creating WAMP vHost

Today I've created a virtual host in WAMP but after that I couldn't access localhost/phpmyadmin and localhost anymore I've also tried to make a vhost for that aswell but it didn't work.
The file httpd-vhosts.conf is included correctly.
EDIT: I can access pao.dev
httpd-vhosts.conf
<VirtualHost *:80>
ServerName pao.dev
DocumentRoot C:/wamp/www/pao/PAO-zwabbertje/public
<Directory C:/wamp/www/pao/PAO-zwabbertje/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName phpmyadmin.dev
DocumentRoot c:/wamp/apps/phpmyadmin4.1.14/
<Directory "c:/wamp/apps/phpmyadmin4.1.14/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Allow from all
</Directory>
</VirtualHost>
pc hosts
127.0.0.1 localhost
127.0.0.1 pao.dev
127.0.0.1 phpmyadmin.dev
Error:
Forbidden
You don't have permission to access /phpmyadmin on this server.
Apache/2.4.9 (Win32) PHP/5.5.12 Server at localhost Port 80

How to change vhosts entry when document root is now a few folders further down

Im using Ubuntu in a VM. I have a script that creates Drupal sites and sets the appropriate vhosts entry. Below is an example:
<VirtualHost *:80>
ServerName d7.dev
ServerAlias *.d7.dev
DocumentRoot /home/drupalpro/websites/d7.dev
<Directory /home/drupalpro/websites/d7.dev>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName d7.dev
ServerAlias *.d7.dev
DocumentRoot /home/drupalpro/websites/d7.dev
<Directory /home/drupalpro/websites/d7.dev>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
SSLEngine on
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
</VirtualHost>
</IfModule>
Ive checked out a site to work on however the web root is now a few folders down. So instead of something like this:
/home/drupalpro/websites/d7.dev
Its now
/home/drupalpro/websites/d7.dev/folder1/site-root
What do I need to change from the original vhosts file? Is it DocumentRoot and Directory but not ServerName and ServerAlias?
From experimentation this appears to be correct:
<VirtualHost *:80>
ServerName d7.dev
ServerAlias *.d7.dev
DocumentRoot /home/drupalpro/websites/d7.dev/folder1/site-root
<Directory /home/drupalpro/websites/d7.dev/folder1/site-root>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName d7.dev
ServerAlias *.d7.dev
DocumentRoot /home/drupalpro/websites/d7.dev/folder1/site-root
<Directory /home/drupalpro/websites/d7.dev/folder1/site-root>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
SSLEngine on
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
</VirtualHost>
</IfModule>

Creating sub domain on webmin

Can anybody help me in creating subdoain through webmin. I want to create subdomain like test.xxxxx.com for this I tried with several reference site but no luck.
exp.
http://www.trickylinux.net/add-domain-virtualminwebmin.html
http://codeboxlabs.com/add-subdomain-webmin-linux/
My current httpd.conf look like:
<VirtualHost *:80>
SSLEngine off
DocumentRoot /var/www/html/******/web
DirectoryIndex index.php
<Directory "/var/www/html/*****/web">
AllowOverride All
Allow from All
</Directory>
ServerName www.******.com
ServerAlias ftp.*****.com
SSLEngine off
SSLVerifyClient optional
</VirtualHost>
Please help me to solve this issue.
I know its been a year and you must have found a path already but its for the future reference.
Just add another host:
<VirtualHost *:80>
DocumentRoot /var/www/html/******/subdomain
DirectoryIndex index.php
<Directory "/var/www/html/*****/subdomain">
AllowOverride All
Allow from All
</Directory>
ServerName www.subdomain.******.com
ServerAlias subdomain.******.com
SSLEngine off
SSLVerifyClient optional
</VirtualHost>
Of course restarting apache is needed in order to make it read the new VHost
What you need to do next is add an A record in you domain registrar (i.e, Godaddy). Record name will be your "subdomain" and it'll point to your server address:
A-----------------> # --------------------> ******.com
A-----------------> ******.com------------> ******.com
A-----------------> subdomian.******.com--> ******.com

Access Local sub domain with IP in wamp

What I need is as follows
I am able to access the sub domain in my local machine as follows test.localhost but I need test.myMachineName or test.myMachineIp to access from another computer in my own network
I have setup the sub domain in my local wamp server as follows:
IN https-vhost.conf:
<VirtualHost *:80>
#ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "c:/wamp/www"
ServerName localhost
ServerAlias localhost
#ErrorLog "logs/dummy-host.example.com-error.log"
#CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
#ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "c:/wamp/www/test"
ServerName localhost
ServerAlias test.localhost
#ErrorLog "logs/dummy-host.example.com-error.log"
#CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
And then enabled vhost in httpd.conf
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
Then added in windows host as follows
127.0.0.1 test.localhost
I don't understand your configuration. First, if you access test.localhost from another computer will not work because your website does not exist on that computer. You have to use the IP address and port forwarding in your router settings (Private IP: Computer local IP, Type: TCP, Range: 80 - 80).
In https-vhost.conf:
<VirtualHost *:80>
#ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "c:/wamp/www"
ServerName localhost
ServerAlias localhost
#ErrorLog "logs/dummy-host.example.com-error.log"
#CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
#ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "c:/wamp/www/test"
ServerName test.youripaddress
ServerAlias test.youripaddress
#ErrorLog "logs/dummy-host.example.com-error.log"
#CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
In HOST file:
127.0.0.1 localhost
youripaddress test.youripaddress
Ask me any questions.

WAMP: 'No such host is known' when trying to connect to mysql

I got this error :
Warning: PDO::__construct() [<a href='pdo.--construct'>pdo.--construct</a>]: [2002] php_network_getaddresses: getaddrinfo failed: No such host is known. (trying to connect via tcp://1:3306) in Z:\work\...
My localhost/phpmyadmin works fine but I can't access localhost or 127.0.0.1 , I get a blank page with "Forbidden : You don't have permission to access / on this server."
I have nothing else running on my port 80
I modified my httpd.conf
DocumentRoot "z:/work/"
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory "z:/work/">
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from all
</Directory>
Also added in my httpd-vhosts.conf
<Directory C:/Users/Alex/Documents/GitHub>
Order Deny,Allow
Allow from all
AllowOverride All
</Directory>
<Directory Z:/work>
Order Deny,Allow
Allow from all
AllowOverride All
</Directory>
<VirtualHost *:80>
DocumentRoot "Z:\work\mysite"
ServerName bullseye.local
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:\Users\Alex\Documents\GitHub\Myproject"
ServerName framework.local
</VirtualHost>
And my phpmyadmin.conf is as follow
Alias /phpmyadmin "c:/wamp/apps/phpmyadmin3.5.1/"
<Directory "c:/wamp/apps/phpmyadmin3.5.1/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Deny from all
Allow from all
</Directory>
The code giving the error :
$host = 'localhost';
$user = 'root';
$pass = '';
$database = 'mydatabase';
$this->db = new PDO('mysql:dbname=' . $database . ';host=' .$host . ';charset=utf8', $user, $pass);
I get the same error using mysql or msqli instead of PDO
My suggestion would be to:
Undo all your changes to httpd.conf. Your changes have removed all knowledge Apache has of the WAMP homepage i.e. localhost.
Comment out the include of the virtual hosts config and check you can again access the WAMP homepage.
Make sure that WAMP is 'OffLine', this will keep the C:\ drive and c:\wamp folder secure.
Now to your Virtual hosts definitions:
In order to keep the wamp homepage working the first entry should be as below, note the Directory block should be part of the definition of the VirtualHost and the security definition makes sure you can only access the wamp homepage from 127.0.0.1(localhost)
###must be first so the the wamp menu page loads
<VirtualHost *:80>
ServerAdmin webmaster#homemail.net
DocumentRoot "D:/wamp/www"
ServerName localhost
ServerAlias localhost
<Directory "D:/wamp/www">
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Directory>
</VirtualHost>
Each VHOST you define should contain its own security settings like this
<VirtualHost *:80>
DocumentRoot "Z:\work\mysite"
ServerName bullseye.local
ServerAlias bullseye.local
AllowOverride All
<Directory "Z:\work\mysite">
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:\Users\Alex\Documents\GitHub\Myproject"
ServerName framework.local
ServerAlias www.framework.local
<Directory "C:\Users\Alex\Documents\GitHub\Myproject">
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>
Uncomment the Include in https.conf for your vhosts definitions and try accessing you other projects again.
I assume you have made the required changes to your c:\windows\system32\drivers\etc\hosts file to include a reference to all you virtual hosts? If not the hosts file should look like this :-
127.0.0.1 localhost
127.0.0.1 framework.local
127.0.0.1 bullseye.local
My concern is this:
DocumentRoot "z:/work/"
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory "z:/work/">
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from all
</Directory>
Unfortunately I don't have time to test this before I suggest it... but if DocumentRoot is z:/work/ then Directory / is also z:/work/ and you have set that to deny all and override none. Later trying to change the permission with Directory "z:/work/" would be considered an override and therefore not be applied? I suggest you try changing the AllowOverride to all or removing the deny all from / before you spend too much time hunting down other possible solutions.