Create an Apache + PHP3 + MySQL-Driven Dynamic Website

Source: Internet
Author: User
Tags imap php software php3 file

Apache is the most widely used Web server. PHP3 is a scripting language similar to ASP. It is more advanced than Perl, and MySQL is a lightweight database system, especially for website construction. These three software are all free software and are the best way to set up database-driven dynamic websites.

This article only describes how to install the three software. For more information about programming and using PHP and MySQL, see.

1. How to obtain software?

There are many ways to obtain these three packages. Currently, most Linux distributions are bundled with these three packages, such as RedHat. The installation method described in this article is based on the software packages downloaded from the official site of these software. For RedHat Linux 6.1, it also introduces their installation and configuration.

The official site of the three software is:

Download the current version of the software Official Website

Apache 1.3.9 here

PHP here

MySQL 3.22.29 here

From the above website, you should go to the following software package:

Software file name

Apache apache_1.3.9.tar.tgz (apache source code package)

PHP php-3.0.13.tar.gz (PHP3 source code package)

MySQL MySQL-3.22.29-1.i386.rpm (MySQL Server)

MySQL-client-3.22.29-1.i386.rpm (MySQL client utility)

MySQL-devel-3.22.29-1.i386.rpm (MySQL contains files and libraries)

MySQL-shared-3.22.29-1.i386.rpm (client program sharing Library)

Ii. Install MySQL

First, check whether your system has installed MySQL:

rpm -q MySQL            rpm -q MySQL-client            rpm -q MySQL-devel            rpm -q MySQL-shared

If your version is earlier than 3.22.29 and you want to upgrade MySQL to 3.22.29, use rpm-e to delete all MySQL packages and:

rpm -i MySQL-3.22.29-1.i386.rpm            rpm -i MySQL-client-3.22.29-1.i386.rpm            rpm -i MySQL-devel-3.22.29-1.i386.rpm            rpm -i MySQL-shared-3.22.29-1.i386.rpm 

Or directly upgrade to version 3.22.29:

rpm -Uvh MySQL-3.22.29-1.i386.rpm            rpm -Uvh MySQL-client-3.22.29-1.i386.rpm            rpm -Uvh MySQL-devel-3.22.29-1.i386.rpm            rpm -Uvh MySQL-shared-3.22.29-1.i386.rpm 

When installing the MySQL server, the installer will prompt you to set the root password. For more information about the post-installation settings of MySQL, see.

The above installation puts the MySQL execution file under the "/usr/bin" directory, including the file under the "/usr/include/mysql" directory, the library files are stored in the "/usr/lib/mysql" directory.

3. Decompress apache and php and compile and install

Download the apache and php source code packages as described above, add the downloaded files to the directory "/apps", go to the "/apps" directory, and use ls to check whether you have these two files:



1. Decompress apache and configure

Use the following command to decompress apache_1.3.9.tar.gz

Tar zxvf apache_1.3.9.tar.gz

It explains how to put the compressed files in the directory apache_1.3.9. Then configure apache:

Cd apache_1.3.9 (go to the directory of the apache source code tree)

