Archive

Posts Tagged ‘XAMPP’

Virtual Hosting Using apache2

October 23, 2009 2 comments

What is Virtual Hosting and where and why it is used?

Vitual Hosting is a method that servers such as web servers use to host more than one domain

name on the same computer.

Virtual hosting allows a website owner to have a site hosted on a web server that is shared with

other websites. In other words, virtual hosting services and bandwidht to more than one website.

Virtual web hosting is one of the most popular hosting options available at the moment –

probably because of cost effective because you won’t have to pay for a dedicated server to host just

your website.

Virtual web hosting is good solution for SME’s even for MNC’s also websites that aren’t constantly being visited

There are two basic methods of accomplishing virtual hosting: name-based, and IP address or ip-based.

Lets move to the Practical Session

Check are you have Apache2, mysql5, php5 in your PC or Laptop or NoteBook what ever you calls otherwise follow below steps

1. Install LAMP

2. Control Apache2

3. Control MySql

4. Virtual Hosting

5. Virtual Hosting with multiple names

1. Install LAMP – Linux Apache2 Mysql Php

I preasume you have Ubuntu Linux installed. Let’s install everything else (Apache 2, PHP5 and MySQL 5)

sudo aptitude install apache2 mysql-server php5 php5-mysql libapache2-mod-php5

Open your favourite web browser and enter http://localhost (or http://127.0.0.1)

Check if Apache 2 and PHP 5 work fine

Create a file called test.php and enter this text in it

<?php phpinfo(); ?>

Save the file and copy it to your web site folder, e.g. /var/www

Open your web browser and run

http://localhost/test.php

2. Control Apache2

To start Apache2

sudo /etc/init.d/apache2 start

To stop Apache2

sudo /etc/init.d/apache2 stop

To restart Apache2

sudo /etc/init.d/apache2 restart

After first install I always get this error:

apache2: Could not determine the server’s domain name, using 127.0.0.1 for ServerName

It is easily fixed – add ServerName localhost into apache2.conf

gksudo gedit /etc/apache2/apache2.conf

3. Control MySQL

To start MySQL

sudo /etc/init.d/mysql start

To restart MySQL

sudo /etc/init.d/mysql restart

To stop MySQL

sudo /etc/init.d/mysql stop

Creating Database using MySql

First Login into MySql Using Following Command here it will ask password then enter the root password of My Sql. MySql Password has given when it was Installing

mysql -u root -p

Create Database

Create Database virtual;

Use Database

Use virtual;

4. Virtual Hosting


(a) Allow user to web directory

(b) Create Folder and link to web directory

(c) Using Virtual Hosts

(d) Adding Virtual Hosts

(e) Apache Configuaration


localhost is the default host, but if you add virtal hosts, you may want to change it to, say, somechow

However, the address http://localhost/ by default points to /var/www. That folder is basically empty that is why you do not see much in your web browser.

To show proper web site, you need to put some web pages in that folder.

(a) allow yourselft to have access to the folder /var/www

sudo chown -R USERNAME /var/www

Now, you can copy your great web site to the folder /var/www.

Start Firefox again and type http://localhost/. Do you see you web site?

If you hate to always navigate to /var/www, you can press Control-D in Nautilus to add a new bookmark in Places menu. You can create a link to it in your home folder for easy access, alternatively.

(b) Create a folder in your desired location and link to the web direcotry

ln -s /var/www ~/WebSite

Now you can place all your web content inside the folder WebSite in your home folder and you will see your web site by going to

http://localhost/

(c) Using virtual hosts

If I put a folder called somechow inside /var/www, I can run my local web site by entering http://localhost/somechow.

However, I prefer more human-readable web addresses. For example, when I enter http://somechow, my local WordPress copy of somechow.Ws (located in /home/some/WebSites/somechow) runs in Firefox.

To use virtual hosts, you need to change hosts file and add some information for Apache.

(d) I add my virtual host address to Hosts file

sudo nano /etc/hosts

127.0.0.1 somechow

