Introduction
Welcome to LAMP 101. In the next few pages we will take a journey of epic proportions. It is my goal that a person with limited knowledge in compiling, and decent knowledge in Linux, will be able to follow this technical document step by step and in less then 2 hours, have a compiled Linux Apache2 server with MySQL and PHP (LAMP). You will also have phpMyAdmin, phpsysinfo, and MediaWiki.
There are a few things I would like to mention before we start. This walk through is based on a clean installation of Fedora 8. On install no web server packages had been installed. If you have apache preinstalled it can be removed with the ‘yum remove httpd’ command. If you have PHP installed, it is possible, but errors and bugs may halt progress. If you are creating a LAMP server on a fresh install or in a VM machine then this step by step process should go smoothly, but remember, this is Linux.
Overview
Before we start the LAMP project, lets get a bit of an idea of what we will be doing and where we will be going. There will be a number of downloads needed, and quite a bit of configuring to do along the way. All of my links were valid and working as of March 19, 2008.
Requirements
There are a few things that are required to complete this project. You will obviously need a computer with Linux on it, root access in Linux, an internet connection and a ZoneEdit managed domain name. Your Linux box will also need a compiling engine so you may need to download gcc+.
The files we need and the order that we need to get is as follows.
1. MySQL
2. LibJpeg
3. LibPNG
4. FreeType
5. Zlib
6. GD2
7. Apache2
8. PHP
9. phpMyAdmin
10. phpsysinfo
11. MediaWiki
The list is long, but fret not, once we get going time will fly. Please note that it is very important that you follow this order for installation as some components need the others installed first. Go fill up your coffee cup, grab a sandwich, and let’s build a LAMP
Preparation
Before we begin to download the files we need, let’s make a directory to put all of files into. We are going to be doing all of this from a terminal so either press cntl/alt/F2 for a GUI-less terminal, which I would recommend most of the time, but in this situation I suggest to use the GUI terminal. If you are in Fedora 8 like me, you will access the terminal selecting the Applications menu => System Tools menu => then Terminal near or at the bottom. Once the terminal has opened type ‘su -’ to get superuser or root status. Then enter the root password. Now we are going to make a directory to place all of the downloads into. Type ‘yum install gcc’. If you already have it it will tell you that there is nothing to do. There were three other library I had to download.Type ‘yum install libxml2-devel’, ‘yum install flex’ and ‘yum install gdbm-devel’ There may be others that you will have to install. Each time I do this project on a different machine it seems to require different little steps but the main ones remain the same. Type ‘pwd’ to make sure that you are in root directory. You should just see ‘/’.I called mine compile. To do this type ‘mkdir compile’. You can now type ‘ls’ to your freshly made compile folder. Type ‘cd /compile’ to enter this directory. You can also push tab while typing and if the file exsits it will auto complete the file. If there are files with similar names, it will complete it until the next different letter. We are now ready to start getting our files to download.
MySQL
The MySQL program runs as a server providing multi-user access to a number of databases. For this project, we are going to use yum install. It is the only part of the entire project that will be done this way. There will be some other programs that will be installed that way but they are not part of the actual LAMP istallation.
1. Type ‘yum install mysql-server’
2. Type ‘yum install php-mysql’
3. Type ‘yum install mysql-*’
4. Type ‘service mysqld start’. This initialized MySQL. Note the change password warning, so lets do that.
5. Now we need to make MySQL come on everytime we start up the box, and incase the box resets because of a power outage. To do this type ‘chkconfig mysqld on’.
6. Type ‘/usr/bin/mysqladmin -u root password 'new-password'’ where new-password is your password. Do not forget your password.
7. Type ‘mysql –u root –p’ and enter your password. You are in your brand new MySQL server. Type ‘exit’ to leave.
Now you have your very own MySQL server. Now on to the compiling.
LibJpeg
LibJpeg is the source code that will give our LAMP the ability to work with jpeg images.
1. From the compile directory type ‘mkdir jpeg’. We will download the file into this folder. Also at this time we are going to make two other folders.
Type ‘mkdir /usr/
2. Type ‘cd / jpeg’. Again if you want to make sure that you are in the right directory type ‘pwd’.
3. Type ‘wget http://www.ijg.org/files/jpegsrc.v6b.tar.gz’ (if you are in a GUI terminal you can copy and paste it into the terminal, less typing means less mistakes and faster install.)
4. Type ‘ls’ to view the file. You see the tar file.
5. Type ‘tar –zxvf jpegscr.v6b.tar.gz’ and hit enter. Your screen will get busy, get use to it, it will happen a lot.
6. If you look in the directory you will now see a new folder called ‘jpeg-6b’ This contains the source code that is to be compiled. Type ‘cd /jpeg-6b’ to enter this directory.
7. Type ‘./configure --enable-shared’ This runs the configure script which checks for items installed, checks for a compiling engine, and which option modules we want to install.
8. Type ‘Make’. This utility reads the makefile’s and step by step instructions are created regarding how the to compile the software.
9. Type ‘Make install’ This compiles the software as per the makefile instructions.
This can take some time, and as you will see later with apache2, some take a lot longer then others. So once we have compiled our first program. We can start on the rest.
LibPNG
LibPNG is the source code that will give our LAMP the ability to work with PNG images.
1. From the compile directory type ‘mkdir png’. We will download the file into this folder.
2. Type ‘cd / png’ Again if you want to make sure that you are in the right directory type ‘pwd’.
3. Type ‘wget http://prdownloads.sourceforge.net/libpng/libpng-1.2.25.tar.gz’
4. Type ‘ls’ to view the file. You see the tar file.
5. Type ‘tar –zxvf libpng-1.2.25.tar.gz’ and hit enter.
6. If you look in the directory you will now see a new folder called ‘libpng-1.2.25’. This contains the source code that is to be compiled. Type ‘cd /libpng-1.2.25’to enter this directory.
7. Type ‘./configure’
8. Type ‘Make’
9. Type ‘Make install’
Now we move on to FreeType.
FreeType
FreeType is a software library that implements a font creation engine. It is used to compile characters into bitmaps and provides support for other font-related operations.
1. From the compile directory type ‘mkdir freetype’. We will download the file into this folder.
2. Type ‘cd / freetype’ Again if you want to make sure that you are in the right directory type ‘pwd’.
3. Type ‘wget http://download.savannah.gnu.org/releases/freetype/freetype-2.3.5.tar.gz’
4. Type ‘ls’ to view the file. You see the tar file.
5. Type ‘tar –zxvf freetype-2.3.5.tar.gz’ and hit enter.
6. If you look in the directory you will now see a new folder called ‘freetype-2.3.5’. This contains the source code that is to be compiled. Type ‘cd / freetype-2.3.5’ to enter this directory.
7. Type ‘./configure’
8. Type ‘Make’
9. Type ‘Make install’
Moving right along, the next piece of software to compile is Zlib.
Zlib
The Zlib library is used for data compression, and was origanaly designed to work with LibPNG.
1. From the compile directory type ‘mkdir zlib’. We will download the file into this folder.
2. Type ‘cd / zlib’ Again if you want to make sure that you are in the right directory type ‘pwd’.
3. Type ‘wget http://www.zlib.net/zlib-1.2.3.tar.gz’
4. Type ‘ls’ to view the file. You see the tar file.
5. Type ‘tar –zxvf zlib-1.2.3.tar.gz’ and hit enter.
6. If you look in the directory you will now see a new folder called ‘zlib-1.2.3’. This contains the source code that is to be compiled. Type ‘cd / zlib-1.2.3’ to enter this directory.
7. Type ‘./configure’
8. Type ‘Make’
9. Type ‘Make install’
GD2 is the last of our minor installs and we compiler it next.
GD2
The GD2 library is used to dynamically manipulate images.
1. From the compile directory type ‘mkdir gd’. We will download the file into this folder.
2. Type ‘cd / gd’ Again if you want to make sure that you are in the right directory type ‘pwd’.
3. Type ‘wget http://www.libgd.org/releases/gd-2.0.35.tar.gz’
4. Type ‘ls’ to view the file. You see the tar file.
5. Type ‘tar –zxvf gd-2.0.35.tar.gz’ and hit enter.
6. If you look in the directory you will now see a new folder called ‘gd-2.0.35’. This contains the source code that is to be compiled. Type ‘cd / gd-2.0.35’ to enter this directory.
7. Type ‘./configure -–with-png -–with-jpeg=/usr/local/lib -–with-freetype’
8. Type ‘Make’
9. Type ‘Make install’
Apache2 is next. All three steps take a while, good time to fill up on coffee.
Apache2
Eighty percent of internet web-servers use the Apache web-server throughout the world. Being opens source is one reason another is its amazing configurability and customization.
1. From the compile directory type ‘mkdir apache2’. We will download the file into this folder.
2. Type ‘cd / apache2’ Again if you want to make sure that you are in the right directory type ‘pwd’.
3. Type ‘wget http://gulus.usherbrooke.ca/pub/appl/apache/httpd/httpd-2.2.8.tar.gz’
4. Type ‘ls’ to view the file. You see the tar file.
5. Type ‘tar –zxvf httpd-2.2.8.tar.gz’ and hit enter
6. If you look in the directory you will now see a new folder called ‘httpd-2.2.8’. This contains the source code that is to be compiled. Type ‘cd / httpd-2.2.8’ to enter this directory.
7. Type ‘./configure –enable-shared –enable-so’ Here are our first options on our configure string.
8. Type ‘Make’
9. Type ‘Make install’
10. Lets see if it starts. Type ‘/usr/local/apache2/bin/httpd –k start’
11. Now type ‘/usr/local/apache2/bin/httpd –k stop’ Hint hit the arrow up button and change the word start to stop.
12. Now that should have started and stopped Apache2 Start it again, open a web browser and type ‘localhost’ If all went well you should see “IT WORKS”
13. So now lets set it Apache to also restart on reboot. Unfortunately it is not as easy as MySQL because we compiled it instead of using yum. To do this we need to tell Linux to start Apache when it is loading its daemons. Type ‘cd /etc/’
14. Type ‘vi rc.local’
15. Now you are in a text editor, you can read what this file does in the top comments. Hit the ‘a’ key to allow editing. Under ‘touch /var/lock/subsys/local’ type ‘/usr/local/apache2/bin/httpd –k start’ then hit ‘esc’ then ‘:’ and then ‘wq’. Now Apache will start up on boot and reboot. Reboot to be sure.
Type ‘reboot’ from root and it will reboot the system.
16. Type ‘vi /usr/local/apache2/conf/httpd.conf’
17. Thpe ‘/daemon’ to search for the group:daemon. Change both instances to apache. We do this so apache does not have too much power.
The Final step in our working LAMP is PHP. Let’s do it
PHP
PHP is a server side programming language that is widely used, and is very similar to Java.
1. From the compile directory type ‘mkdir php’. We will download the file into this folder.
2. Type ‘cd / php’ Again if you want to make sure that you are in the right directory type ‘pwd’.
3. Type ‘wget http://museum.php.net/php5/php-5.2.2.tar.gz’
4. Type ‘ls’ to view the file. You see the tar file.
5. Type ‘tar –zxvf php-5.2.2.tar.gz’ and hit enter.
6. If you look in the directory you will now see a new folder called ‘php-5.2.2’. This contains the source code that is to be compiled. Type ‘cd / php-5.2.2’ to enter this directory.
7. Type ‘./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysqli=/usr/bin/mysql_config --with-gd --with-zlib-dir=/usr/include/ --with-png-dir=/usr/local/lib/ --with-jpeg-dir=/usr/local/lib --with-gdbm --with-gettext --with-ttf --enable-gd-native-ttf --with-freetype-dir=/usr/lib/ --with-mysql’
Now that is one very long string. Just be glad you did not have to figure them out and you can cut and paste.
8. Type ‘Make’
9. Type ‘Make install’
10. Type ‘cp php.ini-dist /usr/local/lib/php.ini
11. Type ‘vi /usr/local/lib/php.ini’ then type ‘a’ ‘/2M’ and change the 2M upload to 50M for larger uploads.
12. Type ‘cd /usr/local/apache2/conf’
13. Type ‘vi httpd.conf’ Here we may need to add a couple of files.
When you get in type ‘/’. This will allow you to search the file.
After the ‘/’ type ‘LoadModule’.
Now depending on what has been compiled, you will need to type after the comments, ‘LoadModule php5_module modules/libphp5.so’
This may already be there.
Do a search again this time for ‘AddType’.
On the next line after the current AddType entries, type ‘AddType application/x-httpd-php .php .phtml’.
14. Go to the htdocs directory.
Type ‘cd ..’ followed by ‘cd htdocs’.
Type ‘vi info.php’.
We can now create a simple php doc.
<\?php //without the backslash
phpinfo();
?>
15. Make sure apache is running and go to your browers and type ‘localhost/info.php’ and you should see your phpinfo page.
Adding an ‘A’ record to DNS
An A record provides a pointer to a domain. One of the most common ‘A’ record is the webmail, webmail.itas.ca. We are going to make 4. First you need to make an account with zone edit, register you domain name, in my case it was kylecorey.ca. I will use my domain name as an example. Add the following A records to YOUR domain.
1. webserver.kylecorey.ca
2. wiki.kylecorey.ca
3. mysql.kylecorey.ca
4. phpmyadmin.kylecorey.ca
Virtual Hosts
The term Virtual Host refers to the practice of maintaining more than one server on one machine, as differentiated by their apparent hostname. We will now be using the ‘A’ records we created. Again I am using my domain as an example. We will not only be adding the Virtual Host, we will also set the ServerAdmin email address.
1. Type ‘cd /usr/local/apache2/conf’
2. Type ‘vi httpd.conf’ Now we can edit out Virtual Hosts.
3. Type ‘/ServerAdmin’ to search for where we will be editing.
4. We now need to enter all the Virtual host information. Change My example with the imperative information with yours. You will need to change my email address, IP’s etc. When we finish this we will install these programs.
ServerAdmin coreyk@itas.ca
NameVirtualHost 142.25.97.229
ServerAdmin coreyk@itas.ca
DocumentRoot /usr/local/apache2/htdocs
ServerName webserver1.kylecorey.ca
DirectoryIndex index.php
ServerAdmin coreyk@itas.ca
DocumentRoot /usr/local/apache2/htdocs/mediawiki-1.12.0rc1
ServerName wiki.kylecorey.ca
DirectoryIndex index.php
AcceptPathInfo on
ServerAdmin coreyk@itas.ca
DocumentRoot "/usr/local/apache2/htdocs/phpsysinfo"
ServerName system.kylecorey.ca
DirectoryIndex index.php
AcceptPathInfo on
ServerAdmin coreyk@itas.ca
DocumentRoot /usr/local/apache2/htdocs/phpMyAdmin-2.11.5-all-languages-utf-8-only/
ServerName mysql.kylecorey.ca
DirectoryIndex index.php
AcceptPathInfo on
Type ‘/usr/local/apache2/bin/httpd –k restart’ to restart apache to allow the changes to take place.
PHPSysInfo
PHP SysInfo is a nice little program that will display many useful pieces of information regarding the server. Things such as uptime, processor and ram information, available ram and so on.
1. From the compile directory type ‘mkdir phpsys’. We will download the file into this folder.
2. Type ‘cd / phpsys’ Again if you want to make sure that you are in the right directory type ‘pwd’.
3. Type ‘wget http://downloads.sourceforge.net/phpsysinfo/phpsysinfo-2.5.3.tar.gz’
4. Type ‘ls’ to view the file. You see the tar file.
5. Type ‘tar –zxvf phpsysinfo-2.5.3.tar.gz’ and hit enter.
6. If you look in the directory you will now see a new folder called ‘phpsysinfo-2.5.3’. This contains the source code that is to be compiled. Type ‘cd /php-2.5.3’ to enter this directory to view the contents.
7. Type ‘cd ..’ ‘mv -r php-2.5.3 /usr/local/apache2/htdocs’
8. Type ‘cp config.php.new config.php’
9. Type ‘/usr/local/apache2/bin/httpd –k restart’ and open a web browser and type ‘system.kylecorey.ca’
phpMyAdmin
phpMyAdmin is a free tool for handling administration of MySQL such as creating and dropping databases, creating, dropping and altering tables and deleting, editing and adding fields.
1. From the compile directory type ‘mkdir phpsys’. We will download the file into this folder.
2. Type ‘cd / phpmyadmin’ Again if you want to make sure that you are in the right directory type ‘pwd’.
3. Type ‘wget http://washington.edu/computing/web/publishing/phpMyAdmin-2.11.3-english.tar.gz’
4. Type ‘ls’ to view the file. You see the tar file.
5. Type ‘tar –zxvf phpMyAdmin-2.11.3-english.tar.gz’ and hit enter.
6. If you look in the directory you will now see a new folder called ‘phpMyAdmin-2.11.3-english’. This contains the source code that is to be compiled. Type ‘cd / phpMyAdmin-2.11.3-english’ to enter this directory to view the contents.
7. Type ‘cd ..’ ‘mv -r phpMyAdmin-2.11.3-english /usr/local/apache2/htdocs’
8. Type ‘cp config.sample.inc.php config.inc.php’
9. Type ‘/usr/local/apache2/bin/httpd –k restart’ and open a web browser and type ‘mysql.kylecorey.ca’
MediaWiki
MediaWiki is a PHP written program thave cam be used with MySQL database and allows users to post comments and such at a central location which is very useful to schools and organizations.
1. From the compile directory type ‘mkdir phpsys’. We will download the file into this folder.
2. Type ‘cd / phpmyadmin’ Again if you want to make sure that you are in the right directory type ‘pwd’.
3. Type ‘wget http://www.washington.edu/computing/web/publishing/mediawiki-1.11.0.tar.gz’
4. Type ‘ls’ to view the file. You see the tar file.
5. Type ‘tar –zxvf mediawiki-1.11.0.tar.gz’ and hit enter.
6. If you look in the directory you will now see a new folder called ‘mediawiki-1.11.0’. This contains the source code that is to be compiled. Type ‘cd / mediawiki-1.11.0’ to enter this directory to view the contents.
7. Type ‘cd ..’ ‘mv -r mediawiki-1.11.0 /usr/local/apache2/htdocs’
8. Type ‘/usr/local/apache2/bin/httpd –k restart’ and open a web browser and type ‘wiki.kylecorey.ca’
9. Click the ‘set up wiki’
10. Type ‘cd /usr/local/apache2/htdocs/mediawiki-1.11.0/’and change the permissions on the config file by typing ‘chmod a+w config’
11. Now we need to enter some information. Fill in the required data, create an admin user name and password.
12. Next we need to make a database. Go to a terminal and type ‘mysql –u root –p’ and enter your password. Type ‘create database test;’
13. On the wiki main page, and enter ‘localhost’ as the database host.
14. Now enter test as the database name.
15. Select the root user as DB user name. and enter your root password where it asks for the password.
16. Click the install MediaWiki.
17. Type ‘cd /usr/local/apache2/htdocs/mediawiki-1.11.0/config
18. Type ‘mv Localsettings.php
/usr/local/apache2/htdocs/mediawiki-1.11.0/mediawiki-1.11.0’
19. Type ‘chmod 444 localsettings.php’
Conclusion
You are now a proud owner of a LAMP server with phpMyAdmin, and MediaWiki. With a little bit of effort and a bunch of typing you can see how easy it is to compile code and configure programs to meet your needs. Enjoy.
Did this help or was it useful?? Are there errors??
Please post feed back so I can change them or know that I have helped.
Resources
andymdn.com