PHP Tutorial. Installing PHP

Source: Internet
Author: User
Tags install php odbc mysql mysql in php file socket variable versions
Tutorial Install PHP
This chapter compiles and installs the following software as follows:
* Apache v.1.3.4-The most popular Web server in the world.
* GCC v.2.8.1--from the GNU C and C + + compilers.
* MySQL V.3.22.16b-gamma-a database used by many people worldwide.
* PHP v.3.0.11-The software described in this book. A newer version can be obtained from the http://www.php.net (or the mirror site of this site) directly downloaded. The other steps in this chapter still apply.
* Expact-a library of functions for reading and processing XML documents.
* Phplib-a PHP function library for session management.
* LIBIODBC-the ODBC function library that is used primarily for accessing databases on non-UNIX computers.
* MYODBC-a function library between PHP, iODBC, and MySQL.
Even so, this chapter is not about the instructions needed to compile the application, but simply to describe it. In short, the focus of this book is on introducing the PHP language, not the C language. The compilation of every application is very clear to me, and I hope that every reader will be able to compile without difficulty. If you do have some problems, you can ask politely on one of the IRC channels, or you can try to use 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 begin the compilation process, let's discuss how to recover from the error. After you get help on 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 inspection are stored in a file called Config.cache. If this file is removed, the configuration program will be forced to re-examine the system from the beginning.
* Make distclean--all Linux applications written in C are compiled using the Make program. The make program looks for each source file to confirm whether 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--Some applications do not support the made Distclean command, instead of the. The Make clean command "resets" all the source programs so that they can be recompiled.
Even though some of the applications that you want to install do not support each of these commands, there is no harm in trying them.

Note: Red Hat v5.2 uses the GLIBC library. If users download or update the programs installed in this chapter from the Internet, they must know the glibc information. The user can use the Rpm-q glibc command to locate the version number of the GLIBC library that is already installed. In the author's system, the glibc-2.0.7.29 is displayed using the Rpm-q glibc command.

