Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Many of the Drupal distributions I've seen are made for earlier versions of Ubuntu: drubuntu only works in 10.10; the Acquia .debs are for <10.x, and I've been told the versions in the repos are out-of-date. What's the easiest way to set up a local testing server for Drupal?

share|improve this question
    
Downloading latest version and setting up a virtual host with drupal inside your home directory. –  sagarchalise Apr 21 '11 at 4:36

4 Answers 4

up vote 16 down vote accepted

Drupal is a free and open-source content-management system, and it’s surprisingly flexible. You can use it for everything from a small blog to a major business or government site. It’s a mildly tricky setup, since you basically have to build a LAMP server from scratch, but here’s a step-by-step guide on how to do it.

First, install Ubuntu into your machine of choice. Once Ubuntu is installed and updated, you will need to install and configure four pieces of software to create a LAMP server to support Drupal: the Apache web server, the MySQL database server, PHP , and the MySQL module for PHP.

Begin with the Apache web server. To install Apache, open up a Terminal window (Applications, Accessories, Terminal), and type the following command (note that all Terminal commands are shown here in bold, and that all Terminal commands are case-sensitive):

sudo apt-get install apache2

Follow the prompts to install Apache. Once the installation is finished, you can test that Apache is working by opening up Firefox and navigating to http://localhost. If you see the “it works!” web page, you have Apache up and running.

Next, you’ll need to install MySQL. Return to the Terminal and type this command:

sudo apt-get install mysql-server-5.1

During the installation you be will asked to provide a root password for MySQL. Be sure to pick a strong password (a combination of lowercase, punctuation, and uppercase letters), since the root user has full access to all tables on all databases. For obvious reasons, you’ll want to remember this password, not least because we need it again in the following steps. MySQL is a big package, and depending on your connection and computer speed, it might take a while to install.

Next, install PHP version 5:

sudo apt-get install php5

Then install the MySQL module for PHP:

sudo apt-get install php5-mysql

Install gd module for PHP:

sudo apt-get install php5-gd

Finally, download the Drupal software to your Downloads folder. You can obtain it from this address:

http://drupal.org/project/drupal

Now that we’ve got our software installed and downloaded, we’ll need to configure it.

First, you’ll probably need to add a line to your /etc/apache2/apache2.conf file. I’ve read differing things about this, but I have found in my own testing that Drupal would not function properly without it, since Apache did not properly interpret the PHP pages otherwise. To edit apache2.conf, use the following command:

gksudo gedit /etc/apache2/apache2.conf

(Note the use of gksudo. Because gedit is a graphical tool we use gksudo. Using sudo can damage permissions, making it difficult to login. )

(Note that it’s a good idea to back up any system configuration file before editing it. You can do so quickly by using sudo cp /etc/apache2/apache2.conf ~/Desktop to save a copy to your Desktop. You can of course use vi or emacs or the editor of your choice, but most new users seem to prefer gedit’s GUI.)

Once you are in gedit, add the following line to the end of the file:

AddType application/x-httpd-php.html

Save the file and exit gedit. Restart Apache with this command, so it re-reads its configuration file:

sudo /etc/init.d/apache2 restart

Now we’ll need to prepare MySQL for use with Drupal. First, you’ll need to run MySQL’s install script:

sudo mysql_install_db

And then this command, to properly secure MySQL. Follow the default prompts to remove the testing database in MySQL:

sudo mysql_secure_installation

Once this is completed, log into the MySQL command-line client:

mysql -u root –p

Enter your MySQL root user password from above, and you’ll find yourself at the MySQL> local client prompt. First, create a database for Drupal to use:

CREATE DATABASE drupal;

(Note that all commands entered in the MySQL local client must end with a semicolon to denote the end of the statement.)

Once the database is created, you’ll need to create a database user for Drupal to use. While still in the MySQL command line client, type this:

CREATE USER drupaluser;

Then create a password for your new user (note that your password will actually go within the quotation marks, and is case-sensitive):

SET PASSWORD FOR drupaluser = PASSWORD(“password”);

Now that you’ve got your Drupal database and your Drupal database user, you’ll need to grant the user all permissions on the database (again, the password goes within the quotation marks, and is case sensitive):

GRANT ALL PRIVILEGES ON drupal.* TO drupaluser@localhost IDENTIFIED BY ‘password’;

(Make sure to append “@localhost” to drupaluser; otherwise you’ll get a database error when you try to start Drupal for the first time.)

Next, make a directory for Drupal with this command:

sudo mkdir /var/www/drupal

Next, you’ll need to unpack the Drupal files and move them to the /var/www/drupal directory. Once the files have been unpacked and copied, you’ll need to make a few changes. First, you’ll have to create a settings.php file for Drupal to use during the installation:

sudo cp /var/www/drupal/sites/default/default.settings.php /var/www/drupal/sites/default/settings.php

Next, make the file writable:

sudo chmod 666 /var/www/drupal/sites/default/settings.php

Then create a files directory for Drupal to use:

sudo mkdir /var/www/drupal/sites/default/files

Mark the files directory as writable:

sudo chmod 666 /var/www/drupal/sites/default/files

Now you’re ready to install Drupal. Open up a web browser on your Ubuntu system and navigate to http://localhost/drupal. You’ll be redirected to the Drupal installation page. Click on the Install Drupal In English link to continue.

On the next page, you’ll be asked for the database name, username, and password you created earlier. Enter those names and continue. On the next page, you’ll be asked to set an admin username and password and a few other settings.

After that, your basical Drupal installation is finished, and you can choose how to further customize the site. One last thing you should do; use this command to change the settings.php file so it is no longer writable:

sudo chmod 744 /var/www/drupal/sites/default/settings.php

share|improve this answer
1  
Great howto, just one thing; When you're finished working the MySql database, you have to type "quit" before you can go on working in the shell. Thank you very much for this howto! –  user24602 Sep 8 '11 at 7:58
    
Small note for noobs, you should change this AddType application/x-httpd-php.html to AddType application/x-httpd-php .html "notice the space between x-httpd-php and .html" and if you got a problem installing sudo apt-get install mysql-server-5.1 replace it with sudo apt-get install mysql-server-5.5 –  saadlulu Dec 4 '12 at 9:16
    
Also do not forget to run sudo a2enmod rewrite then sudo /etc/init.d/apache2 restart hope it helps –  saadlulu Dec 4 '12 at 12:15
    
"First, you’ll have to create a settings.php file for Drupal to use during the installation" NO, that's not correct, Drupal creates settings.php on its own, there's NO need to create settings.php file manually!! –  Sk8erPeter Jan 8 '13 at 11:41
  1. Install LAMP just run sudo tasksel and follow the installation How to install LAMP
  2. Download Drupal and extract inside /var/www/
  3. locate the durupal directory using browser http://localhost/drupal
  4. it is easy to install drupal ones you have setup LAMP use the drupal installation instruction to install Drupal
share|improve this answer

addtype application/x-httpd-php .php

share|improve this answer
2  
Could you please state how to work with that line? Put it in a file? Run it in Terminal? –  hexafraction Aug 16 '12 at 23:21

There is a far more easier way. Use Drubuntu from Drubuntu.info. This sets up Drupal for you right from the start and you could create your Ubuntu Environemnt arround it. Install your favorite desktop and so on

share|improve this answer
    
Until they are ready you could try to install drubuntu trough wget drubuntu.googlecode.com/git/scripts / getit.sh. As far as I know you need to create an user called ubuntu on your system and ad him to the sudoers file. than chmod +x getit .sh su ubuntu and sudo getit sh. –  Josh Sep 6 '13 at 7:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.