Keywords installation tutorials files compiling directories one can use commands programs
Install PHP
This chapter compiles and installs the following software as follows:
* Apache v.1.3.4-The world's most popular web server.
* GCC v.2.8.1--from the GNU C and C + + compilers.
* MySQL V.3.22.16b-gamma-a database used by many people around the world.
* PHP v.3.0.11-The main software introduced in this book. A newer version can be obtained from the direct download of http://www.php.net (or the mirror site of this site). The other steps in this chapter still apply.
* Expact--Library of functions for reading and processing XML documents.
* Phplib--PHP function library for session management.
* LIBIODBC--the ODBC function library used primarily for accessing databases in non-UNIX computers.
* MyODBC-a library of functions between PHP, iODBC, and MySQL.
Even so, this chapter is not about the instructions needed to compile the application, but simply the description. In short, the focus of this book is to introduce the PHP language, not the C language. The compilation of each application is very clear to me and I hope that every reader will be able to compile without difficulty. If you do encounter some problems, you can ask politely on one of the IRC channels, or you can try using newsgroups (which can be accessed from http://www.dejanews.com) to help solve the problem. However, the best help is from the PHP mailing list on http://www.php.net.
Before we start the compilation process, let's discuss how to recover from the error. After getting help with the error, you can reinitialize the source directory with the following command:
* RM config.cache--almost all Linux applications use the Configure command to check their systems for information about how to trim the compilation process. The results of the check will be stored in a file named Config.cache. If this file is moved, the Configurator will be forced to recheck the system from the beginning.
* Make distclean--all Linux applications written in C are compiled with the Make program. The make program looks for each source file to verify that it needs to be compiled or compiled. The Make Distclean command can "reset" all the source programs so that they can be recompiled.
* Make clean--applications do not support the make Distclean command, instead of the make clean command. The Make clean command "resets" all the source programs so that they can be recompiled.
Even though some of the applications you want to install do not support each of these commands, it is harmless to try these commands.
Note: Red Hat v5.2 uses the GLIBC library. If a user downloads or updates a program installed in this chapter from the Internet, you must know the glibc information. Users can use the Rpm-q glibc command to find out the version number of the GLIBC library that has been installed. In the author's system, glibc-2.0.7.29 is displayed using the Rpm-q glibc command.
2.1 Basic Concepts
Perhaps the reader has never compiled a Linux application before, and here are some basic concepts to be able to diagnose the problem in the event of a problem.
Tar
Tar, or tape archiver, can combine several files into a single file and choose whether or not to compress. This command used to be used to make backups so that the data is stored on tape. When the tar files are compressed, they have a. gz suffix, and when the tar files are not compressed, they have a. tar suffix.
Gcc
GCC is the GNU C compiler. It is the work of the people can understand the source code files compiled into a machine can read the target file. C source files usually have the suffix name of. C, and the destination file usually has a suffix name of. O. If the compilation is not working properly, you are encountering a compile-time error, or a syntax error. In most cases, incomplete compilation is usually caused by the compiler not finding one or several include files. The include file has an extension of. h, which is typically used to define different system information and to gather together information that is common to several different. c files.
Make
Make is a common utility that is used to help with compiling. Its job is to compile only those source files that have not yet been compiled. Compiling a. c file will generate an. o file, and if the. c file is updated than the. o file, the source file is edited before the last compilation, and make will recompile the. c file. The make command is typically looking for a makefile file that contains one or more targets that can be executed, for example, make clean tells made to perform the purge target.
Ld
LD is the GNU Link program. Its job is to link all the target files and libraries to create a single executable file. Fortunately, there is basically no manual running of this program, because makefile will take into account all the compilation details.
Ldconfig
Ldconfig will look for shared libraries in multiple library directories (specified in/etc/ld.so.conf). Shared libraries are often used by multiple applications, and their filenames have. So, for example, libqt.so.1.42 is a shared library. After compiling, it is possible to add a directory to the/etc/ld.so.conf file and run the LDCONFIG-V command.
./configure
Configure will look for key information in the computer, such as which C compiler is installed, where the files are, and so on. The Configure will then re-modify the makefile file according to the computer configuration used. You should use./configure to run the program under the current directory to avoid accidentally running other programs in the directory under the $PATH environment variable.
Symbolic connection
Symbolic connections allow the user to specify a different name for an already existing file. For example, a user might want to refer to a file named libqt.so.1.42 as Libqt.so.1. Symbolic connections basically allow a user to copy a file to a different directory, but in fact there is no real copy of the file. The second instance of the file simply points to the first file instance. There are at least two advantages to using symbolic connections, the 1th is that symbolic connections can save hard disk space, less than 16 bytes; The 2nd is a bit tricky, let's take a look at a symbolic connection named Libqt.so.1 and pointing to libqt.so.1.42. What should I do if I need to upgrade to libqt.so.1.88? The user simply changes the symbolic connection so that libqt.so.1 points to libqt.so.1.88, not libqt.so.1.42. This means that programs that involve libqt.so.1 will automatically use the new version of this library. By convention, symbolic connections are often used for the full 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 Pre-compilation preparations
The following steps will prepare your system for pre-compilation.
1. MKDIR/USR/LOCAL/SRC--I chose the/usr/local tree as the root directory for the installed application. Other people may choose the/usr/opt,/opt, or/var directories. To make it easier to follow the instructions in this chapter, use the/usr/local directory as the root directory. When the compilation is complete, the user can copy the files to a different directory.
Note: In order to complete the other steps in this chapter, the user must have root privileges.
2. cd/usr/local/src--go to the source file directory.
3. Download the following files (which can be downloaded from the Http://www.mtolive.com/phpbook site), or copy the files to the/USR/LOCAL/SRC directory from the CD-ROM included in this 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. Use the TAR command to unzip the above file. The x option for tar is the undo option, the V option displays the file name that is extracted from the document on the screen, the z option is the unzip option, and the F option specifies the. tar file name on the command line.
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 version of the existing GCC 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, make a backup of the existing GCC for later use. Another advantage of Linux is that it is easy to store multiple versions of a program in a directory.
7. Httpd-v
Determine the version number of Apache in the system. If Apache in your system is not v1.3.4, replace v1.3.4 with your version number in the following procedure.
8. MV ' which httpd '/usr/sbin/httpd-1.3.4
If necessary, make a backup of the existing Apache for later use.
2.3 Compiling the C compiler gcc
The first program that a consumer should install and compile is the C compiler. The C compiler that came with red Hat v5.2 is GCC v2.7.2.3, because its version is so low that it does not compile PHP correctly. However, GCC v.2.7.3 can be used to compile a higher-version gcc v2.8.1.
Compiling a new version of GCC requires execution:
1. cd/usr/local/src/gcc-2.8.1
Go to the top-level directory of GCC.
2../configure-prefix=/usr/local/gcc
Run the configuration program to force Setup to use/USR/LOCAL/GCC as the installation directory for GCC during the subsequent installation process.
3. Make Bootstrap languages= "C C + +" boot_cflags= "-g-02"
Compile the new C and C + + compilers.
4. Make install languages= "C 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 it contains a version number in its name.
6. ln-s \
/usr/local/gcc/bin/gcc-2.8.1 \
/usr/bin/gcc-
Create a symbolic connection/USR/BIN/GCC to the newly compiled GCC executable file.
7. Gcc-v
Displays the version number of GCC. If both the compilation and installation are normal, v.2.8.1 will be displayed.
2.3 Compiling MySQL
Now to compile MySQL. After the compilation is complete, you can use the MySQL application to test the installation.
1. Cd/usr/src/mysql-3.22.16a-gamma
Go to the top-level directory of MySQL.
2../configure--prefix=/usr/local/mysql
Run the configuration program to force the installer to use/usr/local/mysql as the installation directory for MySQL during the subsequent installation process.
3. Make
Compile MySQL.
4. Make install
Install MySQL.
5. Echo "/usr/local/mysql/lib/mysql" >>/etc/ld.so.conf
Add the directory where the MySQL library is located into the configuration file. This way, when Linux starts or executes the Ldconfig command, the library file is searched in the directory in 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 looks for the MySQL library file in the large output of the Ldconfig command, and qualifies the text to be displayed in a similar manner:
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 boot command to the/etc/rc.d/rc.local file so that MySQL will run automatically each time you start Linux.
8../scripts/mysql_install_db
Initializes the database.
9./usr/local/mysql/bin/safe_mysqld >/dev/null &
To start the MySQL server as a daemon, the MySQL server must be started in order to test the installation.
Ten. ln-s \
/usr/local/mysql/bin/mysql \
/usr/bin/mysql
I prefer to establish symbolic links for the installation directory under the/usr/bin directory. This method reduces the number of directories in the PATH environment variable and hides the MySQL utility program that you do not want other people to run (for example, the Mysqladmin command). Another method is to put the command path= "$PATH:/usr/local/mysql/bin" in the/etc/profile file. Both of these methods can be used.
Ln-s\.
/usr/local/mysql/bin/mysqlshow \
/usr/bin/mysqlshow
The directive is for the general user to be able to run the mysqlshow command.
2.4 Testing MySQL
Before proceeding with Apache and PHP compilation, first test the success of MySQL installation. The official release of MySQL comes with a number of useful tools, where we only use MySQL and Mysqlshow commands for testing. (If you are unfamiliar with the database, don't worry, the concepts of databases such as users, tables, records, etc.) are described in chapter sixth, "Database and SQL." )
The role of Mysqladmin is to create and delete databases, check the status of SQL, and other uses. First, verify that MySQL is installed correctly by checking the version number:
>path= "Usr/local/mysql/bin: $PATH"
>mysqladmin version
Ver 7.8 distrib 3.22.16a-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 min. sec
Threads:1 questions:7 Slow queries:0
Opens:6 Flush tables:1 Open tables:2
You can view all the features of mysqladmin with the following command.
Mysqladmin--help | Less
Perhaps Mysqlshow is a more exciting tool that can list database, table, and field names as follows:
Listing 2.1 mysqlshow--displaying a list of databases, tables, and field names
The last MySQL tool to introduce is MySQL, which will drill down to the center of MySQL and allow you to execute SQL statements immediately at the Linux command prompt. Run MySQL in shell mode.
Page 19 (line 5th)-20 (bottom 5th line)
Caution: Set the password to use the password () function. If you need further information, please consult the MySQL documentation.
Caution: When the system enters normal operation mode, please choose a better root password than "password".
2.5 Compiling IODBC and MYODBC
iODBC is a library of functions that implement an open database interconnect (open Databases Connectivity) protocol. It is primarily used to connect 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 force the settings iODBC to be installed under directory/USR/LOCAL/IODBC. In addition, you should confirm that the ODBC initialization file is/etc/odbc.ini.
3. Make
4. Make install
Copy the library files to the directory/usr/local/iodbc/lib, and copy the included files to the directory/usr/local/iodbc/include.
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 library to the directory/usr/local/myodbc/lib.
2.6 Compiling PHP
Compiling PHP is more complex than compiling a previous application because compiling PHP is actually a combination of expat, Apache, and PHP. The compiled result will generate a version of Apache with PHP. In order to compile PHP, you can take the following 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, and you must ensure that the TAB key is used before you enter AR and ralib.
LIBEXPAT.A: $ (OBJS)
AR-RC $@ $ (OBJS)
Ranlib $@
4. Make LIBEXPAT.A
Combine the expat target file into a library file.
5. MV Libexpat.a/usr/local/lib
The PHP configuration file looks for the libexpat.a file in the/usr/local/lib directory. Moving the libexpat.a file to a directory known as the PHP configuration file can reduce the hassle of 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
Confirm that the/usr/local/include/xml directory is present.
8. ln-s \
/usr/local/src/expat/xmltok/xmltok.h \
/usr/local/include/xml/xmltok.h
When you can create a symbolic connection, why do you want to copy it?
9. ln-s \
/usr/local/src/expat/xmlparse.h \
/usr/local/include/xml/xmlparse.h
This is the other included file that PHP needs to be able to compile correctly.
Ten. cd/usr/local/src/apache_1.3.4
Go to the top-level directory of Apache.
One:/configure-prefix=/usr/local/apache
Run the configuration program to force the Apache installation directory to/usr/local/apache.
cd/usr/local/src/php-3.0.11.
Go to the top-level directory of PHP.
/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 Configurator to support Apache, MySQL, and XML.
. Make
Compile the PHP source file.
. Make Install
Installs the compiled files. PHP library files will be placed in the Apache module directory, so that they can be found when compiling Apache.
cd/usr/local/src/apache_1.3.4.
Go to the top-level directory of Apache.
/configure.
--prefix=/usr/local/apache \
--active-module=src/modules/php3/libphp3.a
Configure Apache again, this time to tell Apache to load the PHP module.
. Make
Compile the Apache source file.
. Make Install
Installs the compiled files.
. MV \
/USR/LOCAL/APACHE/BIN/HTTPD \
/usr/local/apache/bin/httpd-1.3.4
Rename the newly created httpd executable so that you can install multiple versions.
Ln-s \
/usr/local/apache/bin/httpd-1.3.4 \
/usr/sbin/httpd
Create a symbolic link to the new executable file.
Httpd-v.
Verify that you can access the new executable file. The result of the command will show version 1.3.4, and the build 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 application/x-httpd-php3. phtml
AddType application/x-httpd-php3. php3
AddType Application/x-httpd-php3-source. Phps
24. Then edit the/usr/local/apache/conf/http.conf file, search for DirectoryIndex and put Index.php3 at the end of the line.
25. Create a file named/usr/local/local/php3.ini, which should contain the following command line:
include_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
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 will automatically display the PHP file start page correctly.
Ln-s \
/usr/local/src/php-3.0.11/doc \
/usr/local/apache/htdocs/phpdocs
Create a symbolic link so that you can access the PHP document via http://localhost/phpdocs/.
28. Create a file called/usr/local/apache/htdocs/robots.txt, so that you can avoid the search engine to index phplib,phpmyadmin and PHP files, the newly created file should include the following setting line:
#robots. txt for (hostname)
User-agent *
Disallow:/phpdocs/
Disallow:/php/
disallow:/phpmyadmin/
2.7 Installing Phplib
Before you read the 15th chapter, "Handling Concurrent access," You should install Phplib, which you can install by following these steps:
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 you begin to download the file, go to the top-level directory of the Web server.
3. Download the latest version of the file from the Web URL below and note the file name of the GZ suffix to prevent its file name phplib.tar.gz from being altered.
http://phplib.shonline.de/
4. Tar xv2f phplib.tar.gz
Unzip the Phplib module.
5. Edit the/usr/local/lib/php3.ini file, which should include the following settings:
include_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 generally use phpmyadmin, and if you prefer, you can also use SQL commands to create a database.
7. Cd/usr/local/apache/phplib-6.1/stuff
Go to the Build table directory.
8. mysql Php_book--user=root--password <
Create_database.mysql
The database tables required to create the phplib.
9. Add a new record to 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 into
User
(
Host
, the User
, Password
, Select_priv
, Insert_priv
, Update_priv
, Delete_priv
)
VALUES (
'%'
, ' Kris '
, '
, ' y ', ' y ', ' y ', ' y '
)
10. Add a new record to the DB table in the MySQL database using the following values:
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 into
Db
(
Host
Db
, the User
, Select_priv
, Insert_priv
, Update_priv
, Delete_priv
)
VALUES (
'%'
, ' Poe_sessions '
, ' Kris '
, ' y ', ' y ', ' y ', ' y '
)
/usr/local/mysql/bin/mysqladmin-u Root-p Reload
Reload the MySQL permissions table.
12. Create two Phplib Authenticated Users (User01 and User02) in the Php_book database, using the following SQL statement:
Mv\/use/local/apache/phplib-6.1/pages \
/use/local/apach/htdocs
Place the demo subdirectory at the root 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:
Disallow:/phplib/
15. Use a Web browser to access http://localhost/phplib/. You will see the 2.1 pages shown.
Page 29 Figure 2.1
Figure 2.1 Phplib Demo page that appears after reloading two times
2.8 Testing ODBC in a Linux environment
It is important to perform basic testing of the installed software, especially if you need to manually edit the configuration file. The test below ensures that your MySQL driver is working properly and that the compiled iODBC library file is also correct.
1. Use the content listed in Listing 2.1 to create a file named/usr/local/etc/odbc.ini.
[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
Tells the test program which data source to access.
5. Select Host,user from user
Execute an SQL statement at the prompt, and if there is a response, it means that iODBC and MySQL are ready to use.
Now that ODBC is installed on your computer, its installation and test instructions are described in this chapter because its installation steps are not clear and the documentation is very small, but since ODBC is primarily a Microsoft technology and is rarely used in Linux, this is the last one in this book.
2.9 Summary:
This chapter describes how to get PHP and the steps required to install it on your computer, compiling a specific version of the Apache server built into PHP. It also installs the phplib that will be used in the 15th chapter, "midfield four: Handling concurrent access."
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.