To create name based virtual host in unix/wamp/xampp follow the following steps
1) Open httpd.conf (The configuration file of your apache)
2) Add following at the end of the httpd.conf file (assume 0.20 as my local IP address)
NameVirtualHost *
<virtualhost>
ServerName 192.168.0.20
DocumentRoot /www/ or c:/wamp/www
</virtualhost>
<virtualhost>
ServerName newsite.com
DocumentRoot /www/new_site or c:/wamp/www/new_site
</virtualhost>
3)Add following line in host file (See bellow to find host file) or point newsite.com to your IP by DNS server.
192.168.0.20 newsite.com
4) Restart apache/DNS and you are done .....
I spend all my day doing this. It is not so hard but I spend all my day. :( To know why continue reading..
The situation is like I have wamp server running and I am running my project like 192.168.0.20/myprojectname or localhost/myprojectname
This is my development area where I develop web apps and test it. After this the final code is uploaded to the live server.
Normally project contains .htaccess file and RewriteRule
So I face problem like, I have to change the rewrite base each time I upload the .htaccess to the live server.
like from RewriteBase /myprojectname
to RewriteBase /
I can do php codeing that will load setting depend on the server by checking the hostname or serverip but you can not do that in .htaccess
Thats why I made a descision to make a virtual host. Now my RewriteBase will be / for both live server and my development area.
So i made a virtual host. like bellow
<virtualhost>
ServerName newsite.com
DocumentRoot /www/new_site
</virtualhost>
you need to point this newsite.com to your ip. You can do it in DNS if you have or you can add this in host file
for unix it is in the /etc/hosts
for win 2k and xp it is in c:\WINNT\system32\drivers\etc (for win2k), or c:\WINDOWS\system32\drivers\etc (for winxp)
add following line in host file
192.168.0.20 newsite.com
Note: If you you are not using DNS and want your site to be accessible from other system add above entry in host file of all other systems. Then those systems can open newsite.com directly.
this worked for me .... :)
but my other applications like phpmyadmin and joomla are in documentroot of apache.
I was unable to access those ...
All request were going to the virtual host ..
<span style="font-weight: bold;">So the solution for this is when u r adding virtual host to an existing apache(default setting) you have to create virtual host for the default system.</span>
So if you want to add virtual (The very first virtual host to the apache). You have to create two virtual hosts. One will point to your default apache and the another that will point to your new_site
So you have to add two virtual hosts as bellow
<virtualhost>
ServerName 192.168.0.20
DocumentRoot /www
</virtualhost>
<virtualhost>
ServerName newsite.com
DocumentRoot /www/new_site
</virtualhost>
So this will work cool .... ;)
Do not forget to crate the first virtual host that will point to default doc root(if you are using it ....)
read this http://httpd.apache.org/docs/1.3/vhosts/name-based.html for more information
Feel free to ask me if you have any questions
mail me on devendra( dot )in( at )gmail( dot )com
Thanks
:Devendra Jadhav
You will get information about PHP, Drupal, HTML, JavaScript, CSS, Linux, Shell Script. Lets discuss and share ideas.
Monday, January 19, 2009
Tuesday, November 25, 2008
Finding and deleting folders from filesystem. Like .svn folders from svn working directory
The following command will find all svn folders from within your current working directory and delete them all. In short this will make working directory as exported project.
find . -name .svn -exec rm -rf {} \;
Explanation:
The find command will start searching from '.'(Current directory)
Will find the file/folder whose name is '.svn'
The -exec will execute 'rm -rf' command on the result of find command. i.e. the {} will return all files/folders returned by find command.
And the last '\' is important it is escape character.
So you are done....
Be aware you are using rm -rf command..
(I have tested it on Ubuntu 6.06)
find . -name .svn -exec rm -rf {} \;
Explanation:
The find command will start searching from '.'(Current directory)
Will find the file/folder whose name is '.svn'
The -exec will execute 'rm -rf' command on the result of find command. i.e. the {} will return all files/folders returned by find command.
And the last '\' is important it is escape character.
So you are done....
Be aware you are using rm -rf command..
(I have tested it on Ubuntu 6.06)
Saturday, September 6, 2008
copy content of one table to another table- MySQL
To copy all content of one table to another table use following query.
consider you have two tables table_source & table_destination.
To copy content of table_source to table_destination.
INSERT INTO table_destination SELECT * FROM table_source;
see the bellow example
mysql> create table zdevendra(id integer(10) auto_increment primary key, name varchar(50), salery int(10));
Query OK, 0 rows affected (0.01 sec)
mysql> desc zdevendra;
+--------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+----------------+
| id | int(10) | NO | PRI | NULL | auto_increment |
| name | varchar(50) | YES | | NULL | |
| salery | int(10) | YES | | NULL | |
+--------+-------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
mysql> insert into zdevendra (name, salery) values('first name','1000');
Query OK, 1 row affected (0.00 sec)
mysql> insert into zdevendra (name, salery) values('second name','2000');
Query OK, 1 row affected (0.00 sec)
mysql> insert into zdevendra (name, salery) values('third name','3000');
Query OK, 1 row affected (0.00 sec)
mysql> insert into zdevendra (name, salery) values('forth name','4000');
Query OK, 1 row affected (0.00 sec)
mysql> insert into zdevendra (name, salery) values('fifth name','5000');
Query OK, 1 row affected (0.00 sec)
mysql> select * from zdevendra;
+----+-------------+--------+
| id | name | salery |
+----+-------------+--------+
| 1 | first name | 1000 |
| 2 | second name | 2000 |
| 3 | third name | 3000 |
| 4 | forth name | 4000 |
| 5 | fifth name | 5000 |
+----+-------------+--------+
5 rows in set (0.00 sec)
mysql> create table zzdevendra(id integer(10) auto_increment primary key, name varchar(50), salery int(10));
Query OK, 0 rows affected (0.01 sec)
mysql> select * from zzdevendra;
Empty set (0.00 sec)
mysql> insert into zzdevendra select * from zdevendra;
Query OK, 5 rows affected (0.01 sec)
Records: 5 Duplicates: 0 Warnings: 0
mysql> select * from zzdevendra;
+----+-------------+--------+
| id | name | salery |
+----+-------------+--------+
| 1 | first name | 1000 |
| 2 | second name | 2000 |
| 3 | third name | 3000 |
| 4 | forth name | 4000 |
| 5 | fifth name | 5000 |
+----+-------------+--------+
5 rows in set (0.00 sec)
mysql>
You are done!
:Devendra
consider you have two tables table_source & table_destination.
To copy content of table_source to table_destination.
INSERT INTO table_destination SELECT * FROM table_source;
see the bellow example
mysql> create table zdevendra(id integer(10) auto_increment primary key, name varchar(50), salery int(10));
Query OK, 0 rows affected (0.01 sec)
mysql> desc zdevendra;
+--------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+----------------+
| id | int(10) | NO | PRI | NULL | auto_increment |
| name | varchar(50) | YES | | NULL | |
| salery | int(10) | YES | | NULL | |
+--------+-------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
mysql> insert into zdevendra (name, salery) values('first name','1000');
Query OK, 1 row affected (0.00 sec)
mysql> insert into zdevendra (name, salery) values('second name','2000');
Query OK, 1 row affected (0.00 sec)
mysql> insert into zdevendra (name, salery) values('third name','3000');
Query OK, 1 row affected (0.00 sec)
mysql> insert into zdevendra (name, salery) values('forth name','4000');
Query OK, 1 row affected (0.00 sec)
mysql> insert into zdevendra (name, salery) values('fifth name','5000');
Query OK, 1 row affected (0.00 sec)
mysql> select * from zdevendra;
+----+-------------+--------+
| id | name | salery |
+----+-------------+--------+
| 1 | first name | 1000 |
| 2 | second name | 2000 |
| 3 | third name | 3000 |
| 4 | forth name | 4000 |
| 5 | fifth name | 5000 |
+----+-------------+--------+
5 rows in set (0.00 sec)
mysql> create table zzdevendra(id integer(10) auto_increment primary key, name varchar(50), salery int(10));
Query OK, 0 rows affected (0.01 sec)
mysql> select * from zzdevendra;
Empty set (0.00 sec)
mysql> insert into zzdevendra select * from zdevendra;
Query OK, 5 rows affected (0.01 sec)
Records: 5 Duplicates: 0 Warnings: 0
mysql> select * from zzdevendra;
+----+-------------+--------+
| id | name | salery |
+----+-------------+--------+
| 1 | first name | 1000 |
| 2 | second name | 2000 |
| 3 | third name | 3000 |
| 4 | forth name | 4000 |
| 5 | fifth name | 5000 |
+----+-------------+--------+
5 rows in set (0.00 sec)
mysql>
You are done!
:Devendra
Thursday, July 24, 2008
Get Version of Internet Explorer using Java Script
This is the code to get the version of Internet Explorer used by the user. If you use navigator.appVersion you will get value 4 for both ie6 & ie7.
<script type="text/javascript" language="javascript">
//Arguments:
//This function is same as explode function in php.
//It takes input string as a string to be exploded.
//separators as a string separator.
//includeEmpties count of array you want as a return (Not required in our case)
//Return:
//It returns the array of strings(Separated by 'separators')
function explode(inputstring, separators, includeEmpties) {
inputstring = new String(inputstring);
separators = new String(separators);
if(separators == "undefined") {
separators = " :;";
}
fixedExplode = new Array(1);
currentElement = "";
count = 0;
for(x=0; x < inputstring.length; x++) {
char = inputstring.charAt(x);
if(separators.indexOf(char) != -1) {
if ( ( (includeEmpties <= 0) || (includeEmpties == false)) && (currentElement == "")) { }
else {
fixedExplode[count] = currentElement;
count++;
currentElement = ""; } }
else { currentElement += char; }
}
if (( ! (includeEmpties <= 0) && (includeEmpties != false)) || (currentElement != "")) {
fixedExplode[count] = currentElement; }
return fixedExplode;
}
// explode function ends here
//Actual logic starts here ..
full_string = navigator.userAgent;
string_array = explode(full_string,";",10);
version_number = explode(string_array[1]," ",2);
main_version = explode(version_number[2],".",3);
if(main_version[0] == 6){
alert("this is ie6");
}else{
if(main_version[0] == 7){
alert("this is ie7");
}else{
alert("this is other browser");
}
}
</script>
<script type="text/javascript" language="javascript">
//Arguments:
//This function is same as explode function in php.
//It takes input string as a string to be exploded.
//separators as a string separator.
//includeEmpties count of array you want as a return (Not required in our case)
//Return:
//It returns the array of strings(Separated by 'separators')
function explode(inputstring, separators, includeEmpties) {
inputstring = new String(inputstring);
separators = new String(separators);
if(separators == "undefined") {
separators = " :;";
}
fixedExplode = new Array(1);
currentElement = "";
count = 0;
for(x=0; x < inputstring.length; x++) {
char = inputstring.charAt(x);
if(separators.indexOf(char) != -1) {
if ( ( (includeEmpties <= 0) || (includeEmpties == false)) && (currentElement == "")) { }
else {
fixedExplode[count] = currentElement;
count++;
currentElement = ""; } }
else { currentElement += char; }
}
if (( ! (includeEmpties <= 0) && (includeEmpties != false)) || (currentElement != "")) {
fixedExplode[count] = currentElement; }
return fixedExplode;
}
// explode function ends here
//Actual logic starts here ..
full_string = navigator.userAgent;
string_array = explode(full_string,";",10);
version_number = explode(string_array[1]," ",2);
main_version = explode(version_number[2],".",3);
if(main_version[0] == 6){
alert("this is ie6");
}else{
if(main_version[0] == 7){
alert("this is ie7");
}else{
alert("this is other browser");
}
}
</script>
Subscribe to:
Posts (Atom)