Welcome

Wednesday, January 24, 2007

Linux, Apache, MySQL & PHP (LAMP) Setup Guide

LAMP has become a defacto-standard around the web community in the recent years, here is a guide to help you set it up. LAMP is the combination of Linux + Apache + MySQL + PHP. You probably already have Linux up if you have come this far, if not you can get help setting it up throughout this site and on #LinuxHelp.net on DALnet.
Apache is the most popular web server on the net. It is very secure, fast, and reliable. There are may customizations you can make it, such as PHP support (which I am covering), CGI/Perl, SSL, SSI, ePerl, and even ASP. MySQL is the fastest RDBMS in the world. It is very good for web based applications as well. Many tools have been developed for MySQL with PHP, such as phpMyAdmin, a very good web based admin tool for MySQL, which can do anything your heart desires with MySQL.
PHP is an up and coming server-side scripting langauge. It was developed by Rasmus Lerdorf, and countless others. It is currently in version 3.0.12. It has many advantages over its competitors (ASP, Cold Fusion, Perl, Java, ...) , such as it is Object Oriented, embedded into HTML, very fast, cross-platform compatible, can run as an Apache Module, it is constantly updated and fixed, and it borrows the best features from many other langauges. Now that I have filled you with my propaganda, let's get started.
First of all, download the latest stable sources of Apache, MySQL, and PHP, you can find them at www.apache.org, http://www.mysql.com/, and http://www.php.net/, respectively. I would move them into /usr/local/src for consistancy, as well as making sure you get the tarball versions. Next, unpack them by typing:
tar -zxvf filename.tar.gz
Now, we are going to setup MySQL first cd into the mysql directory, maybe /usr/locl/src/mysql-3.23.41 Then configure it by typing:
./configure --prefix=/usr/local/mysql
This will put it in it's own directory, which I always put things in /usr/local as a standardization. Run the make command:
make
Run the make install command:
make install
Now it is installed. You need now to set it up. Add the MySQL Libraries to the ldconfig file:
echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf
Now have it cache all of the libraries:
ldconfig -v grep libmysqlclient
You should now see something returned like:
libmysqlclient.so.10 => libmysqlclient.so.10.0.0
Now have MySQL start at boot time:
echo "/usr/local/mysql/bin/safe_mysqld --skip-networking >> /dev/null &" >> /etc/rc.d/rc.local
Now you must make the initial databases the MySQL needs to run:
./scripts/mysql_install_db
Now start up the service daemon for MySQL:
/usr/local/mysql/bin/safe_mysqld --skip-networking >> /dev/null &
Now add it to the path:
PATH="$PATH:/usr/local/mysql/bin"
Now you should test MySQL:
mysqladmin version
This should give you back all kinds of info on MySQL. Now create a password for the SuperUser:
mysql -u root -p
It will then prompt your for a password:
Enter password:
And MySQL should be setup.
Now the next part is making the new Apache/PHP setup. If you are currently using Apache and have stuff that you would like to keep, do a backup on your data. Now blow away the old Apache, delete it by any means possible. Now change into the Apache source directory:
cd /usr/local/src/apache_X.X.X
Configure apache:
./configure --prefix=/usr/local/apache
Now change into the PHP source directory:
cd /usr/local/src/php-X.X.XX
And run the configuration of php to support MySQL and Apache:
./configure --with-apache=../apache_X.X.X --with-mysql=/usr/local/mysql
Now run the make command:
make
Now run the make install command:
make install
Now change back into the apache source directory:
cd ../apache_X.X.X
Now you have to reconfigure Apache, because we have added in the PHP Module. This will have it use the module you provided:
./configure --prefix=/usr/local/apache --activate-module=src/modules/php3/libphp3.a
This will configure it. Now you must run the the make and make install commands:
make
make install
There is a possibility that it will complain about not having an ANSII C compiler. If so, goto the FAQ on the http://www.php.net/ site. There are some common fixes there. If everything went well, you now have a few last minute setup processses to go through. Rename the http daemon:
mv /usr/local/apache/bin/httpd-X.X.X /usr/loacl/apache/bin/httpd
Now make a sybolic link and startup the http daemon:
ln -s /usr/local/apache/bin/httpd /usr/sbin/httpd
/usr/sbin/httpd
Now that it is up, test and see the version information:
httpd -v
Now you have to add a couple of pieces of info to the apache configuration files. They are located i /usr/local/apache/conf/
pico httpd.conf
Find the AddType section and uncomment these lines:
AddType application/x-httpd-php .phtml
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
This will make apache understand that it needs to pass these extensioned file to the php3 engine. Now find the DirectoryIndex section and add some info for php. It should look like this:
DirectoryIndex index.html index.phtml index.php index.phps
That should do it. Now restart the Apache http daemon:
killall -HUP httpd
Apache should be up with support for php. You can now add the phpMyAdmin tool that is found at http://www.phpwizard.net/ or anyting else you would like. Come find me in #LinuxHelp.net on DALnet and I will show a few things in php, also I will show you a cool version operation for php.

