<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><entry xmlns='http://www.w3.org/2005/Atom' xmlns:georss='http://www.georss.org/georss'><id>tag:blogger.com,1999:blog-11430866.post-114904716448534260</id><published>2006-05-30T20:45:00.000-07:00</published><updated>2006-05-30T20:46:04.896-07:00</updated><title type='text'>Building a LAMP Server</title><content type='html'>&lt;p class="bigtitle"&gt;Building a LAMP Server&lt;/p&gt; &lt;p&gt;Last update: May 10, 2006&lt;/p&gt;   &lt;p class="accent"&gt;Now in development - this HOWTO but with Apache 2, MySQL 5, and PHP 5.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;A note from the author&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;I hope you find this guide, HOWTO, tutorial -- call it what you will -- useful. I also hope it saves you some time. If you do find it useful, I would be grateful if you could make a donation using the button below (and if it wasn't useful, &lt;a href="mailto:brucetimberlake@gmail.com"&gt;mail me&lt;/a&gt; and  tell me why not).&lt;/p&gt;  &lt;p&gt;I receive a great deal of mail as a result of this HOWTO, much of it asking me to solve various  LAMP-related problems. Please bear in mind that the money that puts food on my family's table comes from the consultancy work that I do. If you would like help with any of the points discussed in this article, &lt;a href="mailto:brucetimberlake@gmail.com"&gt;mail me&lt;/a&gt; and  tell me what that help is worth to you. Quote any amount you like, and if I'm able to help you out, you can make a PayPal donation by way of thanks. Fair enough?&lt;/p&gt; &lt;div align="left"&gt; &lt;form action="https://www.paypal.com/cgi-bin/webscr" method="post"&gt; &lt;input name="cmd" value="_s-xclick" type="hidden"&gt;  &lt;input name="encrypted" value="-----BEGIN PKCS7----- MIIHLwYJKoZIhvcNAQcEoIIHIDCCBxwCAQExggEwMIIBLAIBADCBlDCBjjELMAkG A1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQw EgYDVQQKEwtQYXlQYWwgSW5jLjETMBEGA1UECxQKbGl2ZV9jZXJ0czERMA8G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ol/7PL+zt0mV5CbbX3zQv4QHF+uJnhqekWHUKxBodFoBAw70HZR4kmSOX16iF 7ngE5XXnADllF/PvKCBadc3pmcZVcTKT4WRbHA6eoz3Np/sHWXx3pOdCOeOfZ34+ kxPn1Vu/gtP1+ynPVZw/fa0yoA== -----END PKCS7-----" type="hidden"&gt; &lt;/form&gt; &lt;/div&gt;  &lt;hr /&gt;  &lt;p&gt;This document will walk you through the installation of what is known as a "LAMP" system:  &lt;strong&gt;Linux&lt;/strong&gt;, &lt;strong&gt;Apache&lt;/strong&gt;, &lt;strong&gt;MySQL&lt;/strong&gt; and &lt;strong&gt;PHP&lt;/strong&gt;. Depending on who you talk to, the &lt;strong&gt;P&lt;/strong&gt; also stands for &lt;strong&gt;Perl&lt;/strong&gt; or  &lt;strong&gt;Python&lt;/strong&gt;, but in general, it is assumed to be PHP. I run &lt;a href="http://www.centos.org/"&gt;CentOS&lt;/a&gt; on my servers; these directions were written for CentOS/Red Hat/Fedora. I have had requests for SuSE (another RPM-based distribution) as well as Debian-based systems, so I will work on variants of these directions for those distributions in the future (donations might help speed that process up!). The main difference between the distributions is in the paths to the startup scripts. Red Hat systems used &lt;code&gt;/etc/rc.d/init.d&lt;/code&gt; and SuSE uses &lt;code&gt;/etc/init.d&lt;/code&gt;.&lt;/p&gt;  &lt;p class="accent"&gt;If you are not comfortable with trying this procedure yourself, I am  available for hire to install LAMP systems, or assist you with any other Linux-based projects.&lt;br /&gt;&lt;br /&gt;You can check &lt;a href="http://www.brtnet.org/resume.htm"&gt;my resume&lt;/a&gt; for background and contact information, or email &lt;code&gt;bruce.timberlake at gmail.com&lt;/code&gt; with your project details!&lt;/p&gt;  &lt;p&gt;If you need an SSL-enabled server, I have a &lt;strong&gt; &lt;a href="http://www.lamphowto.com/lampssl.htm"&gt;LAMP with SSL howto&lt;/a&gt;&lt;/strong&gt; as well.&lt;/p&gt;  &lt;p&gt;I designed this document so you can just copy/paste each line or block of commands into your shell session and it will "just work" for you. This avoids tedious typing, and  the inevitable typos or missed steps that result.  &lt;strong&gt;These commands work properly via copy/paste. If you are having problems and you are not using copy/paste, please re-check your typing before sending me an email saying "It doesn't work."&lt;/strong&gt;&lt;/p&gt;  &lt;p class="command"&gt; Text in a "command" box like this one is a literal Linux commandline, and should be typed or pasted exactly as written. &lt;/p&gt;  &lt;p class="boldaccent"&gt; One note: many &lt;strong&gt;many&lt;/strong&gt; people have followed these directions as written, and have not had any problems.&lt;br /&gt;If you are having a problem, chances are it's something you are doing (or not doing), something different&lt;br /&gt;about your computer, etc.&lt;br /&gt;&lt;br /&gt;It is probably &lt;strong&gt;NOT&lt;/strong&gt; this procedure. :)&lt;/p&gt;  &lt;p class="title"&gt;Initial Steps&lt;/p&gt;  &lt;p class="accent"&gt;PLEASE BE AWARE THAT A SOURCE-BASED INSTALLATION LIKE THIS ONE IS NOT NEEDED FOR A BASIC LAMP SERVER! You should only be doing a source-based installation if you need to alter settings in one or more components of the  LAMP stack (e.g., you need a feature in PHP that isn't in the default RPM). If you are just getting started with LAMP, use the binaries provided by your distribution - it is much simpler, and a lot easier to upgrade later.&lt;/p&gt;  &lt;p&gt;Most out-of-the-box Red Hat Linux installations will have one or more of the LAMP components installed via RPM files. I personally believe in installing things like this from  source, so I get the most control over what's compiled in, what's left out, etc.  But  source code installs can wreak havoc if overlaid on top of RPM installs, as the two most  likely won't share the same directories, etc.&lt;/p&gt;  &lt;p&gt;If you have not yet installed your Linux OS, or just for future reference, do not choose to install Apache, PHP, or MySQL during the system installation. Then you can immediately proceed with the source-based install listed here.&lt;/p&gt;  &lt;p&gt;Note: to install applications from source code, you will need a C++ compiler (gcc++) installed. This is generally taken care of, but I've had enough queries about it that I've added this note to avoid getting more! You can use your distribution's install CDs to get the proper  version of the compiler. Or, if you are using an RPM based distro, you can use a site like  &lt;a href="http://www.rpmfind.net/"&gt;http://www.rpmfind.net/&lt;/a&gt; to locate the correct RPM  version for your system. (You will obviously not be able to use/rebuild a source RPM to get  the compiler installed, as you need the compiler to build the final binary RPM!) On a Fedora system, you can do this command:&lt;/p&gt;  &lt;p class="command"&gt;su - root&lt;br /&gt;yum install gcc gcc-c++&lt;/p&gt;  &lt;p class="title"&gt;Log in as &lt;code&gt;root&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;Because we will be installing software to directories that "regular" users don't have write access to, and also possibly uninstalling RPM versions of some applications, we'll  log in as &lt;code&gt;root&lt;/code&gt;.  The only steps that &lt;i&gt;need&lt;/i&gt; &lt;code&gt;root&lt;/code&gt; access are the actual  installation steps, but by doing the &lt;code&gt;configure&lt;/code&gt; and &lt;code&gt;make&lt;/code&gt; steps as &lt;code&gt;root&lt;/code&gt;,  the source code will also be inaccessible to "regular" users.&lt;/p&gt;  &lt;p&gt;If you do not have direct access (via keyboard) to the server, &lt;strong&gt;PLEASE&lt;/strong&gt; use &lt;a href="http://www.openssh.com/"&gt;Secure Shell (SSH)&lt;/a&gt; to access the server and not &lt;code&gt;telnet&lt;/code&gt;!! Whenever you use &lt;code&gt;telnet&lt;/code&gt; (or plain FTP for that matter), you are transmitting your username, password, and all session information in "plain text". This means that anyone who can access a machine someplace between your PC and your server can snoop your session and get your info. Use encryption wherever possible!&lt;/p&gt;  &lt;p class="command"&gt;su - root&lt;/p&gt;  &lt;p class="title"&gt;Remove RPM Versions of the Applications&lt;/p&gt;  &lt;p&gt;Before we start with our source code install, we need to remove all the existing RPM files for these products. To find out what RPMs are already installed, use the RPM query command:&lt;/p&gt;  &lt;p class="command"&gt;rpm -qa&lt;/p&gt;  &lt;p&gt;in conjunction with &lt;code&gt;grep&lt;/code&gt; to filter your results:&lt;/p&gt;  &lt;p class="command"&gt; rpm -qa | grep -i apache&lt;br /&gt;rpm -qa | grep -i httpd&lt;br /&gt;rpm -qa | grep -i php&lt;br /&gt;rpm -qa | grep -i mysql &lt;/p&gt;  &lt;p class="info"&gt;The 'httpd' search is in case you have Apache2 installed via RPM.&lt;/p&gt;  &lt;p&gt;To remove the RPMs generated by these commands, do&lt;/p&gt;  &lt;p class="command"&gt;rpm -e &lt;i&gt;filename&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;for each RPM you found in the query. If you have any content in your MySQL database already, the RPM removal step should not delete the database files. When you reinstall MySQL, you should be able to move all those files to your new MySQL data directory and have access to them all again.&lt;/p&gt;  &lt;p class="title"&gt;Get the Source Code for all Applications&lt;/p&gt;  &lt;p&gt;We want to put all our source code someplace central, so it's not getting mixed up in someone's home directory, etc.&lt;/p&gt;  &lt;p class="command"&gt;cd /usr/local/src&lt;/p&gt;  &lt;p&gt;One way application source code is distributed is in what are known as "tarballs." The &lt;code&gt;tar&lt;/code&gt; command is usually associated with making tape backups - &lt;code&gt;tar&lt;/code&gt; stands for &lt;strong&gt;T&lt;/strong&gt;ape &lt;strong&gt;AR&lt;/strong&gt;chive. It's also a handy way to pack up multiple files for easy distribution.  Use the &lt;code&gt;man tar&lt;/code&gt; command to learn more about how to use this very flexible tool.&lt;/p&gt;  &lt;p&gt;At the time of updating this, the current versions of all the components we'll use are:&lt;/p&gt;  &lt;p class="info"&gt; MySQL - 4.0.26 (MySQL v4.1.x coming soon; there are tricky locale issues)&lt;br /&gt;Apache - 1.3.34&lt;br /&gt;PHP - 4.4.2&lt;/p&gt;  &lt;p class="boldaccent"&gt;Please note: these are the &lt;strong&gt;only&lt;/strong&gt; versions of these that I have set up myself, and verified these steps against. If you use another version of any component, especially a newer version, this HOWTO may not be accurate, and I won't be able to provide free support under those circumstances. Paid support and assistance is &lt;strong&gt;always&lt;/strong&gt; available however.&lt;/p&gt;  &lt;p class="command"&gt; wget http://www.php.net/distributions/php-4.4.2.tar.gz&lt;br /&gt;wget http://apache.oregonstate.edu/httpd/apache_1.3.34.tar.gz &lt;/p&gt;  &lt;p&gt;There may be an Apache mirror closer to you - check their &lt;a href="http://httpd.apache.org/download.cgi"&gt;mirror page&lt;/a&gt; for other sources. Then insert the URL you get in place of the above for the &lt;code&gt;wget&lt;/code&gt; command.&lt;/p&gt;  &lt;p&gt;For MySQL, go to &lt;a href="http://dev.mysql.com/downloads/mysql/4.0.html"&gt;http://www.mysql.com/&lt;/a&gt; and  choose an appropriate mirror to get the newest MySQL version (v4.0.26).&lt;/p&gt;  &lt;p class="title"&gt;Unpack the Source Code&lt;/p&gt;  &lt;p class="command"&gt; tar zxf php-4.4.2.tar.gz&lt;br /&gt;tar zxf apache_1.3.34.tar.gz&lt;br /&gt;tar zxf mysql-4.0.26.tar.gz &lt;/p&gt;  &lt;p&gt;This should leave you with the following directories:&lt;/p&gt;  &lt;p class="info"&gt; /usr/local/src/php-4.4.2&lt;br /&gt;/usr/local/src/apache_1.3.34&lt;br /&gt;/usr/local/src/mysql-4.0.26&lt;/p&gt;  &lt;p class="title"&gt;Build and Install MySQL&lt;/p&gt;  &lt;p&gt;First, we create the group and user that "owns" MySQL.  For security purposes, we don't want MySQL running as &lt;code&gt;root&lt;/code&gt; on the system.  To be able to easily identify MySQL processes in &lt;code&gt;top&lt;/code&gt; or a &lt;code&gt;ps&lt;/code&gt; list, we'll make a user and group named &lt;code&gt;&lt;strong&gt;mysql&lt;/strong&gt;&lt;/code&gt;:&lt;/p&gt;  &lt;p class="command"&gt; groupadd mysql&lt;br /&gt;useradd -g mysql -c "MySQL Server" mysql &lt;/p&gt;  &lt;p&gt;If you get any messages about the group or user already existing, that's fine. The goal is just to make sure we have them on the system.&lt;/p&gt;  &lt;p&gt;What the &lt;code&gt;useradd&lt;/code&gt; command is doing is creating a user &lt;code&gt;mysql&lt;/code&gt; in the group &lt;code&gt;mysql&lt;/code&gt; with the "name" of MySQL Server.  This way when it's showed in various user and process watching apps, you'll be able to tell what it is right away.&lt;/p&gt;   &lt;!-- &lt;p&gt;You may ask - doesn't the MySQL user need to log in?  The answer to that is actually no. When MySQL is started, a controlling process owned by &lt;code&gt;root&lt;/code&gt; is started (via the &lt;code&gt;safe_mysqld&lt;/code&gt; script). Then child processes, owned by  &lt;code&gt;mysql&lt;/code&gt; are spawned from it.  The parent controlling process watches the  child processes and restarts them automatically if they get killed off, etc.&lt;/p&gt; --&gt;  &lt;p&gt;Now we'll change to the "working" directory where the source code is, change the file 'ownership' for the source tree (this prevents build issues in  reported in some cases where the packager's username was included on the source  and you aren't using the exact same name to compile with!) and start building.&lt;/p&gt;  &lt;p&gt;The &lt;code&gt;&lt;strong&gt;configure&lt;/strong&gt;&lt;/code&gt; command has many options you can specify.   I have listed some fairly common ones; if you'd like to see others, do:&lt;/p&gt;  &lt;p class="command"&gt;./configure --help | less&lt;/p&gt;  &lt;p&gt;to see them all.  Read the &lt;a href="http://www.mysql.com/documentation/index.html"&gt;documentation on the MySQL website&lt;/a&gt; for a more detailed explanation of each option.&lt;/p&gt;  &lt;p class="command"&gt; cd /usr/local/src/mysql-4.0.26&lt;br /&gt;&lt;br /&gt;chown -R root.root *&lt;br /&gt;&lt;br /&gt;make clean&lt;br /&gt;&lt;br /&gt;./configure --prefix=/usr/local/mysql --localstatedir=/usr/local/mysql/data --disable-maintainer-mode --with-mysqld-user=mysql --with-unix-socket-path=/tmp/mysql.sock --without-comment --without-debug --without-bench &lt;/p&gt;  &lt;p class="info"&gt;18-Jul-2005: If you are installing MySQL 4.0.x on Fedora Core 4, there is a problem with LinuxThreads that prevents MySQL from compiling properly. Installing on Fedora Core 3 works fine though. Thanks to Kevin Spencer for bringing this to my attention. There is a workaround listed at  &lt;a href="http://bugs.mysql.com/bug.php?id=9497"&gt;http://bugs.mysql.com/bug.php?id=9497&lt;/a&gt;. Thanks to Collin Campbell for that link. Another solution can be found at &lt;a href="http://bugs.mysql.com/bug.php?id=2173"&gt;http://bugs.mysql.com/bug.php?id=2173&lt;/a&gt;. Thanks to Kaloyan Raev for that one.&lt;/p&gt;  &lt;p&gt;Now comes the long part, where the source code is actually compiled and then installed. Plan to get some coffee or take a break while this step runs. It could be 10-15 minutes or more, depending on your system's free memory, load average, etc.&lt;/p&gt;  &lt;p class="command"&gt; make &amp;&amp;amp; make install &lt;/p&gt;  &lt;p class="title"&gt;Configure MySQL&lt;/p&gt;  &lt;p&gt;MySQL is "installed" but we have a few more steps until it's actually "done" and ready to start.  First run the script which actually sets up MySQL's  internal database (named, oddly enough, &lt;code&gt;mysql&lt;/code&gt;).&lt;/p&gt;  &lt;p class="command"&gt; ./scripts/mysql_install_db &lt;/p&gt;  &lt;p&gt;Then we want to set the proper ownership for the MySQL directories and data files, so that only MySQL (and &lt;code&gt;root&lt;/code&gt;) can do anything with them.&lt;/p&gt;  &lt;p class="command"&gt; chown -R root:mysql  /usr/local/mysql&lt;br /&gt;chown -R mysql:mysql /usr/local/mysql/data &lt;/p&gt;  &lt;p&gt;Copy the default configuration file for the expected size of the database (small, medium, large, huge)&lt;/p&gt;  &lt;p class="command"&gt; cp support-files/my-medium.cnf /etc/my.cnf&lt;br /&gt;chown root:sys /etc/my.cnf&lt;br /&gt;chmod 644 /etc/my.cnf &lt;/p&gt;  &lt;p class="info"&gt;If you get an error message about the &lt;code&gt;data&lt;/code&gt; directory not existing, etc., something went wrong in the &lt;code&gt;mysql_install_db&lt;/code&gt; step above.  Go back and review that; make sure you didn't get some sort of error message when you ran it, etc.&lt;/p&gt;  &lt;p&gt;Now we have to tell the system where to find some of the dynamic libraries that MySQL will need to run.  We use dynamic libraries instead of static to keep the memory usage of the MySQL program itself to a minimum.&lt;/p&gt;  &lt;p class="command"&gt; echo "/usr/local/mysql/lib/mysql" &gt;&gt; /etc/ld.so.conf&lt;br /&gt;ldconfig &lt;/p&gt;  &lt;p&gt;Now create a startup script, which enables MySQL auto-start each  time your server is restarted.&lt;/p&gt;  &lt;p class="command"&gt; cp ./support-files/mysql.server /etc/rc.d/init.d/mysql&lt;br /&gt;chmod +x /etc/rc.d/init.d/mysql&lt;br /&gt;/sbin/chkconfig --level 3 mysql on &lt;/p&gt;  &lt;p&gt;Then set up symlinks for all the MySQL binaries, so they can be run  from anyplace without having to include/specify long paths, etc.&lt;/p&gt;  &lt;p class="command"&gt; cd /usr/local/mysql/bin&lt;br /&gt;for file in *; do ln -s /usr/local/mysql/bin/$file /usr/bin/$file; done &lt;/p&gt;  &lt;p class="title"&gt;MySQL Security Issues&lt;/p&gt;  &lt;p&gt;First, we will assume that only applications on the same server will be allowed to access the database (i.e., not a program running on a physically separate server).  So we'll tell MySQL not to even  listen on port 3306 for TCP connections like it does by default.&lt;/p&gt;  &lt;p&gt;Edit &lt;code&gt;/etc/my.cnf&lt;/code&gt; and uncomment the &lt;/p&gt;  &lt;p class="info"&gt;skip-networking&lt;/p&gt;  &lt;p&gt;line (delete the leading &lt;code&gt;#&lt;/code&gt;).&lt;/p&gt;  &lt;p&gt;For more security info, check this &lt;a href="http://www.securityfocus.com/infocus/1726"&gt;great tutorial&lt;/a&gt;  over at &lt;a href="http://www.securityfocus.com/"&gt;SecurityFocus&lt;/a&gt;.&lt;/p&gt;  &lt;p class="title"&gt;Start MySQL&lt;/p&gt;  &lt;p&gt;First, test the linked copy of the startup script in the normal server runlevel start directory, to make sure the symlink was properly set up:&lt;/p&gt;  &lt;p class="command"&gt; cd ~&lt;br /&gt;/etc/rc.d/rc3.d/S90mysql start &lt;/p&gt;  &lt;p&gt;If you ever want to manually start or stop the MySQL server, use these commands:&lt;/p&gt;  &lt;p class="command"&gt; /etc/rc.d/init.d/mysql start&lt;br /&gt;/etc/rc.d/init.d/mysql stop &lt;/p&gt;  &lt;p&gt;Let's "test" the install to see what version of MySQL we're running now:&lt;/p&gt;  &lt;p class="command"&gt;mysqladmin version&lt;/p&gt;  &lt;p&gt;It should answer back with the version we've just installed...&lt;/p&gt;  &lt;p&gt;Now we'll set a password for the MySQL &lt;code&gt;root&lt;/code&gt; user (note that the MySQL &lt;code&gt;root&lt;/code&gt; user is &lt;strong&gt;not&lt;/strong&gt; the same as the system &lt;code&gt;root&lt;/code&gt; user, and &lt;strong&gt;definitely&lt;/strong&gt; should not have the same password as the system &lt;code&gt;root&lt;/code&gt; user!).&lt;/p&gt;  &lt;p class="command"&gt;mysqladmin -u root password &lt;i&gt;new-password&lt;/i&gt;&lt;/p&gt;  &lt;p class="info"&gt;(obviously, insert your own password in the above command instead of the "new-password" string!)&lt;/p&gt;  &lt;p&gt;You're done!  MySQL is now installed and running on your server.  It is highly recommended that you read about MySQL security and lock down your server as much as possible.  The MySQL site has info at &lt;a href="http://www.mysql.com/doc/en/Privilege_system.html"&gt;http://www.mysql.com/doc/en/Privilege_system.html&lt;/a&gt;.&lt;/p&gt;  &lt;p class="title"&gt;Test MySQL&lt;/p&gt;  &lt;p&gt;To run a quick test, use the command line program &lt;code&gt;mysql&lt;/code&gt;:&lt;/p&gt;  &lt;p class="command"&gt;mysql -u root -p&lt;/p&gt;  &lt;p&gt;and enter your new &lt;code&gt;root&lt;/code&gt; user password when prompted.  You will then see the MySQL prompt:&lt;/p&gt;  &lt;p class="info"&gt;mysql&gt;&lt;/p&gt;  &lt;p&gt;First, while we're in here, we'll take care of another security issue and delete the sample database &lt;code&gt;test&lt;/code&gt; and all default accounts except for the MySQL root user. Enter each of these lines at the &lt;code&gt;mysql&gt;&lt;/code&gt; prompt:&lt;/p&gt;  &lt;p class="command"&gt; drop database test;&lt;br /&gt;use mysql;&lt;br /&gt;delete from db;&lt;br /&gt;delete from user where not (host="localhost" and user="root");&lt;br /&gt;flush privileges; &lt;/p&gt;  &lt;p&gt;As another security measure, I like to change the MySQL administrator account  name from &lt;code&gt;root&lt;/code&gt; to something harder to guess.  This will make it that much harder for someone who gains shell access to your server to take control of MySQL.&lt;/p&gt;  &lt;p class="boldaccent"&gt; MAKE SURE YOU REMEMBER THIS NEW NAME, AND USE IT WHEREVER&lt;br /&gt;YOU SEE "root" IN OTHER DIRECTIONS, WEBSITES, ETC.&lt;br /&gt;&lt;br /&gt;ONCE YOU DO THIS STEP, THE USERNAME "root" WILL CEASE TO&lt;br /&gt;EXIST IN YOUR MYSQL CONFIGURATION!&lt;/p&gt;  &lt;p class="command"&gt; update user set user="sqladmin" where user="root";&lt;br /&gt;flush privileges; &lt;/p&gt;  &lt;p&gt;Now, on with the "standard" testing... First, create a new database:&lt;/p&gt;  &lt;p class="command"&gt;create database foo;&lt;/p&gt;  &lt;p&gt;You should see the result:&lt;/p&gt;  &lt;p class="info"&gt;Query OK, 1 row affected (0.04 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; &lt;/p&gt;  &lt;p&gt;Delete the database:&lt;/p&gt;  &lt;p class="command"&gt;drop database foo;&lt;/p&gt;  &lt;p&gt;You should see the result:&lt;/p&gt;  &lt;p class="info"&gt; Query OK, 0 rows affected (0.06 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; &lt;/p&gt;  &lt;p&gt;To exit from &lt;code&gt;mysql&lt;/code&gt; enter &lt;code&gt;\q&lt;/code&gt;:&lt;/p&gt;  &lt;p class="command"&gt;\q&lt;/p&gt;  &lt;!-- &lt;div style="border: 1px black solid; padding: 1em;"&gt; &lt;h3 align="center"&gt;MySQL related books that I own and recommend:&lt;/h3&gt; &lt;table border="0" align="center" width="100%"&gt; &lt;tr&gt; &lt;td align="center"&gt;&lt;iframe src="http://rcm.amazon.com/e/cm?t=lamphowtocom-20&amp;o=1&amp;amp;p=8&amp;l=as1&amp;amp;asins=0735712123&amp;fc1=000000&amp;amp;=1&amp;lc1=0000ff&amp;amp;bc1=000000&lt;1=_blank&amp;IS2=1&amp;amp;f=ifr&amp;bg1=ffffff&amp;amp;f=ifr" width="120" height="240" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt; &lt;/iframe&gt;&lt;/td&gt; &lt;td align="center"&gt;&lt;iframe src="http://rcm.amazon.com/e/cm?t=lamphowtocom-20&amp;o=1&amp;amp;p=8&amp;l=as1&amp;amp;asins=1565924347&amp;fc1=000000&amp;amp;=1&amp;lc1=0000ff&amp;amp;bc1=000000&lt;1=_blank&amp;IS2=1&amp;amp;f=ifr&amp;bg1=ffffff&amp;amp;f=ifr" width="120" height="240" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt; &lt;/iframe&gt;&lt;/td&gt; &lt;/tr&gt;&lt;/table&gt; &lt;/div&gt; --&gt;  &lt;p class="title"&gt;Build and Install Apache (with DSO support)&lt;/p&gt;  &lt;p&gt;The advantage to building Apache with support for dynamically loaded modules is that in the future, you can add functionality to your webserver by just compiling and installing modules, and restarting the webserver. If the features were compiled into Apache, you would need to rebuild Apache from scratch every time you wanted to add or update a module (like PHP).  Your Apache binary is also smaller, which means more efficient memory usage.&lt;/p&gt;  &lt;p&gt;The downside to dynamic modules is a slight performance hit compared to having  the modules compiled in.&lt;/p&gt;  &lt;p class="command"&gt; cd /usr/local/src/apache_1.3.34&lt;br /&gt;&lt;br /&gt;make clean&lt;br /&gt;&lt;br /&gt;./configure --prefix=/usr/local/apache --enable-shared=max --enable-module=rewrite --enable-module=so&lt;br /&gt;&lt;br /&gt;make &amp;&amp;amp; make install &lt;/p&gt;  &lt;p class="title"&gt;Build and Install PHP&lt;/p&gt;   &lt;p&gt;This section has only been tested with PHP v4.x. If you are trying to build PHP 5.x, I do not have experience with this yet, and do not provide free support for you to get it working. Please note that there are &lt;b&gt;many&lt;/b&gt; options which can be selected when compiling PHP. Some will have library dependencies, meaning certain software may need to be already installed on your server before you start building PHP. You can use the command&lt;/p&gt;  &lt;p class="command"&gt;./configure --help | less&lt;/p&gt;  &lt;p&gt;once you change into the PHP source directory.  This will show you a list of all possible configuration switches.  For more information on what these switches are, please check the &lt;a href="http://www.php.net/manual/en/configure.php"&gt;PHP website documentation&lt;/a&gt;.&lt;/p&gt;  &lt;p class="command"&gt; cd /usr/local/src/php-4.4.2&lt;br /&gt;&lt;br /&gt;./configure --with-apxs=/usr/local/apache/bin/apxs --disable-debug --enable-ftp --enable-inline-optimization --enable-magic-quotes --enable-mbstring --enable-mm=shared --enable-safe-mode --enable-track-vars --enable-trans-sid --enable-wddx=shared --enable-xml --with-dom --with-gd --with-gettext --with-mysql=/usr/local/mysql --with-regex=system --with-xml --with-zlib-dir=/usr/lib&lt;br /&gt;&lt;br /&gt;make &amp;&amp;amp; make install&lt;br /&gt;&lt;br /&gt;cp php.ini-dist /usr/local/lib/php.ini &lt;/p&gt;  &lt;p&gt;I like to keep my config files all together in &lt;code&gt;/etc&lt;/code&gt;. I set up a symbolic link like this:&lt;/p&gt;  &lt;p class="command"&gt;ln -s /usr/local/lib/php.ini /etc/php.ini&lt;/p&gt;  &lt;p&gt;Then I can just open &lt;code&gt;/etc/php.ini&lt;/code&gt; in my editor to make changes.&lt;/p&gt;  &lt;p&gt;Recommended reading on securing your PHP installation is &lt;a href="http://www.securityfocus.com/infocus/1706"&gt;this article&lt;/a&gt; at &lt;a href="http://www.securityfocus.com/"&gt;SecurityFocus.com&lt;/a&gt;.&lt;/p&gt;  &lt;!-- &lt;div style="border: 1px black solid; padding: 1em;"&gt; &lt;h3 align="center"&gt;PHP related books that I own and recommend:&lt;/h3&gt; &lt;table border="0" align="center" width="100%"&gt; &lt;tr&gt; &lt;td align="center"&gt;&lt;iframe src="http://rcm.amazon.com/e/cm?t=lamphowtocom-20&amp;o=1&amp;amp;p=8&amp;l=as1&amp;amp;asins=0672326728&amp;fc1=000000&amp;amp;=1&amp;lc1=0000ff&amp;amp;bc1=000000&lt;1=_blank&amp;IS2=1&amp;amp;f=ifr&amp;bg1=ffffff&amp;amp;f=ifr" width="120" height="240" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt; &lt;/iframe&gt;&lt;/td&gt; &lt;td align="center"&gt;&lt;iframe src="http://rcm.amazon.com/e/cm?t=lamphowtocom-20&amp;o=1&amp;amp;p=8&amp;l=as1&amp;amp;asins=0975240218&amp;fc1=000000&amp;amp;=1&amp;lc1=0000ff&amp;amp;bc1=000000&lt;1=_blank&amp;IS2=1&amp;amp;f=ifr&amp;bg1=ffffff&amp;amp;f=ifr" width="120" height="240" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt; &lt;/iframe&gt;&lt;/td&gt; &lt;td align="center"&gt;&lt;iframe src="http://rcm.amazon.com/e/cm?t=lamphowtocom-20&amp;o=1&amp;amp;p=8&amp;l=as1&amp;amp;asins=0672325616&amp;fc1=000000&amp;amp;=1&amp;lc1=0000ff&amp;amp;bc1=000000&lt;1=_blank&amp;IS2=1&amp;amp;f=ifr&amp;bg1=ffffff&amp;amp;f=ifr" width="120" height="240" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt; &lt;/iframe&gt;&lt;/td&gt; &lt;/tr&gt;&lt;/table&gt; &lt;/div&gt; --&gt;  &lt;p class="title"&gt;Edit the Apache Configuration File (&lt;code&gt;httpd.conf&lt;/code&gt;)&lt;/p&gt;  &lt;p&gt;I like to keep all my configuration files together in &lt;code&gt;/etc&lt;/code&gt;, so I set up a symbolic link from the actual location to &lt;code&gt;/etc&lt;/code&gt;:&lt;/p&gt;  &lt;p class="command"&gt;ln -s /usr/local/apache/conf/httpd.conf /etc/httpd.conf&lt;/p&gt;  &lt;p&gt;Now open &lt;code&gt;/etc/httpd.conf&lt;/code&gt; in your favorite text editor, and set all the basic Apache options in accordance with &lt;a href="http://httpd.apache.org/docs/install.html#trad_install"&gt;the official Apache instructions&lt;/a&gt; (beyond the scope of this HOWTO).&lt;/p&gt;  &lt;p&gt;Also recommended is the article on &lt;a href="http://www.securityfocus.com/infocus/1694"&gt;securing Apache&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;To ensure your PHP files are properly interpreted, and not just downloaded as text files, remove the &lt;code&gt;#&lt;/code&gt; at the beginning of the lines which read:&lt;/p&gt;  &lt;div class="info"&gt; #AddType application/x-httpd-php .php&lt;br /&gt;#AddType application/x-httpd-php-source .phps &lt;/div&gt;  &lt;p&gt;If the AddType lines above don't exist, manually enter them (without the leading &lt;code&gt;#&lt;/code&gt; of course) after the line&lt;/p&gt;  &lt;p class="info"&gt; AddType application/x-tar .tgz &lt;/p&gt;  &lt;p&gt;or anyplace within the &lt;code&gt;&lt;ifmodule&gt;&lt;/code&gt; section of &lt;code&gt;httpd.conf&lt;/code&gt;.&lt;/p&gt;  &lt;p&gt;If you wish to use other/additional extensions/filetypes for your PHP scripts instead of just &lt;code&gt;.php&lt;/code&gt;, add them to the &lt;code&gt;AddType&lt;/code&gt; directive:&lt;/p&gt;  &lt;p class="info"&gt; AddType application/x-httpd-php .php &lt;strong&gt;.foo&lt;/strong&gt;&lt;br /&gt;AddType application/x-httpd-php-source .phps &lt;strong&gt;.phtmls&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;An example: if you wanted every single HTML page to be parsed and processed like a PHP script, just add &lt;code&gt;.htm&lt;/code&gt; and &lt;code&gt;.html&lt;/code&gt;:&lt;/p&gt;  &lt;p class="info"&gt;AddType application/x-httpd-php .php &lt;strong&gt;.htm .html&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;There will be a bit of a performance loss if every single HTML page is being checked for PHP code even if it doesn't contain any. But if you want to use PHP but be "stealthy" about it, you can use this trick.&lt;/p&gt;  &lt;p&gt;Add &lt;code&gt;index.php&lt;/code&gt; to the list of valid Directory Index files so that your "default page" in a directory can be named &lt;code&gt;index.php&lt;/code&gt;.&lt;/p&gt;  &lt;p class="info"&gt; &lt;ifmodule&gt;&lt;br /&gt;    DirectoryIndex &lt;strong&gt;index.php&lt;/strong&gt; index.htm index.html&lt;br /&gt;&lt;/ifmodule&gt; &lt;/p&gt;  &lt;p&gt;You can add anything else you want here too. If you want &lt;code&gt;foobar.baz&lt;/code&gt; to be a valid directory index page, just add the &lt;code&gt;.baz&lt;/code&gt; filetype to the &lt;code&gt;AddType&lt;/code&gt; line, and add &lt;code&gt;foobar.baz&lt;/code&gt; to the &lt;code&gt;DirectoryIndex&lt;/code&gt; line.&lt;/p&gt;   &lt;p class="title"&gt;Start Apache&lt;/p&gt;  &lt;p&gt;We want to set Apache up with a normal start/stop script in &lt;code&gt;/etc/rc.d/init.d&lt;/code&gt; so it can be auto-started and controlled like other system daemons.  Set up a symbolic link for the &lt;code&gt;apachectl&lt;/code&gt; utility (installed automatically as part of Apache):&lt;/p&gt;  &lt;p class="command"&gt;ln -s /usr/local/apache/bin/apachectl /etc/rc.d/init.d/apache&lt;/p&gt;  &lt;p&gt;Then set up auto-start for runlevel 3 (where the server will go by default):&lt;/p&gt;  &lt;p class="command"&gt;ln -s /etc/rc.d/init.d/apache /etc/rc.d/rc3.d/S90apache&lt;/p&gt;  &lt;p&gt;Then start the daemon:&lt;/p&gt;  &lt;p class="command"&gt;/etc/rc.d/init.d/apache start&lt;/p&gt;  &lt;p&gt;You can check that it's running properly by doing:&lt;/p&gt;  &lt;p class="command"&gt;ps -ef&lt;/p&gt;  &lt;p&gt;and look for the &lt;code&gt;httpd&lt;/code&gt; processes.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/11430866-114904716448534260?l=microdatainc.blogspot.com'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://microdatainc.blogspot.com/feeds/114904716448534260/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=11430866&amp;postID=114904716448534260' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/11430866/posts/default/114904716448534260'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/11430866/posts/default/114904716448534260'/><link rel='alternate' type='text/html' href='http://microdatainc.blogspot.com/2006/05/building-lamp-server.html' title='Building a LAMP Server'/><author><name>microdatainc</name><uri>http://www.blogger.com/profile/05909916944497316292</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='18436329505642318656'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>1</thr:total></entry>