What's the easiest way to install Drupal locally?

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 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.6

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 here on the drupal.org site.

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:

sudo -H gedit /etc/apache2/apache2.conf

(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)

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.)

Go ahead and exit MySQL:

\q

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 775 /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.

if http://localhost/drupal directs you to the 404 page, Apache is likely looking for the wrong document root. Run the following:

sudo -H gedit /etc/apache2/sites-enabled/000-default.conf

Replace DocumentRoot /var/www/html/ with DocumentRoot /var/www/; save and exit.

Restart apache to register the changes:

sudo /etc/init.d/apache2 restart

Go back to the web browser and navigate to http://localhost/drupal. 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 basic 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 world writeable:

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

  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

Tags:

Drupal