Establish Apache+php+mysql database-driven Dynamic website _ server

Source: Internet
Author: User
Tags install php imap mysql client mysql in php and php and mysql unique id web hosting

This article only describes the installation of these 3 software, for PHP and MySQL programming and use see other information.

How do I get the software?
There are many ways to get these 3 packages, and most Linux distributions are now bundled with these 3 packages, such as Redhat. The installation method described in this article is based on downloaded packages from the official site of these software, and also describes their installation and configuration for Redhat Linux 6.1.
The official sites for these 3 software are:
Software official website current version download
Apache 1.3.9 Here
PHP 3.0.13 Here
MySQL 3.22.29 Here
From the above website, you should be under the following 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 shared library)
Second, the installation of MySQL
First check to see if your system has MySQL installed:
Rpm-q MySQL
Rpm-q mysql-client
Rpm-q Mysql-devel
Rpm-q mysql-shared
If your version is older than 3.22.29 and you want to upgrade MySQL to version 3.22.29, first remove all MySQL packages with rpm-e 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 upgrade directly 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
Install the MySQL server, the installer prompts you to set the root password, for MySQL installation post setup, see.
The above installation will be the MySQL execution file in the "/usr/bin" directory, include files in the "/usr/include/mysql" directory, the library file in the "/usr/lib/mysql" directory.
Three, unzip Apache and PHP and compile and install
As mentioned above, download the Apache and PHP source code packages, add the downloaded files in the directory "/apps", enter the "/apps" directory, with LS Check you have these two files:
1. Unzip Apache and configure
Extract the apache_1.3.9.tar.gz with the following command
Tar zxvf apache_1.3.9.tar.gz
It explains the compressed files in the apache_1.3.9 directory. Then configure Apache:
CD apache_1.3.9 (directory that goes into the Apache source code tree)
./configure--prefix=/www (if you want to install Apache finally installed in the directory "/www")
2. Decompress php3 and configure and compile
Cd.. (Return to Superior directory)
Tar zxvf php-3.0.13.tar.gz (Unzip to directory "php-3.0.13")
CD php-3.0.13 (Directory of source code entering PHP3)
./configure--with-mysql--with-apache=. /apache_1.3.9
Make install
3. Compiling and installing Apache
Make install (Install Apache to the "/www" directory)
The above method is to compile PHP into the Apache target code, so its efficiency and performance than the DSO way slightly better. The method of PHP as a module of Apache, see the following introduction.
4. Configure Apache
CD/WWW (to Apache home directory)
CD conf (enter profile directory)
Edit the "httpf.conf" file to remove the comment from the "AddType application/x-httpd-php3. PhP3" line, so that the file with the last suffix ". PhP3" will be processed as a PHP script file.
5, start Apache
Turn off the running httpd (sometimes started at system startup) and restart the new httpd:
./apachectl Start
Use the PS aux command to check that the httpd has started correctly.
6, testing
Lynx localhost
If you can see the page display, you have correctly set up and started the httpd.
7. Test PHP
Cd/www/htdocs (enter Default Web hosting directory)
Create a EX.PHP3 file that reads as follows:

$myvar = "hello,world!";
Echo $myvar;
Phpinfo ();