2.1 Basic Concepts
Perhaps readers have never compiled a Linux application before, and here are some basic concepts to be able to diagnose the problem when a problem arises.
Tar
Tar, or tape archiver, can combine several files into a single file and optionally compress it. This command used to be used for backup so that the data is stored on tape. When the tar files are compressed, they have a. gz suffix; When the tar file is not compressed, they have a. tar suffix.
Gcc
GCC is the GNU C compiler. It is the work of the people can read the source code files compiled into a machine can read the object file. C source files usually have a. c suffix name, and the destination file usually has an. o suffix name. If the compilation does not work correctly, 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. h extension, which is typically used to define different system information and to gather information that is common to several different. c files.
Make
Make is a common tool that is used to help with compilation. Its job is to compile only those source files that have not yet been compiled. Compiling. c files generates an. o file, and if the. c file is newer than the. o file, which means that the source file was edited before the last compilation, make will recompile the. c file. The make instruction is typically looking for a makefile file that contains one or more executable targets, for example, made clean tells make to perform a purge target.
Ld
The LD is a GNU-linked program. Its job is to link all the target files and libraries and create a single executable file. Luckily, there's basically no need to run this program manually, because makefile will take all the compilation details into account.
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 somewhere in their filename there is. 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 on the computer, such as which C compiler is installed, where the files are, and so on. Configure will then modify the makefile file according to the computer configuration used. You should use./configure to run the program in the current directory to avoid accidentally running other programs in the directory in the $PATH environment variable.
Symbolic connection
Symbolic connections allow users 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. A symbolic connection basically allows a user to copy a file to a different directory, but in fact does not actually copy the file. The second file instance simply points to the first file instance. Using symbolic connections can have at least two points of benefit, the 1th is that symbolic connection 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 if you need to upgrade to libqt.so.1.88? As long as the user simply changes the symbolic connection, the libqt.so.1 points to the libqt.so.1.88, not the libqt.so.1.42. This means that the program involved in Libqt.so.1 will automatically use the new version of the 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 the system for preparation before compiling.
1. MKDIR/USR/LOCAL/SRC-I chose the/usr/local tree as the root directory for the installed application. Other people may choose/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 file (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 that comes with the book at random:
. 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 extract the above files. The x option for Tar is to undo the option, the V option will display the file name in the document on the screen, the z option for the decompression option, and the F option to specify 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, back up 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 the 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, back up the existing Apache for later use.

2.3 Compiling the C compiler gcc
The first program that a user should install and compile a program is the C compiler. The C compiler that comes with red Hat v5.2 is GCC v2.7.2.3, because its version is low enough to compile PHP correctly. However, GCC v.2.7.3 can be used to compile a higher version of GCC v2.8.1.
Compiling a new version of GCC requires the following:
1. cd/usr/local/src/gcc-2.8.1
Go to GCC's top-level directory.
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 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.
7. Gcc-v
Displays the version number of GCC. If 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 MySQL's top-level directory.
2./configure--prefix=/usr/local/mysql
Run the configuration program to force the installer to use/usr/local/mysql as the MySQL installation directory 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 to the configuration file. In this way, when Linux starts or executes the Ldconfig command, the library file is searched in the directory in that profile.
6. Ldconfig-v | grep libmysqlclient
The Ldconfig command reads the directories listed in the/etc/ld.so.conf file and buffers the library files found in those directories. The grep command finds the MySQL library file in a large number of output results from the Ldconfig command, and qualifies the text to appear similar to the following:
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 directive to the/etc/rc.d/rc.local file so that MySQL runs automatically every time Linux is started.
8./scripts/mysql_install_db
Initializes the database.
9./usr/local/mysql/bin/safe_mysqld >/dev/null &
Start the MySQL server as a background program, in order to test the installation, the MySQL server must be started.
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 approach reduces the number of directories in the PATH environment variable and hides the MySQL utility program that you do not want others to run (for example, the Mysqladmin command). Another method is to place 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 to allow ordinary users to run the Mysqlshow command.

2.4 Test MySQL
Before you continue to compile Apache and PHP, first test the MySQL installation for success. Officially released MySQL comes with a lot of useful tools, where we only use the MySQL and Mysqlshow commands to test. (If you are unfamiliar with the database, don't worry, the concepts of databases such as users, tables, records, and so on will be covered in chapter sixth "databases and SQL".) )
The role of Mysqladmin is to create and delete databases, check the state of SQL, and some other uses. First, check the version number to verify that MySQL is installed correctly:

>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 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 databases, tables, and field names as follows:

List 2.1 mysqlshow--display database, table and field name list


Page 18 (line 13th)-19 (line 10th), listing 2.1


The last MySQL tool to introduce is MySQL, which will go deep into 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 (line 5th)


Caution: Set the password to use the password () function. Consult your MySQL documentation if you need further information.

Be careful: When the system goes into normal working mode, choose a better root password than "password".

2.5 Compiling IODBC and MYODBC
iODBC is a function library to implement Open database interconnection (Open DB Connectivity) protocol. It is primarily 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 force the setting iODBC to install to the directory/USR/LOCAL/IODBC. In addition, you should confirm that the initialization file for ODBC 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 complicated than compiling a previous application because compiling PHP is actually a combination of expat, Apache, and PHP. The results of the compilation will produce an Apache version with PHP. In order to compile PHP, you can use 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 you use the TAB key 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 libexpat.a files in the/usr/local/lib directory. Moving the libexpat.a file to a directory that is known to 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 in PHP.
7. Mkdir/usr/local/include/xml
Verify that the/usr/local/include/xml directory exists.
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 another included file that PHP needs to be compiled correctly.
cd/usr/local/src/apache_1.3.4
Go to Apache's top-level directory.
/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 in 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 configuration program to support Apache, MySQL, and XML.
Make
Compile the PHP source file.
Make install
Installs the compiled files. The PHP library files are placed in the Apache module directory so that you can find them when you compile Apache.
cd/usr/local/src/apache_1.3.4
Go to Apache's top-level directory.
/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
Compiles 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.
Httpd-v
Verify that you have access to the new executable file. The results of this command will display the version 1.3.4, and the date of creation should be correct.
23. Edit the/usr/local/apache/conf/http.conf file, search for AddType and confirm that the following lines are not commented.
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 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 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 through http://localhost/phpdocs/.
28. Create a file called/usr/local/apache/htdocs/robots.txt that will prevent search engines from indexing Phplib,phpmyadmin and PHP files, and the newly created file should include the following setup lines:
#robots. txt for (hostname)
User-agent *
Disallow:/phpdocs/
Disallow:/php/
disallow:/phpmyadmin/

2.7 Installation Phplib
Before you read chapter 15th, "Processing concurrent access," You should install Phplib, which you can install by following these steps:
1. Register with root or any other user who can write files in the/usr/local/apache directory.
2. cd/usr/local/apache/
Before you start downloading files, go to the top-level directory of the Web server.
3. Download the latest version of the file from the following Web site, note the name of the GZ suffix, lest its filename phplib.tar.gz be changed.
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 called poe_sessions. I typically use phpMyAdmin, and if you want, you can also use SQL commands to create a database.
7. Cd/usr/local/apache/phplib-6.1/stuff
Enter the table directory.
8. mysql Php_book--user=root--password <
Create_database.mysql
Create the database tables required by 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
, 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
, 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.
Re-load the MySQL permission table.
12. To create two Phplib authenticated Users (User01 and User02) in the Php_book database, you can use the following SQL statement:

INSERT into
Auto_user
(
Uid
, username
, password
, perms
) VALUES (
' c14cbf141ab1b7cd009356f555b1234 '
, ' User01 '
, ' Test '
, ' admin '
)

INSERT into
Auth_User
(
Uid
, username
, password
, perms
) VALUES (
' c14cbf141ab1b7cd009356f555b3241 '
, ' User02 '
, ' Test '
, ' admin '
)

Mv\/use/local/apache/phplib-6.1/pages \
/use/local/apach/htdocs
Place the presentation subdirectory under 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:

Disallow:/phplib/

15. Use a Web browser to access http://localhost/phplib/. You will see the page shown in Figure 2.1.


Page 29 Figure 2.1

Figure 2.1 Reloading The Phplib presentation page that appears after two times

2.8 Testing the Linux environment under the ODBC
It is important to perform basic testing on the installed software, especially when you need to manually edit the configuration file. The following test ensures that your MySQL driver is working properly and that 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.

Listing 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
Tells the test program to access the data source.
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 already available.
Now that you have ODBC installed on your computer, since its installation steps are not clear and the documentation is small, this chapter describes its installation and testing instructions, but since ODBC is primarily a Microsoft technology and is rarely used in Linux, this is the last of the books in this book.
2.9 Summary:
This chapter describes how to get PHP, and the steps needed to install it on your computer, and compile a specific version of the Apache server for built-in PHP. It also installs the phplib that will be used in the 15th chapter, "Midfield IV: Handling concurrent access."


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.