Showing posts with label Apache. Show all posts
Showing posts with label Apache. Show all posts

Friday, October 5, 2012

How to create Virtual Hosts in Ubuntu

Virtual Hosting is a method for hosting multiple sites/domains in a single server. It helps to reduce the cost and can share the memory and processor cycle. In local host also we can create Virtual host and we can call original domain name(production/live domain) from our development environment(localhost). Here I am providing the steps for creating Virtual host in Linux/Ubuntu workstation.


i.  Assume your code resides at /var/www/yoursite

ii.  You can access your site using http://localhost/yoursite.

iii.  Edit vhosts file in sites-enabled. sudo gedit /etc/apache2/sites-enabled/vhosts.conf.

iv. Add below code in vhosts file

<VirtualHost *:80>
ServerName local.yoursite.com
ServerAlias www.local.yoursite.com
DocumentRoot /var/www/yoursite
</VirtualHost>
v. Open the file /etc/hosts in your editor.
vi. Add below lines of code.
127.0.0.1   local.yoursite.com
vii. Restart your apache server.
sudo /etc/init.d/apache2 restart
viii. Access http://local.yoursite.com to view your site in direct domain.
 

Friday, July 13, 2012

Redirect all users to access the site with 'www' prefix using htaccess file

We can redirect the site url to "www" prefix, whether the user is accessing the site without "www" prefix by adding rewrite url in .htaccess file in root folder.

add following lines in .htaccess file to add www prefix.

 RewriteEngine on

 RewriteCond %{HTTP_HOST} ^yoursitename\.com$ [NC]

 RewriteRule ^(.*)$ http://www.yoursitename.com/$1 [L,R=301] 


Similarly we can remove "www" prefix from the url and redirect to without "www" by adding following lines in .htaccess file


 RewriteEngine on

 RewriteCond %{HTTP_HOST} ^www\.yoursitename\.com$ [NC]
 RewriteRule ^(.*)$ http://yoursitename
.com/$1 [L,R=301] 


Sunday, February 20, 2011

Installing Apache, MySQL and PHP in Linux-Ubuntu

Apache is the most commonly used web server. It is a free open source web server. PHP is an open source server scripting language. It has a lot of advantages. MySQL is also an open source database used for small and medium data storage. It can also used for large data storage also.

We can install apache, PHP and MySQL in two ways. 1. Download source code from their site and install. 2 the easiest way install it from synaptic package manager. If you use this method apt-get automatically manage all dependencies. So I explain the second method here.

1. Open the Terminal from Applications -> Accessories -> Terminal

2. Install apache2 copy paste command to terminal
sudo apt-get install apache2

3. Install PHP5
sudo apt-get install php5 libapache2-mod-php5

4. Restart apache
sudo /etc/init.d/apache2 restart

Now the PHP was installed. To test it create a php page in /var/www/ - the webroot and run it
Example sudo gedit /var/www/hello.php
write a basic php code in it

to run this script type http://localhost/hello.php in your browser and you can see "Hello World" in it.

5. Install mySQL
sudo apt-get install mysql-client mysql-server mysql-query-browser mysql-admin mysql-navigator php5-mysql php5-gd

6. Restart apache
sudo /etc/init.d/apache2 restart 

7. If you need phpmyadmin follow this step. If you like to use MySQL GUI then skip this step
sudo apt-get install phpmyadmin 

Restart apache
sudo /etc/init.d/apache2 restart 

Add following lines in httpd.conf
# Enable PHPMyAdmin
Include /etc/phpmyadmin/apache.conf

To access httpd.conf copy paste following line to terminal

sudo gedit /etc/apache2/httpd.conf

Restart apache
8. If you need to access your url as http://localhost/~username, enable userdir module in apache2. enable mod_rewrite to allow clean url
cd /etc/apache2/mods-enabled
sudo ln -s ../mods-available/userdir.load
sudo ln -s ../mods-available/userdir.conf
sudo ln -s ../mods-available/rewrite.load
sudo /etc/init.d/apache2 reload

9. Create folder /home/<username>/public_html -- > this is the folder which we are going to use as the document root for local development. So you will be accessing your local websites as http://localhost/~username/sitename

10. Edit /etc/apache2/mods-available/userdir.conf and change the AllowOverride line to just read AllowOverride All
Now you can use public_html as user document root

Enjoy scripting

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Maintained by Web Themes