Run some column commands to check if the output is "Hello,world" and the current PHP settings:
If so, it means your Apache can already handle PHP script files. Congratulations to you!
8. Test MySQL Database
After installing MySQL in the above method, create a Mydb.dump file containing the following contents:
CREATE TABLE Employees (ID tinyint (4) DEFAULT @ #0 @# not NULL
auto_increment, varchar, last varchar (20),
Address varchar (255), Position varchar, PRIMARY KEY (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 @#);

Then use this SQL script to create a database mydb in MySQL with the following command under the shell:
Mysql-u root-pyourpasswd MyDB
Here, if you set the root user password after the installation of MySQL, yourpasswd to your password, if not set the password for root, then remove the-p option.
After creating the above database, create a php3 script file, such as TEST.PHP3, which reads as follows:

$db = mysql_connect ("localhost", "root");
mysql_select_db ("MyDB", $db);
$result = mysql_query ("SELECT * FROM Employees", $DB);
printf ("Name:%s
\ n ", mysql_result ($result, 0," a "));
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 root sets the password, the $DB = mysql_connect ("localhost", "root") is added to the above:
$db = mysql_connect ("localhost", "root", "yourpasswd");
Then test test.php3:
The results of this display should be:
The Name:bob
Last Name:smith
address:128 here St, CityName
Position:marketing Manager
If it is, your php3 has been able to handle the MySQL database, congratulations again!!

C. Compile php3 into a module of Apache
The above method is to compile the php3 into Apache binary code, the advantage is simple configuration, high efficiency, but a more flexible approach is to PHP3 as a DSO (Dynamic Shared Object) module, as described in the Apache document. Here's how to compile php3 into one of Apache's modules.
1. Configure Apache
Enter the Apache source code directory and run the following command (assuming the httpd is installed under the "/web" directory)
CD apache_1.3.9
Make (Compile Apache)
Make install (install Apache in/web directory)
2. Configure php3 and compile and install
Assume that you have the Apache directory (please remember this directory), into the PHP3 source directory for configuration and compilation:
CD php-3.0.13
Make (compiled)
Make install (install
The above configuration is to put the php3 configuration file "Php3.ini" in the/web directory, you must manually php3 source directory under the "Php3.ini-dist" copy to the/web directory, modify/web/ The httpd.conf file in the Conf directory, add the following text so that Apache supports the PhP3 script file, which is automatically modified by the make install:
Addmodule mod_php3.c
LoadModule Php3_module libexec/
AddType application/x-httpd-php3. php3
Reboot httpd:
/web/bin/apachectl Stop (STOP)
/web/bin/apachectl Start (start)
3, testing
You can still use the example above to test the php3 script, if correct, you have installed correctly!

Iv. How to install and configure from the RPM package
In many Linux distributions are bundled with Apache, PhP3 and MySQL, because MySQL itself is distributed in the RPM format, so its installation has been described above, the following is only the Apache and PHP installation and configuration. This article is based on Redhat Linux 6.1. The PHP Designer does not recommend php3 from the RPM configuration, but it will solve the problem in PHP4. Since it is cumbersome to reconfigure and install PHP from RPM, the following methods are for informational purposes only.
1, you need the rpm file
In order to reconfigure and compile PHP, you should download the PHP3 source code rpm:php- The package can generate 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
Before installing the new RPM, you should first delete the PHP packages you already have:
Rpm-e php-imap php-ldap php-pgsql php php-manual
recompiling PHP requires the following packages:
Apache Apache-devel
PostgreSQL Postgresql-devel
2, reconfigure, compile and install PhP3
To 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, configures and compiles according to the following command:
VI Php.spec
Edit the Php.spec file, find the%build section, and Add in the Options section about./configure:
option, which indicates that PHP supports the MySQL database.
CD imap-4.5
Make rpm_opt_flags= "$RPM _opt_flags" LNP
Cflags= "-fpic"./configure--prefix=/usr \
--enable-safe-mode \
--with-exec-dir=/usr/bin \
--with-system-regex \
--disable-debug \
--with-zlib \
--enable-debugger \
--enable-magic-quotes \

Save changes, rebuild RPM package:
Finally, the corresponding binary RPM packages can be found in the/usr/src/redhat/rpms/i386 directory to reinstall them:
3. Configure httpd.conf and srm.conf
After installing PHP, you should configure HTTPD to support PHP3 scripts. First edit the/etc/httpd/conf/httpd.conf, find the following two lines, and remove the previous annotation symbol #:
Addmodule mod_php3.c
LoadModule Php3_module modules/
In compiling/etc/httpd/conf/srm.conf, remove the following line of annotation characters #:
AddType application/x-httpd-php3. php3
In this way, httpd is treated as a PHP script file for a file ending with. php3.
4, testing
You can use the above two examples to do the test.
5, summary
Some Linux publishers, such as Redhat, have bundled the three packages in their distribution, but PHP's RPM package was initially unsupported by MySQL databases. In addition, the original use of mod_php3 or mod_php is obsolete, and the new format is, so no mod_php3 or mod_php is already included in the Redhat standard binary distribution.
If you want to use the latest version of these three software all the time, the first two methods are most appropriate.
The above only describes the installation of these three software, you must configure the PHP and MySQL security settings
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: 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.