How To Setup A SLAMP Server

This how-to will demonstrate quickly setting up a SLAMP (Slackware Apache MySQL PHP) server with minimal fuss. We won’t delve into the full configuration options; rather this is a quick “cheat sheet” for quickly getting a full feature web server up and running with the least effort.

Required Materials and Prior Knowledge

You should have a fresh installation of Slackware Linux which has been fully updated. This how-to was defined using Slackware64 14.0, but the principles are the same for most recent versions. You can refer to the slackpkg how-to for help with updating your installation. You should be familiar with basic shell commands and navigation.

Part 1: Apache and PHP

The first step is modifying the Apache web server configuration file. Open your shell and navigate to /etc/httpd and open httpd.conf with your favorite text editor. The two changes we must make to this file in order to get PHP working are to edit the DirectoryIndex and include the mod_php.conf. Before making any changes to your httpd.conf I highly recommend backing it up.

Find the section of httpd.conf that looks like this:

  • <IfModule dir_module>
  •  DirectoryIndex index.html
  • </IfModule>

Append index.php after index.html, separated by a single space, so that it looks like this:

  • <IfModule dir_module>
  •  DirectoryIndex index.html index.php
  • </IfModule>

Next, find the section that looks like this, and remove the # so that it is uncommented.

  • #Include /etc/httpd/mod_php.conf

Now that the config file is (minimally) prepared, we can start the service. Navigate to /etc/rc.d, chmod rc.httpd to be executable, and fire it up.

  • cd /etc/rc.d
  • chmod 755 rc.httpd
  • ./rc.httpd start

The Apache web server test screen. Click to enlarge.

To test that the server is running, open a web browser and navigate to localhost. You should see an, “It Works!” page like the one in the screenshot to the right.

The final step in this section is to test that PHP is working. Once again, open your favorite text editor, and create a file in your root web directory (default /var/www/htdocs) called test.php. Add the following code to it.

  • <?php
  • phpinfo();
  • ?>

The expected browser output of phpinfo(). Click to enlarge.

Then open your browser again and navigate to localhost/test.php. The screenshot to the left shows what should be displayed in your browser window. If this is what you get, then your PHP module has successfully loaded, and it is time to move on to the MySQL setup.

Part 2: MySQL

The first step in getting the “M” in SLAMP running is to set the permissions on rc.mysqld so that it is executable. Then, we need to run mysql_install_db, which “initializes the MySQL data directory and creates the system tables that it contains, if they do not exist.” You can read more about the mysql_install_db command at the MySQL reference pages.

  • cd /etc/rc.d
  • chmod 755 rc.mysqld
  • mysql_install_db

We then make sure that the user mysql is the owner and group for mysql and start the service. Next, we log into mysqladmin and run the secure installation script. When executing the script, which hardens your MySQL installation, just follow the prompts.

  • chown -R mysql:mysql /var/lib/mysql
  • ./rc.mysqld start
  • mysqladmin -u root password 'yourpasswordhere'
  • mysql_secure_installation

Once you have completed your mysql_secure_installation, you can log into MySQL using the password you established and do a “show databases;” to confirm that it is running. Last, restart the httpd service.


The barebones of a SLAMP server should now be up and running. I would highly encourage the reader to become familiar with httpd.conf and php.conf, so that you can intelligently configure your server based on your needs.

Andrew Nelson ; First Published: 12 April 2013 under the GPL v3 License.

Leave a Reply

Your email address will not be published. Required fields are marked *