Linux, Apache, MySQL, PHP
Created On: March 23, 2000
Last Updated: Nov 17, 2002
This page walks through the setup of Apache, PHP and MySQL on a Redhat (Fedora) Linux system. The installation is very similar on other Linux distributions. Also, since each package is open source they run almost every OS including Mac OS X and even Windows.
For complete information regarding installation, especially if there are new versions released, you should read the install notes for each of the packages.
The first assumption is you are running Linux and have it installed properly. For help with installing and configuring Linux, read some of the related links below. The installation process has become increasingly easier as it becomes a more popular and adopted platform.
For starting out with Linux, I would recommend Fedora Core. To make setup even easier, you can install most of these packages during the OS installation.
Download Packages
First download the required packages to a directory. If you are running a different
platform be sure to download the appropriate files for your platform:
- Apache download (latest: 1.3.27)
- PHP Source download (latest: 4.2.3)
- MySQL Download (latest: 3.23.53)
- Server for i386 (Redhat)
- Client programs for i386 (Redhat)
- Include files and libraries for i386 (Redhat)
- Client shared libraries for i386 (Redhat)
Extract the Apache and PHP package into that directory using
# tar xfz php_4.2.3.tar.gz
Installing MySQL
MySQL is easiest to install on Redhat systems using the RPM packages.
To install MySQL, change to the directory with the downloaded RPM
packages and use the command:
After MySQL is installed you need to set the database root password. The MySQL database system has a different set of users than your OS, these users are managed and controlled in MySQL and set the access and permissions to the database.
To set the root password use the following commanding changing
my_password to the password you want for the root user to
access MySQL.
Note: If the MySQL service is not running, you may have to start it
by hand before trying to set the password. It should start automatically when
the computer boots. The command to start MySQL is:
You can test the MySQL installation by doing the following:
# mysql mysql (connect to mysql database)
Enter Password:
mysql> SELECT * FROM user; (grab some data out of user table)
This should return the data in the user table. Type exit to leave.
The above test uses the mysql client to connect to the database called "mysql". Inside of that database is a table called "user". This table stores all of the users and permissions for MySQL, see the MySQL manual for more information on setting up permissions.
Installing Apache with PHP
The most flexible way Apache with PHP can be installed is as an Apache module.
Apache supports modules, verse compiling the functionality into the httpd binary.
This works well when you don't want to re-compile Apache each time a module is
updated. It also allows you to switch out modules easily. It may be a touch
slower as a module, but with like 3-jigaherz processor and development, who cares.
Here are the directions to install Apache and PHP in the directory /usr/local/apache
Compile Apache with DSO support
In Apache src directory (apache_1.3.27)
--enable-module=so
$ make
$ make install
Install PHP as a Module
In PHP src directory (php_4.2.3)
--with-apxs=/usr/local/apache/bin/apxs
# make
# make install
This will install Apache and then install the PHP module into the appropriate Apache directories. To load this module when Apache starts, add the following line in the apache/conf/httpd.conf file.
Configuring Apache and PHP
To configure PHP copy php.ini-dist which is in the PHP src directory to /usr/local/lib/php.ini Edit this file setting the options you wish, generally nothing needs to be edited. However, you can set various options such as a default MySQL username and password.
To configure Apache edit /usr/local/apache/conf/httpd.conf
and set the your document directory and any other Apache settings you may want.
To enable Apache and PHP to work together the following line needs to be added:
Look for this line or something similar already in the httpd.conf file and replace it with the above. Make sure to remove the # comment mark.
After editing the config file you need to restart Apache The command to restart
Apache is:
To test Apache and PHP work together create the following PHP file:
test.php in your document root.
If you did not change the DocumentRoot in the Apache config file, the default is /usr/local/apache/htdocs/, create the file there. You can load this page in your browser using the URL: http://localhost/test.php
Another good page for development to create is a phpinfo.php page. This page shows all of the PHP settings and variables. Simply create a file with the following in it:
You should now have Apache, PHP and MySQL all installed and working nicely together. To see how to write a web application using this setup check out the Web Database Tutorial.
Related Links
- Home Pages
· Fedora Core - Operating System
· Apache - Web Server
· MySQL - Database System
· PHP - Scripting Language
- Manuals
· Redhat Linux Manuals
· The Linux Installation HOWTO
· Apache HTTP Server Documentation
· MySQL Documentation
· PHP Manual