In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Using Apache+PHP3+MySQL to build a database-driven dynamic website (transfer) [@ more@] 1. How to get the software?
There are many ways to obtain these three packages, and most Linux distributions currently bundle them, such as RedHat. The installation method described in this article is based on packages downloaded from the official site of these software, and their installation and configuration are also described for RedHat Linux 6.1s.
The official sites of the three software are:
Download the current version of the official website of the software
Apache http://www.apache.org/httpd.html 1.3.9 here
PHP http://www.php.net/ 3.0.13 here
MySQL http://www.mysql.com 3.22.29 here
From the above website, you should download 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 includes files and libraries)
MySQL-shared-3.22.29-1.i386.rpm (client shared library)
Second, install 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 3.22.29, first delete 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
When installing the MySQL server, the installer will prompt you to set the root password. For the post-installation settings of MySQL, please refer to this site.
The above installation places the MySQL execution files in the "/ usr/bin" directory, the include files in the "/ usr/include/mysql" directory, and the library files in the "/ usr/lib/mysql" directory.
Extract apache and php and compile and install
Download the apache and php source code packages as described above, add the downloaded files and put them in the directory "/ apps", enter the "/ apps" directory, and use ls to check that you have these two files:
Apache_1.3.9.tar.gz
Php-3.0.13.tar.gz
1. Extract 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 that the compressed files are placed in the apache_1.3.9 directory. Then configure apache:
Cd apache_1.3.9 (enter the directory of the apache source code tree)
. / configure-- prefix=/www (if you want to install apache and eventually install it in the directory "/ www")
2. Extract php3 and configure and compile
Cd.. (go back to the superior directory)
Tar zxvf php-3.0.13.tar.gz (extract to directory "php-3.0.13")
Cd php-3.0.13 (enter the source code directory of php3)
. / 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 to the "/ www" directory)
The above method compiles php into the apache object code, so its efficiency and performance are slightly better than the DSO approach. See the following introduction to the method of using php as a module of apache.
4. Configure apache
Cd / www (to apache home directory)
Cd conf (enter the profile directory)
Edit the "httpf.conf" file and remove the comment on the line "AddType application/x-httpd-php3 .php3" so that files with the suffix ".php3" will be treated as php script files.
5. Start apache
Turn off the running httpd (sometimes started when the system starts) and restart the new httpd:
Cd / www/bin
. / apachectl start
Use the ps aux command to verify that httpd is started correctly.
6. Testing
Lynx localhost
If you can see the page display, you have set up and started httpd correctly.
7. Test php
Cd / www/htdocs (enter the default webpage directory)
Create an ex.php3 file with the following contents:
$myvar= "Hello,World!"
Echo $myvar
Phpinfo ()
? >
Run some commands to check whether the output is "Hello,World" and the settings for the current php:
Lynx localhost/ex.php3
If so, your apache is ready to process php script files. Congratulations!
8. Test MySQL database
After installing MySQL as described above, create a mydb.dump file that contains the following:
CREATE TABLE employees (id tinyint (4) DEFAULT'0' NOT NULL
AUTO_INCREMENT, first varchar (20), last varchar (20)
Address varchar, position varchar, PRIMARY KEY (id)
UNIQUE id (id))
INSERT INTO employees VALUES (1) the Bobbies, the Smithies
'128 Here St, Cityname','Marketing Manager')
INSERT INTO employees VALUES (2) John, John, Roberts, and 45 There St
Townville','Telephonist')
INSERT INTO employees VALUES (3 recordings, braddies, pundles, Johnsons1, 34 Nowhere Blvd
Snowston','Doorman')
Then use this SQL script to create a database mydb in MySQL and type the following command under shell:
Mysql-u root-pyourpasswd mydb
Here, if you set the password of the root user after you install the MySQL, change the yourpasswd to your password, and if you do not set the password for root, remove the-p option.
After creating the above database, create a php3 script file, such as test.php3, with the following contents:
$db = mysql_connect ("localhost", "root")
Mysql_select_db ("mydb", $db)
$result = mysql_query ("SELECT * FROM employees", $db)
Printf ("First Name:% s"
", mysql_result ($result,0," first ")
Printf ("Last Name:% s"
", mysql_result ($result,0," last ")
Printf ("Address:% s"
", mysql_result ($result,0," address ")
Printf ("Position:% s"
", mysql_result ($result,0," position ")
? >
If root has a password set, add the password in $db = mysql_connect ("localhost", "root"); above:
$db = mysql_connect ("localhost", "root", "yourpasswd")
Then test the test.php3:
Lynx localhost/test.php3
The result should be:
First Name: Bob
Last Name: Smith
Address: 128 Here St, Cityname
Position: Marketing Manager
If so, it means that your php3 has been able to handle MySQL database, congratulations again!
Compile php3 into a module of apache
The above method compiles php3 into the binary code of apache, which has the advantages of simple configuration and high efficiency, but a more flexible method is to use php3 as a DSO (Dynamic Shared Object) module of apache, as detailed in the apache documentation. Here's how to compile php3 into a module of apache.
1. Configure apache
Go to the apache source directory and run the following command (assuming httpd is installed in 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
Suppose you have put it in the apache directory (remember this directory) and entered the php3 source code directory to configure and compile:
Cd php-3.0.13
. / configure-- with-apxs=/web/bin/apxs-- with-config-file-path=/web-- with-mysql
Make (compiled)
Make install (install libphp3.so)
The above configuration is to put the php3 configuration file "php3.ini" in the / web directory. You must manually copy the "php3.ini-dist" in the php3 source code directory to the / web directory, modify the httpd.conf file in the / web/conf directory, and add the following text to allow apache to support the php3 script file, which is automatically modified by the above 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 (startup)
3. Testing
You can still test with the example of the php3 script above, and if it is correct, you have installed it correctly!
How to install and configure from the RPM package
Apache, php3, and MySQL are bundled in many Linux distributions. Since MySQL itself is distributed in RPM format, its installation has been described above, and only the installation and configuration of apache and php are described below. This article is based on RedHat Linux 6.1. The designers of PHP do not recommend configuring php3 from RPM, but it will solve this problem in php4. Due to the hassle of reconfiguring and installing php from RPM, the following methods are for reference only.
1. The rpm file you need
To reconfigure and compile php, you should download the php3 source code rpm:php-3.0.12.6.src.rpm. The 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 a new rpm, you should first delete the existing php package:
Rpm-e php-imap php-ldap php-pgsql php php-manual
The following packages are required to recompile 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, goes to that directory, and configures and compiles according to the following command:
Cd / usr/src/redhat/SPECS
Vi php.spec
Edit the php.spec file, find the% build section, and add: in the options section about. / configure:
-- with-mysql=/usr
Option, which indicates that php supports MySQL databases.
% 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 the changes and rebuild the rpm package:
Rpm-bb / usr/src/redhat/SPECS/php.spec
Finally, you can 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 comment # before them:
AddModule mod_php3.c
LoadModule php3_module modules/libphp3.so
In compiling / etc/httpd/conf/srm.conf, remove the comment # on the following line:
AddType application/x-httpd-php3 .php3
In this way, httpd is treated as a php script file for files that end in .php3.
4. Test
You can use the above two examples for testing.
5. Summary
Although some Linux publishers such as RedHat have bundled the above three packages in their distribution, php's rpm package does not initially support MySQL databases. In addition, the original use of mod_php3 or mod_php is out of date, while the new format is libphp3.so, so mod_php3 or mod_php is no longer included in the binary distribution of the RedHat standard.
If you want to use the latest versions of these three software all the time, the first two methods are the most suitable.
The above only describes the installation of these three software, you must configure the security settings of php and MySQL.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.