Install and configure the PHP environment in Linux

Source: Internet
Author: User

Install and start MySQL: http://blog.csdn.net/wy3552128/article/details/8143686 in Linux

Linux installation, configuration, start Apache: http://blog.csdn.net/wy3552128/article/details/8143875

Mysql and Apache have been installed successfully. Next we will install and configure the PHP environment. It seems complicated to compile PHP5, and many problems have occurred. Record them here.

Platform: Virtual centos4.7 on VMware

HOST: windows

Preparations before installing PHP:

1. Check whether php has been installed. If php-v is used, check whether the version number is visible; or If php has been installed using rpm-qa | grep php.

2, download the PHP installation package,: http://www.php.net/downloads.php I download is php-5.3.18.tar.gz, in any directory of Linux, only specify the directory to install when compiling.

tar -zxvf php-5.3.18.tar.gzcd php-5.3.18

However, in the subsequent configure compilation process, some complicated problems were encountered:

1. error message: configure: error: Cannot find MySQL header files under/var/lib/mysql/

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs  --with-mysql=/var/lib/mysql/

Solution:

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/lib --enable-track-vars --with-xml --with-mysql

2. error message: configure: error: Cannot find MySQL header files under yes
Solution: this problem is mainly because the -- with-mysql path is not specified in the configure parameter above.

Run find/-name mysql. h to see if this file is in the path, and if it does not exist, install the MySQL-devel-4.1.12-1.i386.rpm (which must be installed ).

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/lib --enable-track-vars --with-xml --with-mysql-dir=/usr/include/mysql/mysql.h

3. error message: configure: error: Try adding -- with-zlib-dir = <DIR>. Please check config. log for more information.
Solution:

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/lib --enable-track-vars --with-xml --with-mysql-dir=/usr/include/mysql/mysql.h --with-zlib-dir=/usr/lib

Compile PHP's complete configure parameters (note the apache path ):

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/lib --enable-track-vars --with-xml --with-mysql-dir=/usr/include/mysql/mysql.h --with-zlib-dir=/usr/libmakemake install

To configure php. ini, just copy the php. ini-production in the php-5.3.18 installation package to/usr/local/php/lib.

[Root @ localhost php-5.3.18] # cp php. ini-production/usr/local/lib/php. ini
(It must be named php. ini./Usr/local/lib/path; php can be specified during compilation. you can also specify the ini storage location in Apache. If the location is incorrect, the php extension will not be loaded, and the extension information will not be displayed on the phpinfo () test page.)

----------------------------------------------- The split line can be calculated ----------------------------------------------------------------

Configure the PHP environment in Apache

You need to modify the Apache configuration file httpd. conf to get PHP parsing:

1. Add LoadModule php5_module modules/libphp5.so to LoadModule.

2. Add the following content under AddType application/x-gzip. gz. tgz:

    # probably should define those extensions to indicate media types:    #    AddType application/x-compress .Z    AddType application/x-gzip .gz .tgzAddType application/x-httpd-php .phpAddType application/x-httpd-php-source .phps
3. Add index. php In DirectoryIndex so that Apache can recognize the index in PHP format.
<IfModule dir_module>      DirectoryIndex index.html index.php  </IfModule> 

The last step is to verify the PHP environment:

Create a php phpinfo test page in the Apache website directory,/usr/local/apache/htdocs/info. php

[root@localhost htdocs]# vi info.php<?phpphpinfo();?>

Through http: // 192.168.200.102/info. php verification, you can view a lot of information through phpinfo (), such as the storage path of php. ini, and all extension components, which are very powerful.

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.