http with php on use_dir.

Well, it made me do a lot of googling to find how to do set apache2 with php on debian, actaully i think it was working, but since i was trying with userdir, and it was not working, so checked in /etc/apache2/mods-available/php5.conf

    # To re-enable php in user directories comment the following lines
    # (from <IfModule …> to </IfModule>.) Do NOT set it to On as it
    # prevents .htaccess files from disabling it.

and then everything was so easy. Well btw, if facing a problem of php file being downloaded the solution is pretty simple. This could be because Debian’s config puts “application/x-httpd-php php” in its mime.types file, but fortunately the fix is easy. Clear your browser’s cache and restart the browser, and then try again.

Installing Apache 2 and PHP 5 on Debian


Lately a lot of folks on #Apache have requested help with installation of Apache 2[.2] and PHP 5 on Debian-based systems.   

Even though this is a rather straightforward process, we have so far neglected to document it. This page provides that documentation.   


Preparing your system


Before getting started, you should prepare your system, and before preparing your system, you should prepare yourself. You should know: What do you want to achieve? What technology is best to achieve that goal? What constraints are there?   

Now that you know that you want to create a website, using Apache 2, PHP 5 and MySQL, that your knowledge is your only constraint, and that this wiki will help you learn more, you can start preparing your system by typing [either as root, or prefixed with sudo]:   


apt-get update


This will download the latest lists of packages, to make sure you install the current versions of the software.   


Installing the Software


Installing the required packages is as straightforward as installing any other package on Debian; the trick is knowing what packages you need:   


apt-get install apache2-mpm-prefork libapache2-mod-php5


This should actually suffice. Debian’s package mangement system should now automatically chose the missing packages which need to be installed. If you’re running the latest version of Debian [as of this writing: Etch], you might want to also install the latest [and best] version of apache, by explicitly specifying apache2.2-common in the above install command.  

If you also need MySQL, adding php5-mysql and mysql-server-5.0, should do the rest of the magic.

After that install is complete, visiting http://localhost/ in your browser should prove that you now have a running web server.


Configuring PHP


As Debian is trying to be extra-friendly, it splits a single package up into all possible and impossible modules. In Apache’s case those modules are called libapache2-mod-something and their configuration files are saved in /etc/apache2/mods-available. To enable a module, you’d type something like:


a2enmod php5


Which will simply symlink /etc/apache2/mods-available/php5.conf and /etc/apache2/mods-available/php5.load to /etc/apache2/mods-enabled/.

If you had php4 installed you might get the following error when restarting apache:


Forcing reload of web server (apache2)...apache2: Syntax error on line 185 of /etc/apache2/apache2.conf: Syntax error on line 1 of /etc/apache2/mods-enabled/php4.load: Cannot load /usr/lib/apache2/modules/ into server: /usr/lib/apache2/modules/ cannot open shared object file: No such file or directory


To solve this disable the php4 module:


a2dismod php4



For debian Lenny (5.0) and lower


You’re half done now. The last two things that need to be taken care of are to correct Debian’s default PHP configuration for Apache. You can do this by editing /etc/apache2/mods-available/php5.conf:



AddType application/x-httpd-php .php


<FilesMatch \.php$>
  SetHandler application/x-httpd-php

and save the changes.


And now you’ll have to tell Apache to reload its configuration and thus enable PHP:


/etc/init.d/apache2 restart

That’s it. You should now be able to run PHP scripts on your newly installed web server.

%d bloggers like this: