Community Documentation

Installing PHP, MySQL and Apache under Linux

Last updated February 23, 2010. Created by mike stewart on August 23, 2002.
Edited by Wolfflow, bekasu, ax, add1sun. Log in to edit this page.

Prior to choosing components to install, please be sure to reference Drupal requirements.

Install MySQL

Installing MySQL shouldn't be too much of a burden, when using a Linux distribution that can handle RPMs (RPM.org) or DEBs packages (Debian.org). All you have to do is grab the RPMs or DEBs packages from the MySQL website. Please do note that you'll also need the MySQL client RPM, not only the MySQL server one.

Install Apache and PHP

Once MySQL has been installed, download Apache and PHP, and unpack them in the same directory. To install Apache together with PHP and MySQL, follow the "quick install"-instructions in the INSTALL-file located in your PHP directory. When configuring PHP do not forget to replace 'apache_1.3.x' with your version of Apache HTTP Server.

After the compilation process you have to set the DocumentRoot in Apache's httpd.conf to the path of your drupal-directory. Make sure your Apache is setup to allow .htaccess files so drupal can override Apache options from within the drupal directories. Therefore, set AllowOverride to "All" instead of "None". Somewhat down httpd.conf they ask you to set Directory to whatever you set DocumentRoot to. The last thing to do is to add index.php in IfModule mod_dir.c behind DirectoryIndex. Apache will then look for index.php in the DocumentRoot and will display it as its main page.

mod_rewrite and clean urls
This works when running Apache2 under Debian (Sarge & Lenny) and should work for most systems:

To enable mod_rewrite:

# a2enmod rewrite
# /etc/init.d/apache2 restart

Note: the command a2enmod rewrite is unique to the Debian Linux based systems.

If you get an error regarding not finding gd, look in your php.ini file for a line reading
;extension=gd.so
and remove the ";" at the beginning of the line, then restart apache.

Note: look for the right php.ini configuration file as not every Linux based system use the same location

To get clean URLs working, make sure that your site definition file contains the Apache directive
AllowOverride All
(otherwise the .htaccess file won't take effect.)

Reverse proxy

Try using a plain httpd that serves static pages and cgi, and a mod_php httpd running as user x to run php scripts securely and fast. The .htaccess that comes with drupal doesn't work then of course. Using this instead (drupal 4.2.0-rc):

  (...php stuff...)

<IfModule mod_rewrite.c&gt
  RewriteEngine on

  # Rewrite URLs of the form 'index.php?q=x':
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ http://localhost:1234/index.php?q=$1 [L,QSA,P]
  # Redirect php scripts to mod_php server
  RewriteRule ^(.*\.php)$ http://localhost:1234/$1 [L,P]
</IfModule>

It might save you several minutes to hours when setting up :)

Comments

Note

I was able to skip the "add index.php" step, and neither "# a2enmod rewrite" or "# /etc/init.d/apache2 restart" do anything in Arch Linux. Apache is restarted by issuing "# /etc/rc.d/httpd restart".

Only Debian based Linux systems

To enable mod_rewrite:
This works when running Apache2 under Debian (Sarge) and should work for most systems:

This command are unique for Debian and Debian based Linux systems like Ubuntu : Linux specific guidelines

# a2enmod rewrite

Package manager?

This article makes installation unnecessarily hard work. With any modern Linux distro there is no need to download and install, the user should take advantage of a package manager, e.g. on Debian or Ubuntu use Synaptic (gui) or Apt-get/Aptitude (command line). Or at the command line 'tasksel' and select Lamp server.