Create an Apache + PHP3 + MySQL-Driven Dynamic Website

Source: Internet
Author: User
Tags 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 introduces the installation of the three software, including

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 introduces the installation of the three software, including

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 3.0.13 here

MySQL 3.22.29

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 MySQLrpm-q MySQL-clientrpm-q MySQL-develrpm-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.rpmrpm-I MySQL-client-3.22.29-1.i386.rpmrpm-I MySQL-devel-3.22.29-1.i386.rpmrpm-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.rpmrpm-Uvh MySQL-client-3.22.29-1.i386.rpmrpm-Uvh MySQL-devel-3.22.29-1.i386.rpmrpm-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, add the downloaded files to the directory "/apps", go to the "/apps" directory, and use ls to check whether you have these two files:

Apache_1.3.9.tar.gz

Php-3.0.13.tar.gz

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

Make install

3. Compile and install apache

Cd ..

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

Make

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 NULLAUTO_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', 'ots', '45 There St, Townville ', 'telephonist '); insert into employees VALUES (3, 'bra', '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: % sn", mysql_result ($ result, 0, "first"); printf ("Last Name: % sn", mysql_result ($ result, 0, "last"); printf ("Address: % sn", mysql_result ($ result, 0, "address"); printf ("Position: % sn ", 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: BobLast Name: SmithAddress: 128 Here St, CitynamePosition: Marketing Manager

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

3. Compile php3 into a module of apache

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: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.