Wednesday, February 3, 2010

Howto Tutorial on setting up Apache2, Php5, Mysql 5.0, phpmyadmin 4 on Debian Lenny (Squeeze Repos)

Recently, I had to rebuild my debian server, and decided to cover (in more depth this time) setting up several essential web server services.  I enabled the squeeze repositories, (I need them for the deluge torrent server setup).  The first thing we need to do is install apache2.


Apache2 Setup and Basic Configure

sudo aptitude install apache2
This should automatically set up and configure apache2 for you. It should also start the apache2 service at the end of installation. If not, here are some useful commands for apache2:
sudo /etc/init.d/apache2 [stop | start] - Starts or Stops the apache2 server.
sudo /etc/init.d/apache2 [restart | reload] - Restarts the apache2 server, or reloads the apache2 configuration files. Many times, all you will need to do is reload the configuration files and not restart apache2 entirely to apply changes.
Note:  When you install apache2, it creates a new user named "www-data".  This is the user that apache2 uses.  By default, the document root for apache web server is /var/www/
To test your configuration, type http://localhost or IP address if you are configuring remotely, and it should say "It works!".
Many of the configuration options can be changed by editing the apache2.conf file.
sudo nano /etc/apache2/apache2.conf
As well, many user configurations can be written to the httpd.conf file located in /etc/apache2/ folder along with apache2.conf
If for some reason apache2 is not working, you can ensure it is running by using the following command:
ps aux | grep apache2
This should list at least a few instances of apache2 running.
As well, if you want to change site specific settings, you can edit your default site file:
sudo nano /etc/apache2/sites-enabled/000-default
Next we will be covering PHP5, and how to integrate that into apache2.

PHP5 Installation and Integration with Apache2


Installing php5 is quite simple:
sudo aptitude install php5
Installing php5 should automatically link it with apache2 correctly. However to ensure that it is installed correctly, or if you encounter problems, you can check the following.
sudo nano /etc/apache2/apache2.conf
Around line 115, you should see the following lines:
Include /etc/apache2/mods-enabled/*.load
Include /etc/apache2/mods-enabled/*.conf
Make sure these lines are correct, and not commented out. This ensures that apache2 loads all of the enabled mods. Now if we want we can check to see which mods we have in our enabled folder.
ls -la /etc/apache2/mods-enabled
Notice that the mods-enabled are all links to .conf and .load files in the mods-available folder.
If you want to enable a mod there is an easy way to do that in debian:
a2enmod
This should bring up a large list of modules you can choose from to install, so just type the module you wish to install and apache should install it.
Next, you will notice that apache2 will not server .php file extensions by default, when there is a index.html file in the folder.  This is caused by a specific mod that is enabled with apache2 by default when installed.  The mod mod_dir controls what extensions and names are served first.  To change this we use the following command:
sudo nano /etc/apache2/mods-enabled/dir.conf
You should see the following line:
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
Change this line to suit your needs and you should be all set to go. Now, to test you php installation, you can create a simple php page and load it in the web browser. It should display a large amount of information about you php installation.


If the page loads successfully without errors, you should have php5 installed correctly.

Mysql 5.0 Server Installation and Configuration


sudo aptitude install mysql-server mysql-client
Follow the command prompts to set up an administrator password and you should be all set, mysql server 5.0 should be installed. To test the installation, log onto mysql:
mysql -u root -p
Enter your password and you should be logged into your mysql server. If you are good at mysql that might be all you need to get things done. However for those that need a little more help, we will install phpmyadmin.

Phpmyadmin Install and Configuration


Phpmyadmin is a very powerful tool for managing your mysql installation. Installing has to be done after you install your webserver, as phpmyadmin will automatically set itself up.
sudo aptitude install phpmyadmin
I am installing version (4:2.11.8.1-5+lenny3). As the package installs, it will prompt you to select the web server you have installed. Select apache2, and you should be all set. To access phpmyadmin, you should be able to navigate to http://localhost/phpmyadmin, and once you log in you should be able to manipulate mysql from your web browser.

6 comments:

  1. It actually worked. It saved me no end of grief. Thanks

    ReplyDelete
  2. Nice tutorial
    The only backward is that, why are there so much "sudo this sudo that" everywhere?? :S
    Sounds like Ubuntu more than Debian
    Anyway, thanks

    ReplyDelete
  3. Thanks for the tutorial. Please Add to install php-config which help to configure apache an php.

    ReplyDelete
  4. Very good tutorial, works in squeeze. Follow this and you cant go wrong.
    One thing I would like to add:
    sudo nano /etc/apache2/apache2.conf

    Add this to the last line:

    Include /etc/phpmyadmin/apache.conf

    Then,
    sudo /etc/init.d/apache2 restart

    And PHPMyAdmin should now work.

    ReplyDelete
  5. thx this worked for me great :D

    ReplyDelete