In above quote instead of 127.0.0.1 I used my desktop IP.

Then I reboot the computer or networking for changes to take effect

sudo /etc/init.d/networking restart

(e) Apache Configuration

Open the window in super user mode  uisng following command prompt

sudo nautilus

I create a copy of file default which is located in /etc/apache2/sites-available and rename it to somechow.

I created a link to this file by right-clicking and selected MakeLink option

I copy this link to /etc/apache2/sites-enabled

I change link file into somechow:

NameVirtualHost * is changed to NameVirtualHost somechow

ServerName@somechow is added under ServerAdmin

DocumentRoot /var/www/ is changed to DocumentRoot /home/some/WebSites/somechow

5. Virtual Hosting with multiple names


(a) Allow user to web directory

(b) Create Folder and link to web directory

(c) Using Virtual Hosts

(d) Adding Virtual Hosts

(e) Apache Configuaration

localhost is the default host, but if you add virtal hosts, you may want to change it to, say, somechow and somedary

However, the address http://localhost/ by default points to /var/www. That folder is basically empty that is why you do not see much in your web browser.

To show proper web site, you need to put some web pages in that folder.

(a) allow yourselft to have access to the folder /var/www

sudo chown -R USERNAME /var/www

Now, you can copy your great web site to the folder /var/www.

Start Firefox again and type http://localhost/. Do you see you web site?

If you hate to always navigate to /var/www, you can press Control-D in Nautilus to add a new bookmark in Places menu. You can create a link to it in your home folder for easy access, alternatively.

(b) Create a folder in your desired location and link to the web direcotry

ln -s /var/www ~/WebSite

Now you can place all your web content inside the folder WebSite in your home folder and you will see your web site by going to

http://localhost/

(c) Using virtual hosts

If I put a folder called somechow and somedary inside /var/www, I can run my local web site by entering http://localhost/somechow or http://localhost/somedary

However, I prefer more human-readable web addresses. For example, when I enter http://somechow and http://somedary , my local WordPress copy of somechow.Ws or somedary.ws(located in /home/some/WebSites/somechow and /home/some/WebSites/somedary ) runs in Firefox.

To use virtual hosts, you need to change hosts file and add some information for Apache.

(d) I add my virtual host address to Hosts file

sudo nano /etc/hosts

127.0.0.1 somechow

127.0.0.1 somedary

In above quote instead of 127.0.0.1 I used my desktop IP.

Then I reboot the computer or networking for changes to take effect

sudo /etc/init.d/networking restart

(e) Apache Configuration

(i) For somechow

Open the window in super user mode  uisng following command prompt

sudo nautilus

I create a copy of file default which is located in /etc/apache2/sites-available and rename it to somechow.

I created a link to this file by right-clicking the somechow and selected MakeLink option

I copy this link to /etc/apache2/sites-enabled

I change link file into somechow:

NameVirtualHost * is changed to NameVirtualHost somechow

ServerName@somechow is added under ServerAdmin

DocumentRoot /var/www/ is changed to DocumentRoot /home/some/WebSites/somechow

(ii) For somedary

Open the window in super user mode  uisng following command prompt

sudo nautilus

I create a copy of file default which is located in /etc/apache2/sites-available and rename it to somedary.

I created a link to this file by right-clicking the somechow and selected MakeLink option

I copy this link to /etc/apache2/sites-enabled

I change link file into somedary:

NameVirtualHost * is changed to NameVirtualHost somedary

ServerName@somedary is added under ServerAdmin

DocumentRoot /var/www/ is changed to DocumentRoot /home/some/WebSites/somedary






Advertisements

Setup easy web development environment (XAMPP)

May 7, 2009 Leave a comment

This is a how-to for setting up a web development environment easily. This guide will install the XAMPP lampp stack into /opt, setup an easy way to start it up and shut it down, and link a folder in your home directory to the webserver.

WARNING
This guide is aimed at a development environment only and should not be used as a public webserver. To setup a public webserver follow the directions on the Ubuntu wiki https://help.ubuntu.com/community/ApacheMySQLPHP