Linux System Administration


The Linux System Administrator's Guide
Version 0.9
Lars Wirzenius
<Email address removed by request>
Joanna Oja
<Current email address unknown>
Stephen Stafford
<stephen@clothcat.demon.co.uk.NOSPAM>
Alex Weeks
<draxeman@gmail.com.NOSPAM>

An introduction to system administration of a Linux system for novices.
Legal Notice
Table of Contents
About This Book
1. Acknowledgments
2. Revision History
3. Source and pre-formatted versions available
4. Typographical Conventions
1. Introduction
1.1. Linux or GNU/Linux, that is the question.
1.2. Trademarks
2. Overview of a Linux System
2.1. Various parts of an operating system
2.2. Important parts of the kernel
2.3. Major services in a UNIX system
3. Overview of the Directory Tree
3.1. Background
3.2. The root filesystem
3.3. The /etc directory
3.4. The /dev directory
3.5. The /usr filesystem.
3.6. The /var filesystem
3.7. The /proc filesystem
4. Hardware, Devices, and Tools
4.1. Hardware Utilities
4.2. Kernel Modules
5. Using Disks and Other Storage Media
5.1. Two kinds of devices
5.2. Hard disks
5.3. Storage Area Networks - Draft
5.4. Network Attached Storage - Draft
5.5. Floppies
5.6. CD-ROMs
5.7. Tapes
5.8. Formatting
5.9. Partitions
5.10. Filesystems
5.11. Disks without filesystems
5.12. Allocating disk space
6. Memory Management
6.1. What is virtual memory?
6.2. Creating a swap space
6.3. Using a swap space
6.4. Sharing swap spaces with other operating systems
6.5. Allocating swap space
6.6. The buffer cache
7. System Monitoring
7.1. System Resources
7.2. Filesystem Usage
7.3. Monitoring Users
8. Boots And Shutdowns
8.1. An overview of boots and shutdowns
8.2. The boot process in closer look
8.3. More about shutdowns
8.4. Rebooting
8.5. Single user mode
8.6. Emergency boot floppies
9. init
9.1. init comes first
9.2. Configuring init to start getty: the /etc/inittab file
9.3. Run levels
9.4. Special configuration in /etc/inittab
9.5. Booting in single user mode
10. Logging In And Out
10.1. Logins via terminals
10.2. Logins via the network
10.3. What login does
10.4. X and xdm
10.5. Access control
10.6. Shell startup
11. Managing user accounts
11.1. What's an account?
11.2. Creating a user
11.3. Changing user properties
11.4. Removing a user
11.5. Disabling a user temporarily
12. Backups
12.1. On the importance of being backed up
12.2. Selecting the backup medium
12.3. Selecting the backup tool
12.4. Simple backups
12.5. Multilevel backups
12.6. What to back up
12.7. Compressed backups
13. Task Automation --To Be Added
14. Keeping Time
14.1. The concept of localtime
14.2. The hardware and software clocks
14.3. Showing and setting time
14.4. When the clock is wrong
14.5. NTP - Network Time Protocol
14.6. Basic NTP configuration
14.7. NTP Toolkit
14.8. Some known NTP servers
14.9. NTP Links
15. System Logs --To Be Added
16. System Updates --To Be Added
17. The Linux Kernel Source
18. Finding Help
18.1. Newsgroups and Mailing Lists
18.2. IRC
A. GNU Free Documentation License
A.1. PREAMBLE
A.2. APPLICABILITY AND DEFINITIONS
A.3. VERBATIM COPYING
A.4. COPYING IN QUANTITY
A.5. MODIFICATIONS
A.6. COMBINING DOCUMENTS
A.7. COLLECTIONS OF DOCUMENTS
A.8. AGGREGATION WITH INDEPENDENT WORKS
A.9. TRANSLATION
A.10. TERMINATION
A.11. FUTURE REVISIONS OF THIS LICENSE
A.12. ADDENDUM: How to use this License for your documents
Glossary (DRAFT, but not for long hopefully)
Index-Draft
List of Tables
5-1. Comparing Filesystem Features
5-2. Sizes
5-3. My Partitions
9-1. Run level numbers
12-1. Efficient backup scheme using many backup levels
List of Figures
2-1. Some of the more important parts of the Linux kernel
3-1. Parts of a Unix directory tree. Dashed lines indicate partition limits.
5-1. A schematic picture of a hard disk.
5-2. A sample hard disk partitioning.
5-3. Three separate filesystems.
5-4. /home and /usr have been mounted.
10-1. Logins via terminals: the interaction of init, getty, login, and the shell.
12-1. A sample multilevel backup schedule.


