While I am pretty much a Microsoft guy today, I fiddled quite a lot with Linux, and especially the Slackware distro back in the days . I recently threw away my old file server, that ran Linux (Slackware 12.1), and replaced it with some new hardware and Hyper-V.
Since I like to keep up to date on stuff I’ve been doing in the past, I decided to set up a new Linux guest on my Hyper-V, and while I won’t go through the basics of installing the OS, I decided to write a short guide to install Apache, PHP and MySQL on Slackware 12.1 to get a web server with a database back-end up and running. I also decided I might as well post it here, and as this is written for Slackware 12.1, it will probably work for previous releases (I think I’ve used this method since 9.0), and also the latest 13.0 build. Remember that this is a quick guide, so if you need to do more customization you will have to go elsewhere (preferably read the docs).
So here goes.
1. Install MySQL
Get the latest sources from MySQL. Unless you need the Enterprise features and are willing to pay, get the Community Server GA (Generally Available). In Slackware you can use wget to get the sources. You can also get RPM packages, but I generally like to compile the sources myself so I know how the stuff is put together. It also gives me more control.
I usually put all my sources into /usr/local/src so I know where they are if I need them later. I’ll work from this directory in this guide.
root@dev:~# cd /usr/local/src/
root@dev:/usr/local/src# wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.45.tar.gz/from/http://mysql.borsen.dk/
The latest version is as of now 5.1.45.
Now, simply extract the tar file, go into the new path, configure the Makefile and start compiling it. I chose a prefix to /usr/local/mysql, because I want it there. After it has been successfully compiled (which can take some time, depending on your hardware, so go grab some coffee), it can be installed with ‘make install’.
root@dev:/usr/local/src# tar zxvf mysql-5.1.45.tar.gz
root@dev:/usr/local/src# cd mysql-5.1.45
root@dev:/usr/local/src/mysql-5.1.45# ./configure –prefix=/usr/local/mysql
root@dev:/usr/local/src/mysql-5.1.45# make install
You shouldn’t get any errors with a plain Slackware install, but if you do check out Google or the MySQL forums for help.
Now, let’s install the basic database-set containing grant tables (you need this if this is the first install), and set some permissions to tighten security a bit.
root@dev:/usr/local/src/mysql-5.1.45# chown -R root /usr/local/mysql
root@dev:/usr/local/src/mysql-5.1.45# chown -R mysql /usr/local/mysql/var
root@dev:/usr/local/src/mysql-5.1.45# chgrp -R mysql /usr/local/mysql
MySQL is now installed, but not running yet. You can start the MySQL database daemon by using the following command.
root@dev:/usr/local/src/mysql-5.1.45# /usr/local/mysql/bin/mysqld_safe –user=mysql &
You should get something like this as output.
100421 06:19:13 mysqld_safe Logging to ‘/usr/local/mysql/var/dev.err’.
100421 06:19:13 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/var
Success. The database has been started. I would strongly advise you to also change the default root user’s password, since it is blank by default. This must be done after the database has been started.
root@dev:/usr/local/src/mysql-5.1.45# /usr/local/mysql/bin/mysqladmin -u root password ‘new-password’
You should now be able to login to your database by using the mysql command, as so.
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.1.45 Source distribution
Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the current input statement.
Note that by using this method, all binaries for MySQL will be in /usr/local/mysql/bin, so if you would like to simply run ‘mysql’ to connect, you’d have to create a link to the binary in /usr/bin. Don’t ask me why I do it this way, I simply do.
2. Install Apache
Now that MySQL is installed (the hard part), get the latest sources from Apache. I use version 2.2.15 as of this writing. Remember to change back to /usr/local/src.
root@dev:/usr/local/src# wget http://mirrorservice.nomedia.no/apache.org/httpd/httpd-2.2.15.tar.gz
Now simply extract the sources, and do configure, make and make install.
root@dev:/usr/local/src# tar zxvf httpd-2.2.15.tar.gz
root@dev:/usr/local/src# cd httpd-2.2.15
root@dev:/usr/local/src/httpd-2.2.15# ./configure –prefix=/usr/local/apache –enable-module=so –enable-module=rewrite –with-apxs2=/usr/local/apache/bin/apxs
root@dev:/usr/local/src/httpd-2.2.15# make install
Now, as you can see there are more options than just prefix here. You don’t NEED these, but they are nice to have. The ‘so’ module makes it easier to load modules on startup, and I personally use the ‘rewrite’ module for some stuff. The apxs2 option also makes it a lot easier to get PHP to work by loading the module, and to use this you do need the ‘so’ module.
That’s basically it for Apache. You can start the server with the following command. After this you should be able to browser http://localhost
3. Install PHP
Get the latest sources from PHP. The latest build is 5.3.2. Simply extract, configure and compile.
root@dev:/usr/local/src# wget http://no.php.net/get/php-5.3.2.tar.gz/from/this/mirror
root@dev:/usr/local/src# tar zxvf php-5.3.2.tar.gz
root@dev:/usr/local/src# cd php-5.3.2
root@dev:/usr/local/src/php-5.3.2# ./configure –with-mysql=/usr/local/mysql –with-apxs2=/usr/local/apache/bin/apxs
root@dev:/usr/local/src/php-5.3.2# make install
Notice that we point to the installation of both MySQL and the apxs binary for Apache when installing PHP. This should make PHP and Apache work smoothly together, and also make PHP be able to recognize that MySQL is installed on the server.
For Apache to parse PHP files correctly you also need to do one change in the httpd.conf file located in /usr/local/apache/conf. Simply search for AddType in the file and insert the following two lines somewhere between the <IfModule mime_module> tag. There should be some other AddType instances there, so you can see how it is done. This basically makes Apache recognize the php and phps files so that they are parsed with the x-httpd-php mime types.
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
Now simply restart (or start if you haven’t already) the Apache web server, and you should be good to go.
/usr/local/apache/bin/apachectl start / restart
You can create a file called for example info.php in /usr/local/apache/htdocs to include the following, and you should get some environment info for your Apache installation.
Congratulations, you are done. 🙂