As this is Ubuntu, all the major parts of a typical web server are included (in the main repo, or on the Ubuntu Server CD) and this is a great way to setup a server. The ubuntu developers have prepared a great web server and have made the process as seemless as possible.

But what if even the official way is still to complicated? What if you just want a quick web server for development?

Fortunately there is the XAMPP project: http://www.apachefriends.org/en/xampp.html. The XAMPP project bundles Apache, PHP4 & 5, Perl, mySQL, and a bunch of other utilities/applications into an simple package for Mac OSX, Windows, Solaris, and Linux. Obviously this HOWTO only deals with the linux version.

For those of you with already existing Apache/mySQL/php installations it installs everything into /opt so it doesn’t conflict with any other installation, and it is completely setup and ready to run.

Install XAMPP

Two easy steps:

  1. Download the most recent version of XAMPP: (at time of writing 1.5.3a)
    http://prdownloads.sourceforge.net/x…ar.gz?download
    (Source URL: http://www.apachefriends.org/en/xampp-linux.html#374)
  2. Extract the archive to /opt using sudo: (make sure you are in the directory that you downloaded the archive to)
    Code:
    sudo tar xvfz xampp-linux-1.5.3a.tar.gz -C /opt

Start XAMPP

To start it up, open a terminal and type this:

Code:
sudo /opt/lampp/lampp start

Stop XAMPP

To stop it, open a terminal and type this:

Code:
sudo /opt/lampp/lampp stop

Additional XAMPP commands

To see additional commands, open a terminal and type this:

Code:
sudo /opt/lampp/lampp

Sweet XAMPP Control Panel

To use the sweet gtk/python control panel:

Run in a terminal:

Code:
gedit ~/.local/share/applications/xampp-control-panel.desktop

Paste the following into the open file and save and exit.

Code:
[Desktop Entry]
Comment=Start/Stop XAMPP
Name=XAMPP Control Panel
Exec=gksudo "python /opt/lampp/share/xampp-control-panel/xampp-control-panel.py"
Icon[en_CA]=/usr/share/icons/Tango/scalable/devices/network-wired.svg
Encoding=UTF-8
Terminal=false
Name[en_CA]=XAMPP Control Panel
Comment[en_CA]=Start/Stop XAMPP
Type=Application
Icon=/usr/share/icons/Tango/scalable/devices/network-wired.svg

“XAMPP Control Panel” will show up in your applications menu under Internet. Use the Alacarte Menu Editor to move it around.

Test to see if XAMPP is running

Once XAMPP is up and running open firefox and go to: http://localhost/

You should see the XAMPP test page:

Location of files and uploading

XAMPP by default uses /opt/lampp/htdocs as the root web directory. The easiest way to start working on files is to link a folder in your home directory into this directory.
My user name is peter so I have /home/peter/public_html linked to /opt/lampp/htdocs/peter. So if I navigate to http://localhost/peter/ I get a listing of all the files/folders in that directory. (As long is there isn’t a index.php/html/etc file)
To set this up, run in a terminal:

  1. Make public_html directory in home directory:
    Code:
    mkdir ~/public_html
  2. Link to /opt/lampp/htdocs
    Code:
    sudo ln -s ~/public_html /opt/lampp/htdocs/$USER

Now any files and folders you place in ~/public_html will be published to your personal webserver.

Bookmark http://localhost/username to make this easy to access.

WARNING – SECURITY
http://www.apachefriends.org/en/xampp-linux.html#381
Open holes:

  1. The MySQL administrator (root) has no password.
  2. The MySQL daemon is accessible via network.
  3. ProFTPD uses the password “lampp” for user “nobody”.
  4. PhpMyAdmin is accessible via network.
  5. Examples are accessible via network.
  6. MySQL and Apache running under the same user (nobody).

This doesn’t leave your whole system wide open, but someone could hack your XAMPP installation, so be wary.
To fix most of the security weaknesses open a terminal and run:

Code:
sudo /opt/lampp/lampp security
%d bloggers like this: