Clean URLs with Apache 2 on Ubuntu

Tags

, , , ,

There are two methods for setting up Drupal 5.x/6.x with Apache on Ubuntu. The first (preferred) method edits the virtual host configuration, which is the default setup on Ubuntu (even for a single-site web server). The second edits the main apache2.conf, which is typical for an older setup.

Step 1 – Method A: “Virtual Host” Setup
First, from the Linux command line, enable the rewrite module for apache with this command:

sudo a2enmod rewrite

You can check to see if this worked by running:

apache2ctl -M

and seeing if it is on the list.

Next, use an editor (such as nano) to edit the appropriate Apache configuration file for your Drupal site in the /etc/apache2/sites-available/ directory. For a single site, the file is /etc/apache2/sites-available/default; if you have multiple sites, the file names should reflect the names of the sites to which they refer. Thus, to edit the default site configuration, use

sudo nano /etc/apache2/sites-available/default

Look for the Directory section referring to the folder where your Drupal site lives (in /etc/apache2/sites-available/default, this is typically ), and change the line:

AllowOverride None to AllowOverride All

(This directive permits an .htaccess file, such as Drupal’s, to be used to override Apache’s default settings, and is necessary to allow the URL rewriting to work. See https://help.ubuntu.com/community/EnablingUseOfApacheHtaccessFiles for more information).

Save this file and then reload Apache as follows:

sudo /etc/init.d/apache2 reload

Subdomain Setup

Instead of creating multiple virtual host files, you can create one virtual host file that uses a wildcard in the ServerAlias. Both a simple multi-site Drupal setup and multiple Drupal versions can run this way, if the different subdomains are defined for each site in settings.php.

Consider the following and modify your configuration file to fit your needs.

http://myproject.dr5.example/

http://myproject.dr6.example/

http://myproject2.dr6.example/

Here is a partial listing of a virtual host configuration file that would support the last two lines in the above example. Note this is not intended to be a COMPLETE configuration file, but rather provide guidance for your development setup.

DocumentRoot "/www/Dr6"
ServerName example
ServerAlias *.dr6.example

AllowOverride All


Edit & save your config file to suit your development needs. Assuming the site is already enabled, then reload Apache.

Step 1 – Method B: apache2.conf
In Apache version 2, httpd.conf has been deprecated and the new file is located at:

/etc/apache2/apache2.conf.

Thus, it’s no longer necessary to do the following in httpd.conf to enable the rewrite module (mod_rewrite):

LoadModule rewrite_module modules/mod_rewrite.so
AddModule mod_rewrite.c

Simply run the following from the Linux command line:
sudo a2enmod rewrite

To disable the module you can run:
sudo a2dismod rewrite
(Note that this would cause clean URLs to break.)

Once mod_rewrite is enabled, open apache2.conf in a text editor. Note that it will probably be read-only, so you will need sudo privileges to edit it. Use a command such as:
sudo nano /etc/apache2/apache2.conf

Find where the sections are in your apache2.conf and add another one for your Drupal site similar to this:

AllowOverride All


After you edit apache2.conf as listed above, you need to restart the server by:
sudo /etc/init.d/apache2 reload

Step 1 – Method C: Add Rewrite Rules Directly to Virtual Host or apache2.conf
If you do not wish to allow .htaccess overrides, you can add the rewrite rules directly to a virtual host file or apache2.conf. The following should work:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

This can provide slightly faster server performance since Apache will not look in every directory for an .htaccess file.

Note that, for proper security, you will need to add in the rules from the Drupal files directory’s .htaccess file as well.

Debugging Rewrite Issues
If you are having problems with getting your rewrite to work you can set Apache to log rewrite errors. To do that add this to the end of /etc/apache2/apache2.conf:

RewriteLog “/var/log/apache2/rewrite.log”
RewriteLogLevel 3
Level 0 does no logging. Level 9 logs everything. Choose the level necessary for resolving your issue.

Security Warning: Make sure to either remove or comment the logging code out when finished, or else put the log file in a directory that can’t be read by normal users (such as /var/log/apache2). If this is not done, it can result in a security breach. Also, note that rewrite logging adds somewhat to server load, and can easily generate large amounts of output not needed on a production server.

Step 2: Enable Clean URLs
Now go to http://yoursite.com/?q=admin/settings/clean-urls, and run the test for “Clean URLs” (In Drupal 4.6 – 5.x this is buried in the paragraph explaining what “clean urls” are).

Then, select the radio button to set clean URLs to “enabled” and submit the form. You should now be able to access your site using URLs without the query string in them.

Note: In Drupal 7.2, if still you are having issues with Clean URLs, and your site is in maintenance mode, turn off maintenance mode while enabling clean URLs.

Originally posted in http://drupal.org/node/134439

Tips and Tricks for Ubuntu after Installation

Tags

,

Ubuntu is a free operating system or a Linux distribution (“distro”) which receives the highest hits on DistroWatch and has been selected by readers of DesktopLinux as the most popular distro. It also gets the highest number of votes in Poll Results on Gizmo’s Freeware Forum.

If you have the Ubuntu system which comes with the default Gnome desktop environment installed in your PC, you might find these tips and tricks useful for working with the system.

Looking for a desktop interface with a start menu that looks closer to the Windows system? Then give Linux Mint a try and check out Tips and Tricks for Linux Mint after installation.

Note: The steps described in this article work with Ubuntu 11.04 (logged into Ubuntu Classic session), Ubuntu 10.10 and Ubuntu 10.04.

Source…
http://www.techsupportalert.com/content/ubuntu-tips-and-tricks.htm

Install Multiple Sites Under Drupal

Tags

I googled many times to get the correct procedure to install multiple sites under Drupal and after so many attempts I successfully got a exact procedure to do this..

Follow the steps as it is mentioned here..

1. Open the ‘sites‘ folder under your drupal’s main installation folder..
2. Create a new folder and give a site name to it, like site2.localhost
3. Under site2.localhost folder create another folder called files.
4. Now from “./sites/defaults/” folder copy the “default.settings.php” file to the site2.localhost folder and rename it to “settings.php” .
5. Now open your Terminal and type the following commands…

sudo mysqladmin -u root -p create drusite2

Give your sudo password.. your new database with name “drusite2” will be created under phpmydmin.

6. Now you have to create a symbolic link.. Open terminal and change your directory to ./sites under main drupal folder. Type the following in Your terminal.

cd ~/workspace/drupal6.18/sites/

Here my main drupal directory is under the workspace folder home directory..Please change the the directory names because the path should be correct as it is in your System.. Now type the following Command to create symbolic link.

ln -s ~/site2.localhost.6

Create an entry in the hosts file

To make it possible to run a number of local Drupal sites simultaneously, each site must have its own hostname. To add a new hostname, open a terminal window and run the following command to open the hosts file in a text editor:

sudo gedit /etc/hosts

Since we’re setting up drupal6.18, we’ll add the hostname drupal6.18 to the hosts file and have it point at the local web server on the IP address 127.0.0.1.
Save the file and exit the text editor when you have added the hostname.

7. Next you have to create virtual site for your new site . Type the following command in your terminal…

cd /etc/apache2/sites-available
sudo gedit site2.localhost

A gedit texeditor will open with the site2.localhost filename. Enter the following virtual host definition and save the file:

ServerAdmin webmaster@localhost
ServerName site2.localhost

DocumentRoot /home//Drupal/drupal-6.18

Options FollowSymLinks
AllowOverride All


The ServerName must match the hostname you added to the hosts file, and the DocumentRoot must match the name of the folder where Drupal is installed. Replace with the username you use to log in to the local machine (on this machine it got replaced by akinza).
When you have saved the file, you can run the following commands in a terminal window to enable the new virtual host and reload the Apache configuration:

sudo a2ensite site2.localhost
sudo /etc/init.d/apache2 reload

8. Now open your browser and type the site name(http://site2.localhost) folow the installation procedure…

And Enjoy and install multiple site using only one drupal installer.

Installation of Drupal in Ubuntu Localhost

Install Apache, MySQL, and PHP

Open a terminal window (Applications → Accessories → Terminal) and run the following command to install Apache, MySQL and PHP:

sudo apt-get install lamp-server^

When sudo asks for a password, simply enter the password you used to log in to the system.
Apt-get displays a list of the packages which are about to be installed. Answer yes or press enter to start the installation. Apt-get will then download and install the required packages.

Install additional software

Open a terminal window and run the following command to install the rest of the packages required to run Drupal and NetBeans:
(On Ubuntu 10.04 you need to enable the Partner repository to install the Java Development Kit: Go to System → Administration → Software sources. Click the Other software tab and enable the lucid partner repository. Click Close and then Reload to rebuild the list of available software.)

sudo apt-get install php5-cli php5-gd php5-xdebug sun-java6-jdk

This command installs the following packages:

php5-cli The PHP command-line interpreter
php5-gd GD support for PHP
php5-xdebug Xdebug support for PHP
sun-java6-jdk The Sun Java™ Development Kit

PHP

Open a terminal window and run the following command to edit the main PHP configuration file (this is not necessary on 10.04):

sudo vi /etc/php5/apache2/php.ini

Configure Apache

In order to use clean URLs in Drupal, you must enable the Apache rewrite module. Open a terminal window and run the following command:

sudo a2enmod rewrite

When the module has been enabled, you must restart Apache:

sudo /etc/init.d/apache2 restart

Apache will complain that it can’t determine the server’s fully qualified hostname. You can safely ignore this error message.
If you want to get rid of the error message, create a file called servername in the /etc/apache2/conf.d directory. Put the following line in the file:

ServerName drupal

Replace drupal with the hostname you chose for you machine during the Ubuntu installation process.

Configure MySQL

Next you must create a user in the MySQL database. This user will be used to access all your local Drupal databases. Open a terminal window and start the MySQL client (you will be asked to enter the password you chose when you installed MySQL):

mysql -u root -p

The command tells the MySQL client that you want to log in as the root user and that you want to be prompted for a password.
When you have logged in to the client, you can run the following commands to create a local drupal user and exit the MySQL client:

CREATE USER drupal@localhost IDENTIFIED BY ‘drupal’;
FLUSH PRIVILEGES;
EXIT

You can run the following command to make sure that the new user can log in:

mysql -udrupal -pdrupal

The user doesn’t have access to any databases yet. We will grant it database privileges when we set up the local Drupal sites.

Install Drupal

Before you can begin installing local Drupal sites you must create a local folder for them. Open a terminal window and run the following command to create a sub-directory in your home directory:

mkdir Drupal

We will use this as the base directory for all local Drupal sites.

From an official release Installing a local copy of an official Drupal release requires the following actions:

Download and unpack a stable release of Drupal
Create an entry in the hosts file
Create an Apache virtual host
Create a NetBeans project
Create a MySQL database
Run the Drupal installer
In the following sections each of these steps will be described in detail.

Download and unpack Drupal
Go to Drupal.org and download the latest version of Drupal. At the time of writing this is version 6.18. Save the file in the Drupal sub-directory in your home folder.

Next, open a terminal window and type the following commands to change to the Drupal sub-directory and unpack the downloaded file:

cd Drupal/
tar xzf drupal-6.18.tar.gz
rm drupal-6.18.tar.gz

You now have a copy of the latest version of Drupal in your Drupal folder.

Create an entry in the hosts file

To make it possible to run a number of local Drupal sites simultaneously, each site must have its own hostname. To add a new hostname, open a terminal window and run the following command to open the hosts file in a text editor:

sudo gedit /etc/hosts

Since we’re setting up Drupal 6.18, we’ll add the hostname drupal618to the hosts file and have it point at the local web server on the IP address 127.0.0.1.

Save the file and exit the text editor when you have added the hostname.

Create a Apache virtual host
Next we have to create a new Apache virtual host to handle requests to http://drupal618/. Open a terminal window and run the following commands to create a new virtual host definition:

cd /etc/apache2/sites-available
sudo gedit drupal618

It is a good idea to use the hostname as the name of the virtual host file. This makes it easier to manage a lot of virtual hosts.
Enter the following virtual host definition and save the file:

ServerAdmin webmaster@localhost
ServerName drupal618

DocumentRoot /home//Drupal/drupal-6.18

Options FollowSymLinks
AllowOverride All


The ServerName must match the hostname you added to the hosts file, and the DocumentRoot must match the name of the folder where Drupal is installed. Replace with the username you use to log in to the local machine (on this machine it got replaced by wulff).
When you have saved the file, you can run the following commands in a terminal window to enable the new virtual host and reload the Apache configuration:

sudo a2ensite drupal618
sudo /etc/init.d/apache2 reload

You can now access the Drupal site at http://drupal618/.

Follow

Get every new post delivered to your Inbox.