web blazonry web development scripts and tutorials Get best price on Unlocked Galaxy S20 5G
   PHP       Name Generators       Perl       CSS       Javascript       Java       MySql       How Tos       Resources   

How Tos Home

Free Linux Books
  Programming for Linux
  Sys & Network Admin
  On the Desktop

Articles
Tech Tips for Picking a Web Host

Database Tutorial (PHP & MySQL)

How to Instal Apache + PHP + MySQL

PHP vs. ASP vs. JSP

Introduction to Debugging

MySQL JDBC Drivers

Overview of Client Side

Margins Flush with Edges of Browser

Specifying Alternate Document to Print

Web App Security
  Who Submit That?
  Cookie Security
  Passwords
  Secure Web Development

Bookmark and Share





How To Install Apache + PHP + MySQL

This tutorial discusses the setup of Apache, PHP and MySQL for both Windows and Red Hat Linux.

Because the install for Windows is straightforward, the discussion for Windows is an overview. The tutorial and how to for Red Had Linux is much more detailed and covers both downloading and installing packages as well as using Apache's DSO Module.

Overall, more people ask about installing Apache, PHP and MySQL on their local Windows computer because their web hosting company takes care of the install on their web server. A common set-up for web site programmers is their localhost environment is Windows and the web server is Linux. This is an effective set-up.


Installing Apache, PHP, MySQL on Windows Computers

Installation of Apache, PHP and MySQL is straightforward for Windows computers.

Go to each of the Apache, PHP and MySQL sites to download the software. Select the appropriate ZIP file. Pick the versions that match your web server.

You will have to modify your ini and configuration files as described in the install READMEs, but you do not have to worry about DSO modules, compiling, etc. as discussed for Linux below. I have omitted detailed discussion of changes to local files because different versions of PHP, MySQL and Apache have different requirements.

Most web sites are hosted on a web server that hosts many sites. In most cases your site will be hosted with standard PHP, MySQL, Apache configurations. On your localhost (your own computer), you should not deviate too far from the configuration of your web hosting server. Otherwise, you will find yourself in the common programmer situation of saying ”well it works on my machine.” (More help about this subject is in my web hosting for developers article.)

One of the great things about PHP and MySQL is many web hosting companies provide them at reasonable prices. So, install Apache, PHP and MySQL on your machine, write some code test it and upload it to a real web server for all the world to see.

Installing Apache, PHP, MySQL for Red Hat Linux

Installation is similar on other Linux distributions. The tutorial below covers two approaches. The first discussed is downloading and installing packages. How to use Apache's DSO Module is discussed second.

The following tutorial was written for then current (year 2000) versions. For complete information regarding installation, especially if there are new versions released, you should read the install notes for each of the packages.

This tutorial assumes you are running Linux and it is installed properly. For help with installing and configuring Linux check out some of the related links at the bottom of this page.


Download the Packages

First download the required packages to a directory. If you are running a different platform be sure to download the appropiate files for your platform:

Extract the Apache and PHP package into that directory using

# tar xfz apache_1.3.14.tar.gz
# tar xfz php_4.0.3pl1.tar.gz

Note: The pound sign # is the system prompt. You type in only what is after it .


Installing MySQL

MySQL is easiest to install on Red Hat systems using the RPM packages. To install MySQL in the same directory as the RPM packages use the command:
# rpm -Uvh *.rpm

Note: You most likely need to do this as the root user. Either log in or su to root.

After MySQL is installed you need to set the root password. To do this use the following commanding changing my_password to the password you want for the root user to access MySQL.

# mysqladmin -u root password 'my_password'

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:

# /etc/rc.d/init.d/mysqld start

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.


Installing Apache with PHP

Apache with PHP can be installed a few different ways. One way is to statically embed the PHP binary into the Apache binary. This is probably the fastest and best way to run PHP. You can also install PHP as a DSO module (see below)

Here are the step by step directions to install Apache and PHP in the directory /usr/local/apache

In Apache src directory (apache_1.3.14/)
# ./configure --prefix=/usr/local/apache


In PHP src directory (php-4.0.3pl1/)
# ./configure --with-mysql \
    --with-xml \
    --enable-track-vars \
    --with-apache=../apache_1.3.14 \

# make
# make install

In Apache src directory (apache_1.3.14)
# ./configure --prefix=/usr/local/apache \
    --enable-module=rewrite \
    --activate-module=src/modules/php4/libphp4.a

# make
# make install

This will install Apache in the /usr/local/apache directory. The only thing left to do is to configure them.


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:

AddType application/x-httpd-php .php

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:

/etc/rc.d/init.d/httpd restart

To test that Apache and PHP work together, create a PHP file. Name it test.php. The entire contents of the file are:

<?php
echo("<h1>Yay! PHP and Apache Work!</h1>");
?>

Copy this file to the document directory, if you did not change the document directory in the config file (httpd.conf) then the default document directory is /usr/local/apache/htdocs/ Load this page in your browser by using the following URL: http://localhost/test.php

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 my Web Database Tutorial.


Installing Apache and PHP Using Apache's DSO Module

Another way to install Apache and PHP is by using Apache's DSO module. Apache supports adding modules on instead of embedding them in the httpd binary. This works well when you don't want to re-compile Apache each time a module is updated, or if you want to add on numerous modules for development purposes.

Compile Apache with DSO support
In Apache src directory (apache_1.3.14)

# ./configure --prefix=/usr/local/apache \
    --enable-module=so
    --enable-module=rewrite

$ make
$ make install

Install PHP as a Module
In PHP src directory (php_4.0.3pl1)

# ./configure --with-mysql \
    --with-xml \
    --enable-track-vars \
    --with-apxs=/usr/local/apache/bin/apxs

# make
# make install

This will install Apache and then install the PHP module into the appropiate Apache directories. The only difference in configuration from above is the module needs to be added in the Apache httpd.conf file. To add a module in Apache add the following line in the httpd.conf file (if it is not already there, sometimes the install script adds it for you)

LoadModule php4_module libexec/libphp4.so

Be sure to following the rest of the configuration instructions above.



Related Links for Apache, PHP, MySQL

Free Linux Books
  Programming for Linux
  System & Network Administration
  Linux On the Desktop

Three Apache Administration Books I Own:

Linux Apache Web Server Administration, Second Edition (Craig Hunt Linux Library) Linux Apache Web Server Administration, Second Edition (Craig Hunt Linux Library)





Red Hat Linux Administration Red Hat Linux Administration: A Beginner's Guide
I was initially turned off by the title, but discovered that this
book assumes a good working knowledge of computers and level
of technical expertise.



Hacking Exposed Linux, 2nd Edition Hacking Exposed Linux, 2nd Edition
I was impressed with the rave reviews this book gets.





Apache, PHP, MySQL Downloads & Resources


 

Newest Pages
Test Google Ads Ver. 2
Free Linux Admin Books
Free Linux Books for Programmers
Free Books for Linux on the Desktop
Free PHP Books
Free JavaScript Books
Free Java Books - Advanced
Free Java Books - Basic
Free Perl Books
Free Python Books
Quote of the Day (PHP)
Debugging Part 2
How to Test Google Ads
Most Popular Pages
Baby Name Generator
U.S. Name Generator
Wu Name Generator
Popup Windows (JavaScript)
Upload and Resize an Image (PHP)
How To Install Apache + PHP + MySQL
Intro to Web Databases (PHP, MySQL)

Least Popular Pages
iNews Applet (Java)
Java Resources
Site Monitor (Perl)
PHP Resources
 
 

  privacy policy     ||     © 1997-2016. astonishinc.com   All Rights Reserved.