Next


About This Book

Linux HOW TOs


LDP HOWTO-INDEX
Guylhem Aznar
Joshua Drake
Greg Ferguson
v9.0, 2005-12-29

This document contains an index to the Linux HOWTOs as well as other information about the HOWTO project.
Table of Contents
1. What Are Linux HOWTOs?
2. Where Can I Get Linux HOWTOs?
3. HOWTO Translations
4. Categorized List of HOWTOs
4.1. The Linux OS
4.1.1. Getting Started
4.1.2. Switching from Other Operating Systems
4.1.3. Distributions
4.1.4. Installation
4.1.5. Kernel
4.1.6. Boot Loaders and Booting the OS
4.1.7. Parallel Processing
4.1.8. Partitions and Filesystems
4.1.9. RAID
4.1.10. Printing
4.1.11. Shell
4.1.12. Using Linux
4.2. System Administration and Configuration
4.2.1. Configuration / Installation
4.2.2. Benchmarking
4.2.3. Clustering
4.2.4. Backup
4.2.5. Recovery
4.2.6. Security
4.3. Hardware
4.3.1. General
4.3.2. Platforms
4.3.3. Video Cards
4.3.4. CPUs / Architectures
4.3.5. CD-ROM / DVD-ROM Drives
4.3.6. Optical Disks
4.3.7. Keyboard and Console
4.3.8. Digital Cameras
4.3.9. Graphic Tablets
4.3.10. Diskettes
4.3.11. Hard Disks
4.3.12. Jaz and ZIP Drives
4.3.13. Mice
4.3.14. Modems
4.3.15. Printers / Scanners
4.3.16. Routers
4.3.17. SCSI
4.3.18. Serial Ports
4.3.19. Sound Cards
4.3.20. Tape Drives
4.3.21. Touchscreens
4.3.22. UPS
4.3.23. Wireless
4.3.24. Miscellaneous
4.4. Networking
4.4.1. General
4.4.2. Protocols
4.4.3. Dial-up
4.4.4. DNS
4.4.5. Virtual Private Networks
4.4.6. Bridging
4.4.7. Routing
4.4.8. Security
4.4.9. Telephony / Satellite
4.4.10. Miscellaneous
4.5. Applications / GUI / Multimedia
4.5.1. Installing Applications
4.5.2. User Applications
4.5.3. Server Applications
4.5.3.1. DBMS / Databases
4.5.3.2. Mail
4.5.3.3. Usenet Network News
4.5.3.4. HTTP / FTP
4.5.3.5. Miscellaneous
4.5.4. GUI / Window Managers
4.5.4.1. X Window System
4.5.4.2. Window Managers
4.5.4.3. Fonts
4.5.5. Multimedia
4.5.5.1. Audio
4.5.5.2. Video
4.6. Programming
4.6.1. General
4.6.2. Compilers
4.6.3. Languages
4.6.4. Libraries
4.6.5. Interfaces / API / Protocols
4.6.6. Security
4.6.7. Tools
4.6.8. Version Control
4.6.9. DBMS / Databases
4.6.10. Miscellaneous
4.7. Other (human) Languages
4.7.1. Language Support
4.7.2. Using Specific Languages
4.8. Miscellaneous
4.8.1. Authoring / Documentation
4.8.2. Linux Advocacy / Getting (and Staying) Involved
4.8.3. Hobbies and Special Interests
4.9. Archived Documents
4.9.1. Archived Documents
5. Single list of HOWTOs
6. Single list of mini-HOWTOs
7. Unmaintained HOWTOs
8. Writing and Submitting a HOWTO
9. Copyright Information


Next


What Are Linux HOWTOs?