Create an Apache + PHP + MySQL database-driven dynamic website

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

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 Customer Utility Program )

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:

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 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 @ #, @ # Robert ts @ #, @ #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 (Compilation)

Make install (install libphp3.so)

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/libphp3.so

And

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-3.0.12.6.src.rpm. 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:

Apache APACHE-devel

PostgreSQL postgresql-devel

Mysql-devel

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:

CD/usr/src/RedHat/specs

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 \

-- With-apxs =/usr/sbin/apxs \

-- With-config-file-Path =/etc/httpd \

-- Enable-safe-mode \

-- With-Exec-Dir =/usr/bin \

-- With-system-RegEx \

-- Disable-Debug \

-- With-zlib \

-- Enable-debugger \

-- Enable-magic-quotes \

-- With-mysql =/usr \

-- Enable-track-vars

Save and modify 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 to find the following two lines and remove the annotator #:
addmodule mod_php3.c
loadmodule php3_module modules/libphp3.so
compile/etc/httpd/CONF/SRM. conf, remove the annotation of the following line #:
addtype application/x-httpd-php3. php3
in this way, httpd. the file ending with php3 is considered a PHP script file.
4. Test
you can use the following two examples for testing.
5. Summary
some Linux publishers, such as RedHat, bundle these three software packages in their distribution, however, the RPM package of PHP initially does not support MySQL databases. In addition, the usage of mod_php3 or mod_php is outdated, and the new format is libphp3.so. 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 preceding section describes the installation of the three software. You must configure the security settings for PHP and MySQL.

Related Article

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.