Linux How to Install Apache, MySQL and PHP on CrunchBox Linux

5 Comments

So, you’re a CrunchBang Linux user but you want to get a little web development work done? This post will describe how to install and configure Apache, MySQL, and PHP on your box. Once set up, you’ll be able to use your LAMP server to do basic web development and code testing, maintain local copies of your web sites, etc.

The software discussed in this post are free and open source. Apache is licensed under the terms of the Apache License, a free-software license authored by the Apache Software Foundation. MySQL is available under the terms of the GNU GPL. PHP is distributed under the PHP license v3.01, an open source, BSD-style license certified by the Open Source Initiative. The remaining software, phpMyAdmin and WordPress, are not required, however, they are available under the terms of the GNU GPL. The versions for the software discussed in this post are as follows:

  • Apache v2.2.11-2ubuntu2
  • MySQL v5.1.30really5.0.75-0ubuntu10
  • PHP v5.2.6.dfsg.1-3ubuntu4
  • phpMyAdmin v4:3.1.2-1
  • WordPress v2.8.5
  • Let’s get started.

    Install Apache

    Let’s grab the latest version of the Apache HTTP server:

    Once successfully installed, the Apache server will start automatically. You may notice Apache complaining with “Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName.” No worries, it simply means that Apache could not find a qualified domain name like foo.com in its configuration file. Let’s prevent this message from popping up though by binding the server name to the localhost IP address. Open /etc/apache2/apache2.conf as root and append the following line to the end of the file:

    Now restart the Apache server with the following command:

    Let’s also make sure now that the server is working. Open a web browser and enter http://localhost. You should see Apache’s time tested “It Works!” message.

    Install MySQL.

    Now that the Apache HTTP server is up and running, let’s download and install the MySQL server:

    During the installation you’ll be asked several times to enter a password. You can leave it blank, but for obvious security reasons and to avoid configuration problems later, I would strongly suggest entering a password. Like Apache, once the MySQL server is installed, it will will start automatically. Now, let’s make sure the server is bound to the local host IP address like we did with Apache. Open /etc/mysql/my.cnf as root and make sure the following line exists. If not, simply append it to the end of the file:

    Now restart the MySQL server with the following command:

    Install PHP

    Almost there. Let’s download and install PHP:

    Brilliant. Now let’s test to make sure PHP was installed correctly. Navigate to /var/www/ (Apache’s web root folder) and create the following file:

    Open that file as root and enter the following PHP function:

    [php light=”true”]
    <?php phpinfo() ?>
    [/php]

    Open your web browser and enter http://localhost/phpinfo.php. You should see a page providing some information regarding your PHP installation (See Figure 1).

    Screenshot of the of the phpinfo function output

    Figure 1

    A completely optional but handy package to have for administering your MySQL server is phpMyAdmin. This package gives you the ability to create, copy, rename, alter and drop databases and tables using a web interface instead of the terminal. To install phpMyAdmin:

    During the installation you’ll be asked to chose the web server that should be automatically configured to run phpMyAdmin. You’ll want to chose Apache2. PhpMyAdmin will also indicate that it needs to have a database installed and configured before it can be used, and offer to set up a temporary configuration for you using db-config. Since we already have our MySQL server up and running we should choose No here. Once the install finishes, open your web browser and enter http://localhost/phpmyadmin. You should see the logon page for phpMyAdmin (See Figure 2).

    Screenshot of the phpMyAdmin logon page

    Figure 2

    That’s it for the installation. Now let’s move on make sure everything works together.

    Testing our LAMP installation using WordPress

    WordPress is a full-featured blogging tool (This web site was built using WordPress. The author is not full-featured) that makes heavy use of Apache, MySQL and PHP. We’ll install it on our LAMP server to ensure we have these packages installed correctly. Let’s start by downloading WordPress directly from the developers site. You can also download and install using Aptitude but I don’t recommend it as the repository’s release is a version or two behind the most current release. Navigate to your home directory (or wherever you’d prefer to download the package to) and download and untar the package:

    Let’s move the extracted wordpress/ directory to Apache’s web root folder:

    Now let’s create an MySQL database for our WordPress installation. Open phpMyAdmin in your browser. Enter root for the Username and the password you set during the MySQL installation (or simply leave this field blank if you skipped entering a password). To create a database, enter a name for it in the Create a new database field. For purposes of our example, let’s use wordpress as the name. Now select Create (See Figure 3).

    Screenshot of a database being created through phpMyAdmin

    Figure 3

    Now we need to do a little pre-configuration on one of the wordpress files in preparation for installation. First, navigate to /var/www/wordpress/. As root, copy the file wp-config-sample.php to wp-config.php. Open the latter file and enter the database name as well as your MySQL login and password. If you chose not to create a password when you installed the MySQL server, make sure to leave two single quotes with nothing in between in DB_PASSWORD. When complete, it should look like the following:

    Now let’s install WordPress. Open your web browser and navigate to http://localhost/wordpress/wp-config.php. If everything is configured as it should be you will be greeted with WordPress’s installation wizard (See Figure 4).

    Screenshot of the wordpress install wizard

    Figure 4

    Final thoughts

    One issue you may encounter is phpMyAdmin complaining that it can’t load the MySQL extension. More than likely the problem in this case is that phpMyAdmin wants the MySQL PHP module loaded automatically when Apache starts (it isn’t by default). To fix this, open /etc/php5/apache2/php.ini and uncomment following line extension=mysl.so. Save the file and restart Apache.

    Finally, you may not want your LAMP server running continuously but rather only when needed. There’s a couple of ways to keep Apache and MySQL from running at boot time. First, you could simply remove their corresponding entries from /etc/rc2.d. A more elegant way to manage these daemons, however, is to download and install sysv-rc-conf.

    sysv-rc-conf provides an easy to use interface for managing rc.d symlinks. The interface comes in two different flavors, one that simply allows turning services on or off and another that allows for more fine tuned management of the symlinks. To use it just enter sysv-rc-conf on a command line as root.

    When you want to use your LAMP server again you’ll need to start Apache and MySQL from the command line:

    Well, that’s it. With a couple of open source packages and a few minutes of your time you can a get a fully configured web server up and running on your CrunchBang Linux box.

    References

    http://httpd.apache.org/
    http://dev.mysql.com/doc/refman/5.1/en/
    http://php.net/index.php
    http://www.phpmyadmin.net/home_page/index.php
    http://wordpress.org/

    Tags: , , ,

    5 Responses to “How to Install Apache, MySQL and PHP on CrunchBox Linux”

    1. mojo706 Says:

      Hey thanks alot, 5 years later and it has helped me today.

    2. iceflatline Says:

      mojo706, thanks for the thanks!

    3. Darcy Says:

      Yes thanks – this is still a great howto.

      On a recent CrunchBang install I had to bash ‘sudo ln -s /usr/share/phpmyadmin /var/www’ to access phpmyadmin across my local network.

    4. Darcy Says:

      Oh – and rather than going to ‘http://localhost/wordpress/wp-config.php’ (which went into a redirect) I had to just simply go to ‘http://localhost/wordpress/index.php’ which went to the simple install page.

    5. iceflatline Says:

      Darcy, thanks for your comments. Much appreciated.

    Leave a Reply