PHP Tutorial. Introduction to installing PHP: this is a PHP Tutorial. a detailed page for installing PHP, which describes the related knowledge, skills, experience, and some php source code.
Class = 'pingjiaf' frameborder = '0' src = 'http: // biancheng.dnbc?info/pingjia.php? Id = 326954 'Rolling = 'no'> install PHP
This chapter will follow the steps below to compile and install the following software:
* Apache v.1.3.4-the most popular Web server in the world.
* Gcc v.2.8.1 -- source from gnu c and C ++ compilers.
* MySQL v.3.220. B-gamma-databases used by many people around the world.
* PHP v.3.0.11-software mainly introduced in this book. Download the latest version from http: // www. php.net (or the image site of this site. Other steps in this chapter still apply.
* Expact -- function library used to read and process XML documents.
* Phplib-PHP function library used for session management.
* Libiodbc -- mainly used to access the ODBC function library of databases on non-UNIX computers.
* MyODBC-function libraries between PHP, iODBC, and MySQL.
Even so, this chapter does not introduce the commands required for compiling an application, but simply describes them. In short, this book focuses on introducing the PHP language rather than the C language. The compilation of each application is very clear to me. I hope every reader can compile the application without any difficulties. If you have encountered some problems, you can ask politely in an IRC channel, or you can try to solve the problem by using newsgroups (which can be accessed from a http://www.dejanews.com. However, the best help is from the PHP mail list on the http://www.php.net.
Before starting the compilation process, let's first discuss how to recover from errors. After obtaining help for errors, you can use the following command to reinitialize the source code directory:
* Rm config. cache -- almost all Linux applications use the configure command to check their systems and find information about how to crop the compilation process. The check results will be stored in a file named config. cache. If this file is removed, the configuration program will be forced to re-check the system from the beginning.
* Make distclean-all Linux applications written in C language are compiled using the make program. The make program looks for each source file to confirm whether it needs to be compiled or has already been compiled. The make distclean command can "reset" all source programs to recompile them.
* Make clean -- some applications do not support the make distclean command, instead of the make clean command. The make clean command "resets" all source programs so that they can be re-compiled.
Even if the applications to be installed do not support each of the preceding commands, it is no harm to try these commands.
Note: Red Hat v5.2 uses the glibc Library. If you download or update programs installed in this chapter from the Internet, you must know information about glibc. You can use the rpm-q glibc command to check the version number of the installed glibc Library. In the author's system, the glibc-2.0.7.29 is displayed using the rpm-q glibc command.
2.1 Basic concepts
Maybe you have never compiled a Linux application before. here, we will introduce some basic concepts to help you diagnose problems when they occur.
Tar
Tar, that is, tape archiver. it can combine several files into one and choose whether to compress them. This command was used for backup in the past to store data on tape. When a tarfile is compressed, it has a. gz suffix. when a tarfile is not compressed, it has a. tar suffix.
Gcc
Gcc is the gnu c compiler. Its job is to compile source code files that people can understand into target files that machines can understand. The C source file usually has a. c extension name, and the target file usually has a. o extension name. If compilation fails, a compilation error occurs or a syntax error occurs. In most cases, incomplete compilation is usually generated when the compiler cannot find one or more contained files. Each file contains A. h extension, which is usually used to define different system information and collect the information shared by multiple. c files.
Make
Make is a common tool program used for compilation. It only compiles source files that have not been compiled. Compile. the c file will generate. o file, if. c file ratio. o file update, that is, the source file has been edited before the previous compilation, then make will re-compile. c file. The make command is generally used to find a Makefile file that contains one or more executable targets. for example, make clean tells make to clear the targets.
Ld
Ld is a GNU link program. It links all target files and libraries to create a single executable file. Fortunately, you don't need to run this program manually, because Makefile will take into account all the compilation details.
Ldconfig
Ldconfig searches for shared libraries in multiple library directories (specified in/etc/ld. so. conf. A shared library is often used by multiple applications. the file name contains. so. for example, libqt. so.1.42 is a shared library. After compilation, you may need to add a directory in the/etc/ld. so. conf file and run the ldconfig-v command.
./Configure
Configure will find some key information in the computer, such as which C compiler is installed and where the file is. Configure then modifies the Makefile according to the computer configuration. Use./configure to run programs in the current directory to avoid accidental running of other programs in the $ PATH environment variable.
Symbolic connection
Symbolic connections allow users to specify a different name for an existing file. For example, you may want to call a file named libqt. so.1.42 libqt. so.1. The symbolic connection allows you to copy a file to another directory, but the file is not actually copied. The second file instance simply points to the first file instance. Symbolic connections can have at least two advantages. The first point is that symbolic connections can save hard disk space, up to 16 bytes. The second point is a bit subtle. let's take a look at the next one called libqt. so.1 and points to libqt. so.1.42. What should I do if I need to upgrade to libqt. so.1.88? You only need to change the symbolic connection to point libqt. so.1 to libqt. so.1.88, rather than libqt. so.1.42. This means that the program involving libqt. so.1 will automatically use the new version of this library. By convention, symbolic connections are often used for the complete release version number. In other words, libqt. so.1.88 and libqt. so.2.32 should have two different Dynamic Connections (libqt. so.1 and libqt. so.2 respectively ).
2.2 preparations before compilation
The following steps prepare the system for compilation.
1. mkdir/usr/local/src -- I chose the/usr/local tree as the root directory of the installed application. Others may choose the/usr/opt,/opt, or/var directory. For more convenient operations according to the instructions in this chapter, select the/usr/local directory as the root directory. After compilation, you can copy these files to different directories.
Note: to complete other steps in this chapter, you must have the root permission.
2. cd/usr/local/src -- go to the source file directory.
3. download the following files (which can be downloaded from http://www.mtolive.com/phpbook ), or copy these files to the/usr/local/src directory from the disc that is randomly attached to the book:
. Apache_1.3.4.tar.gz
Gcc-2.8.1.tar.gz
Mysql-3.22.16b-gamma.tar.gz
Php-3.0.11.tar.gz
. Expat.tar.gz
. Phplib.tar.gz
Libiodb-2.50.3
Myodbc-2.50.24-src
4. decompress the above files using the tar command. Upload file name.
Tar xvzf apache_1.3.4.tar.gz
Tar xvzf gcc-2.8.1.tar.gz
Tar xvzf mysql-3.22.16b-gamma.tar.gz
Tar xvzf php-3.0.11.tar.gz
Tar xvzf expat.tar.gz
Tar xvzf phplib.tar.gz
5. gcc-v
Determine the current gcc version in the system. If your system is not v2.7.2.3, replace v.2.7.2.3 with your gcc version number in the following procedure.
6. cp 'which gcc '/usr/bin/gcc-2.7.2.3
If necessary, back up the existing gcc for later use. Another advantage of Linux is that it is easy to store multiple versions of a program under a directory.
7. httpd-v
Determine the Apache version number in the system. If Apache in your system is not v1.3.4, replace v1.3.4 with your version number in the following operation steps.
8. mv 'which httpd '/usr/sbin/httpd-1.3.4
If necessary, back up the existing Apache for later use.
2.3 compile C compiler gcc
The first program to be installed and compiled by the user is the C compiler. The C compiler that comes with Red Hat v5.2 is gcc v2.7.2.3. due to its low version, PHP cannot be compiled correctly. However, gcc v.2.7.3 can be used to compile gcc v2.8.1 with a higher version.
To compile a new version of gcc, run:
1. cd/usr/local/src/gcc-2.8.1
Go to the gcc top-level Directory.
2../configure-prefix =/usr/local/gcc
Run the configuration program and force the installer to use/usr/local/gcc as the gcc installation directory.
3. make bootstrap versions ages = "c ++" BOOT_CFLAGS = "-g-02"
Compile the new C and C ++ compilers.
4. make install versions ages = "c ++" BOOT_CFLAGS = "-g-02"
Install the new C and C ++ compilers.
5. mv/usr/local/gcc/bin/gcc/usr/local/gcc/bin/gcc-2.8.1
Rename the new gcc compiler so that its name contains the version number.
6. ln-s \
/Usr/local/gcc/bin/gcc-2.8.1 \
/Usr/bin/gcc-
Create a symbolic connection/usr/bin/gcc for the newly compiled gcc executable file.
7. gcc-v
The gcc version is displayed. If both compilation and installation are normal, v.2.8.1 is displayed.
2.3 compile MySQL
Compile MySQL now. After compilation, you can use the MySQL application to test the installation.
1. cd/usr/src/mysql-3.22.16a-gamma
Go to the MySQL top-level Directory.
2../configure -- prefix =/usr/local/mysql
Run the configuration program and force the installation program to use/usr/local/mysql as the installation directory of MySQL.
3. make
Compile MySQL.
4. make install
Install MySQL.
5. echo "/usr/local/mysql/lib/mysql">/etc/ld. so. conf
Add the Directory of the MySQL database to the configuration file. In this way, when Linux starts or executes the ldconfig command, the library file will be searched in the directory of the configuration file.
6. ldconfig-v | grep libmysqlclient
The ldconfig command can read the directories listed in the/etc/ld. so. conf file and buffer the library files found in those directories. The grep command searches for MySQL database files in a large number of output results of the ldconfig command and displays the restricted text in a similar way as follows:
Libmysqlclient. so.6 => libmysqlclient. so.6.0.0.
7. echo "/usr/local/mysql/bin/safe_mysqld>/dev/null &">/etc/rc. d/rc. local
Add the MySQL startup command to the/etc/rc. d/rc. local file, so that MySQL runs automatically every time Linux is started.
8 ../scripts/mysql_install_db
Initialize the database.
9./usr/local/mysql/bin/safe_mysqld>/dev/null &
Start the MySQL server as the background program. to test the installation, the MySQL server must be started.
10. ln-s \
/Usr/local/mysql/bin/mysql \
/Usr/bin/mysql
I prefer to create a symbolic link for the installation directory under the/usr/bin directory. This method reduces the number of directories in the PATH environment variable and hides MySQL tool programs that do not require others to run (for example, mysqladmin command ). Another method is to place the command PATH = "$ PATH:/usr/local/mysql/bin" in the/etc/profile file. Both methods can be used.
11. ln-s \
/Usr/local/mysql/bin/mysqlshow \
/Usr/bin/mysqlshow
This command allows general users to run the mysqlshow command.
2.4 test MySQL
Before compiling Apache and PHP, first test whether MySQL is successfully installed. The officially released MySQL comes with many useful tools. here we only use the mysql and mysqlshow commands for testing. (Do not worry if you are not familiar with the database. the concepts of databases such as users, tables, and records will be introduced in Chapter 6 "databases and SQL .)
Mysqladmin is used to create and delete databases, check the SQL status, and for other purposes. First, check the version number to check whether MySQL has been correctly installed:
> PATH = "usr/local/mysql/bin: $ PATH"
> Mysqladmin version
Ver 7.8 Distrib 3.2g0a-gamma, for pc-linux-gun on i686 TCX Datakonsult AB, by Monty
Server version 3.22.16a-gamma
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket/tmp/mysql. sock
Uptime: 2 hours 30 min 39 sec
Threads: 1 Questions: 7 Slow queries: 0
Opens: 6 Flush tables: 1 Open tables: 2
Run the following command to view all functions of mysqladmin.
Mysqladmin -- help | less
Perhaps mysqlshow is a more exciting tool that lists database, table, and field names, as shown below:
Listing 2.1 mysqlshow -- display a list of database, table, and field names
Page 18 (13th rows)-19 (10th rows), listing 2.1
The MySQL tool is mysql, which goes deep into the MySQL center and allows you to execute SQL statements immediately at the prompt of the Linux command line. Run mysql in shell mode.
Page 19 (last 5th rows)-20 (last 5th rows)
Be careful: use the password () function to set the password. For more information, see the MySQL documentation.
Be careful: when the system enters normal working mode, select a better root password than "password.
2.5 compile iODBC and MyODBC
IODBC is a function library that implements Open Database connectivity. It is mainly used to connect to the database engine running on Microsoft Windows.
1. cd/usr/local/src/libiodbc-2.50.3
Go to the iODBC directory.
2../configure \
-- Prefix =/usr/local/iodbc \
-- With-iodbc-inidir =/usr/local/etc
Run the configuration program and set iODBC to the/usr/local/iodbc directory. In addition, check that the odbc initialization file is/etc/odbc. ini.
3. make
4. make install
Copy the library file to the/usr/local/iodbc/lib directory, and copy the included files to the/usr/local/iodbc/include directory.
5. cd/usr/local/src/myodbc-2.50.24
Go to the MyODBC directory.
6 ../configure \
-- Prefix =/usr/local/myodbc \
-- With-mysql-sources =/usr/local/mysql-3.22.16a-gamma \
-- With-odbc-ini =/etc/odbc. ini \
-- With-iodbc =/usr/local/iodbc
Run the MyODBC configuration program.
7. make
8. make install
Copy the database to the/usr/local/myodbc/lib directory.
2.6 compile PHP
Compiling PHP is more complex than compiling previous applications, because compiling PHP is actually a combination of expat, Apache, and PHP. The compiled results will generate an Apache version with PHP. To compile PHP, follow these steps:
1. cd/usr/local/src/expat
Go to the expat Directory.
2. make
Compile the expat source file.
3. add the following command to the Makefile file. you must ensure that the Tab key is used before entering ar and ralib.
Libexpat. a: $ (OBJS)
Ar-rc $ @ $ (OBJS)
Ranlib $ @
4. make libexpat.
Combine the expat target file into a library file.
5. mv libexpat. a/usr/local/lib
Find the libexpat. a file in the/usr/local/lib Directory of the PHP configuration file. Moving the libexpat. a file to a directory known to the PHP configuration file can reduce the trouble for future operations.
6. cd/usr/local/src/php-3.0.11
Go to the top-level directory of PHP.
7. mkdir/usr/local/include/xml
Check whether the/usr/local/include/xml directory exists.
8. ln-s \
/Usr/local/src/expat/xmltok. h \
/Usr/local/include/xml/xmltok. h
Why do I need to copy a symbolic connection?
9. ln-s \
/Usr/local/src/expat/xmlparse. h \
/Usr/local/include/xml/xmlparse. h
This is another inclusion file required by PHP to be correctly compiled.
10. cd/usr/local/src/apache_1.3.4
Go to the Apache top-level Directory.
11 ../configure-prefix =/usr/local/apache
Run the configuration program and set the installation directory of Apache to/usr/local/apache.
12. cd/usr/local/src/php-3.0.11
Go to the top-level directory of PHP.
13 ../configure \
-- With-apache = ../apache_1.3.4 \
-- With-iodbc =/usr/local/iodbc \
-- With-mysql =/usr/local/mysql \
-- With-xml
Run the configuration program and tell the configuration program to support Apache, MySQL, and XML.
14. make
Compile the PHP source file.
15. make install
Install compiled files. The PHP library files will be placed under the Apache module directory, so that they can be found during Apache compilation.
16. cd/usr/local/src/apache_1.3.4
Go to the Apache top-level Directory.
17 ../configure \
-- Prefix =/usr/local/apache \
-- Active-module = src/modules/php3/libphp3.a
Configure Apache again and tell Apache to load the PHP module this time.
18. make
Compile the Apache source file.
19. make install
Install compiled files.
20. mv \
/Usr/local/apache/bin/httpd \
/Usr/local/apache/bin/httpd-1.3.4
Rename the newly created httpd executable file to install multiple versions.
21. ln-s \
/Usr/local/apache/bin/httpd-1.3.4 \
/Usr/sbin/httpd
Create a symbolic link pointing to a new executable file.
22. httpd-v
Confirm access to the new executable file. The command execution result will display Version 1.3.4, and the creation date should be correct.
23. edit the/usr/local/apache/conf/http. conf file, search for AddType, and confirm that the following lines are not annotated.
AddType applications/x-httpd-php3. phtml
AddType application/x-httpd-php3. php3
AddType application/x-httpd-php3-source. phps
24. edit the/usr/local/apache/conf/http. conf file, search for DirectoryIndex, and put index. php3 at the end of the row.
25. create a file named/usr/local/php3.ini that contains the following command line:
Export de_path =.:/usr/local/apache/php/
Auto_prepend_file =/usr/local/apache/php/prepend. php3
Track_vars = on
Magic_quotes_gpc = on
Sendmail_path/usr/sbin/sendmail-t
26. ln-s \
/Usr/local/src/php-3.0.11/doc/manual.html \
/Usr/local/src/php-3.0.11/doc/index.html
Create a symbolic link so that most Web browsers automatically display the php file start page correctly.
27. ln-s \
/Usr/local/src/php-3.0.11/doc \
/Usr/local/apache/htdocs/phpdocs
Create a symbolic link to access the PHP document through http: // localhost/phpdocs.
28. create a file named/usr/local/apache/htdocs/robots.txt to avoid indexing the PHPLIB, phpMyAdmin, and PHP files by the search engine, the newly created file should include the following setting lines:
#Robots.txt for (hostname)
User-agent *
Disallow:/phpdocs/
Disallow:/php/
Disallow:/phpMyAdmin/
2.7 install PHPLIB
Install PHPLIB before reading chapter 15th "processing concurrent access". you can follow the steps below to install PHPLIB:
1. register with the root user or any other user who can write files in the/usr/local/apache directory.
2. cd/usr/local/apache/
Before downloading files, go to the top-level Directory of the Web server.
3. download the latest file from the Web site, and upload the file name with the gzsuffix, with the free file name phplib.tar.gz changed.
Http://phplib.shonline.de/
4. tar xv2f phplib.tar.gz
Decompress the PHPLIB module.
5. edit the/usr/local/lib/php3.ini file, which includes the following settings:
Export de_path =.:/usr/local/apache/phplib-6.1/php
Auto_prepend_file =/usr/local/apache/phplib-
6.1/php/prepend. php3
Track_vars = on
Magic_quotes_gpc = on
Sendmail_path/usr/sbin/sendmail-t
6. create a mysql database named poe_sessions. I usually use phpMyAdmin. if you want to, you can also use SQL commands to create a database.
6. cd/usr/local/apache/phplib-6.1/stuff
Go to the table creation directory.
8. mysql php_book -- user = root -- password <
Create_database.mysql
Create the database table required by PHPLIB.
9. add a new record in the mysql database table using the following values:
Host: %
Password: <-- no password.
Select_priv: Yes
Insert_priv: Yes
Update_priv: Yes
Delete_priv: Yes
For users named "kris", "user01", and "user02 ".
Note: You can also use the following SQL statement:
INSERT
User
(
Host
, User
, Password
, Select_priv
, Insert_priv
, Update_priv
, Delete_priv
)
VALUES (
'%'
, 'Kris'
,'
, 'Y'
)
10. use the following values to add a new record to the mysql database table:
Host: %
Db: poe_sessions
Select_priv: Yes
Insert_priv: Yes
Update_priv: Yes
Delete_priv: Yes
For users named "kris", "user01", and "user03 ".
Note: You can also use the following SQL program.
INSERT
Db
(
Host
, Db
, User
, Select_priv
, Insert_priv
, Update_priv
, Delete_priv
)
VALUES (
'%'
, 'Poe _ session'
, 'Kris'
, 'Y'
)
11./usr/local/mysql/bin/mysqladmin-u root-p reload
Reload the MySQL permission table.
12. create two PHPLIB authenticated users (user01 and user02) in the php_book database and use the following SQL statement:
INSERT
Auto_user
(
Uid
, Username
, Password
, Perms
) VALUES (
'C14cbf141ab1b7cd009356f555b1234'
, 'User01'
, 'Test'
, 'Admin'
)
INSERT
Auth_user
(
Uid
, Username
, Password
, Perms
) VALUES (
'C14cbf141ab1b7cd009356f555b3241'
, 'User02'
, 'Test'
, 'Admin'
)
13. mv \/use/local/apache/phplib-6.1/pages \
/Use/local/apach/htdocs
Place the demo subdirectory in the root directory of the Web server so that you can access it in a browser.
14. edit the text file/usr/local/apache/htdocs/robots.txt to include the following content:
Disallow:/phplib/
15. use a Web browser to access http: // localhost/phplib /. The page shown in 2.1 is displayed.
Page 29. 1
. 1. reload the PHPLIB demo page that appears after two times
2.8 test ODBC in Linux
It is important to perform basic tests on the installed software, especially when you need to manually edit the configuration file. The following test ensures that the MySQL driver runs properly and the compiled iODBC library file is correct.
1. use the content listed in listing 2.1 to create a file named/usr/local/etc/odbc. ini.
Configuration 2.2/usr/local/etc/odbc. ini-system ODBC configuration file
;
; Odbc. ini
;
[ODBC Data Sources]
Mysql = mysql
[Php_book]
Driver =/usr/local/myodbc/lib/libmyodbc. so
Host = localhost
Database = mysql
User = root
2. cd/usr/local/src/libiodbc-2.50.3/samples
3./odbctest
Run the ODBC test program.
4. DSN = mysql; PWD = password
The data source to be accessed by the test program.
5. select host, user from user
Execute an SQL statement at the prompt. if there is a response, it means that iODBC and MySQL are ready to use.
ODBC has been installed on the computer. since the installation steps are not clear and there are few documents, this chapter describes its installation and test commands, however, since ODBC is mainly a Microsoft technology and rarely used in Linux, this is the last introduction in this book.
2.9 conclusion:
This chapter describes how to obtain PHP and how to install it on a computer. it compiles a specific version of Apache server with built-in PHP. At the same time, it also installed the PHPLIB that will be used in Chapter 4 "midfield 4: processing concurrent access.
"PHP Tutorial. install PHP" more articles
Love J2EE follow Java Michael Jackson video station JSON online tools
Http://biancheng.dnbcw.info/php/326954.html pageNo: 13.