./Configure -- prefix =/www (if you want to install apache in the directory "/www)

2. Decompress php3 and configure and compile it.

Cd .. (back to the parent directory)

Tar zxvf php-3.0.13.tar.gz (extract to directory "php-3.0.13 ")

Cd php-3.0.13 (go to The php3 source code directory)

./Configure -- with-mysql -- with-apache = ../apache_1.3.9


Make install

3. Compile and install apache

Cd ..

./Configure -- prefix =/www -- activate-module = src/module/php3/libphp3.a


Make install (install apache under the "/www" Directory)

The above method is to compile php into the apache target code, so its efficiency and performance are slightly better than the DSO method. The method of using php as a module of apache is described later.

4. Configure apache

Cd/www (to apache main directory)

Cd conf (enter the configuration file directory)

Edit "httpf. conf "file, put" AddType application/x-httpd-php3. remove the comments of a row in php3 ". files with the suffix php3 "are processed as php script files.

5. Start apache

Turn off the running httpd (sometimes started at system startup) and restart the new httpd:

Cd/www/bin./apachectl start

Run the ps aux command to check whether httpd has been properly started.

6. Test

Lynx localhost

If you can see the page, it means you have set and started httpd correctly.

7. Test php

Cd/www/htdocs (go to the default webpage storage directory)

Create an ex. php3 file with the following content:

$myvar="Hello,World!";            echo $myvar;            phpinfo();            ?>

Run some column commands to check whether the output is "Hello, World" and the current php settings:

Lynx localhost/ex. php3

If yes, your apache can already process php script files. Congratulations!

8. Test the MySQL database

After installing MySQL in the above method, create a mydb. dump file, including the following content:

CREATE TABLE employees (  id tinyint(4) DEFAULT '0' NOT NULL            AUTO_INCREMENT,  first varchar(20),  last varchar(20),            address varchar(255),  position varchar(50),  PRIMARY KEY (id),            UNIQUE id (id));            INSERT INTO employees VALUES (1,'Bob','Smith',            '128 Here St, Cityname','Marketing Manager');            INSERT INTO employees VALUES (2,'John','Roberts','45 There St ,            Townville','Telephonist');            INSERT INTO employees VALUES (3,'Brad','Johnson','1/34 Nowhere Blvd,            Snowston','Doorman');

Use this SQL script to create a database mydb in MySQL and run the following command in shell:

Mysql-u root-pyourpasswd mydb

Here, if you have installed MySQL and set the root user password, replace yourpasswd with your password. If you have not set the password for root, remove the-p option.

After the above database is created, create a php3 script file, such as test. php3. Its content is as follows:

$db = mysql_connect("localhost", "root");            mysql_select_db("mydb",$db);            $result = mysql_query("SELECT * FROM employees",$db);            printf("First Name: %s            \n", mysql_result($result,0,"first"));            printf("Last Name: %s            \n", mysql_result($result,0,"last"));            printf("Address: %s            \n", mysql_result($result,0,"address"));            printf("Position: %s            \n", mysql_result($result,0,"position"));            ?>

If the password is set for the root user, add the password in $ db = mysql_connect ("localhost", "root"); above:

$ Db = mysql_connect ("localhost", "root", "yourpasswd ");

Test. php3:

Lynx localhost/test. php3

The displayed result is:

First Name: Bob            Last Name: Smith            Address: 128 Here St, Cityname            Position: Marketing Manager

If yes, your php3 has been able to process the MySQL database. Congratulations again !!

3. Compile php3 into a module of apache

The above method is to compile php3 into apache binary code, which has the advantages of simple configuration and high efficiency, however, a more flexible method is to use php3 as a DSO (Dynamic Shared Object) module of apache. For details, see the apache documentation. The following describes how to compile php3 into an apache module.

1. Configure apache

Go to the apache source code directory and run the following commands (assuming that httpd is installed under the "/web" directory)

Cd apache_1.3.9

./Comfigure -- prefix =/www -- enable-shared = max

Make (compile apache)

Make install (install apache in the/web directory)

2. Configure php3 and compile and install it

Assume that you have entered the apache directory (remember this directory) to the php3 source code directory for configuration and Compilation:

Cd php-3.0.13. /configure -- with-apxs =/web/bin/apxs -- with-config-file-path =/web -- with-mysql make (compile) make install (install

The above configuration is to put the php3 configuration file "php3.ini" under the/web directory, you must manually copy the "php3.ini-dist" under the php3 source code directory to the/web directory, modify httpd in the/web/conf directory again. conf file, add the following text to make apache support the php3 script file, which is automatically modified by make install:

AddModule mod_php3.c

LoadModule php3_module libexec/


AddType application/x-httpd-php3. php3 restart httpd:

/Web/bin/apachectl stop (stop)

/Web/bin/apachectl start (start)

3. Test

You can still use the above php3 script example for testing. If it is correct, you have installed it correctly!

4. How to install and configure the RPM package

Apache, php3, and MySQL are bundled in many Linux releases. Since MySQL is distributed in RPM format, the installation has been described above, the following describes only the installation and configuration of apache and php. This article is based on RedHat Linux 6.1. PHP designers do not recommend configuring php3 from RPM, but it will solve this problem in php4. Since re-configuring from RPM and installing php are troublesome, the following methods are for reference only.

1. the rpm file you need

To reconfigure and compile php, you should download the source code rpm of php3: php- This package generates the following rpm:

php-3.0.12-6.i386.rpm    php-manual-3.0.12-6.i386.rpm            php-imap-3.0.12-6.i386.rpm  php-ldap-3.0.12-6.i386.rpm            php-pgsql-3.0.12-6.i386.rpm

Before installing the new rpm, you should first Delete the php software package:

Rpm-e php-imap php-ldap php-pgsql php-manual

The following software packages are required to re-compile php:




2. reconfigure, compile, and install php3

Install the php3 source code package:

Rpm-I php-3.0.12-6.src.rpm

It installs the php source code in the/usr/src/redhat Directory, enters the directory, and configures and compiles the following command:


Vi php. spec

Edit the php. spec file, find the % build section, and add the following to the./configure options section:

-- With-mysql =/usr \

It indicates that php supports the MySQL database.

%build            cd imap-4.5            make RPM_OPT_FLAGS="$RPM_OPT_FLAGS" lnp            cd ..            autoconf            CFLAGS="-fPIC" ./configure --prefix=/usr            

Save the changes and recreate the rpm package:

Rpm-bb/usr/src/redhat/SPECS/php. spec

Finally, find the corresponding binary rpm packages in the/usr/src/redhat/RPMS/i386 directory and reinstall them:

Rpm-I/usr/src/redhat/RPMS/i386 /*

3. Configure httpd. conf and srm. conf.

After installing php, you should configure httpd to support php3 scripts. First, edit/etc/httpd/conf/httpd. conf, find the following two lines, and remove the annotator #:

AddModule mod_php3.c

LoadModule php3_module modules/

After compiling/etc/httpd/conf/srm. conf, remove the annotator # In the following line #:

AddType application/x-httpd-php3. php3

In this way, httpd treats files ending with. php3 as php script files.

4. Test

You can use the above two examples for testing.

5. Summary

Although some Linux publishers such as RedHat bundle the above three software packages in their distribution, php's rpm package initially does not support MySQL databases. In addition, the usage of mod_php3 or mod_php is outdated, and the new format is Therefore, mod_php3 or mod_php is not included in the binary distribution of RedHat.

If you want to keep using the latest versions of the three software, the first two methods are the most suitable.

The above only introduces the installation of these three software, you must configure the Security Settings of php and MySQL.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.