Compile and install PHP under CentOS

Source: Internet
Author: User
Tags dbase dbx dio php development environment zts

Compile and install PHP under CentOS

1. Go to the php official website to download the source code http://www.php.net/downloads.php, I download the use of is (php-5.4.8.tar.gz)

2. installation environment

Yum install xml2

2. Unzip to the/usr/src directory and execute the command: sudo tar-zxvf php-5.4.8.tar.gz-C/usr/src

3. Execute./configure \

-- Prefix =/usr/local/php \

-- With-mcrypt =/usr/local/libmcrypt \

-- With-zlib -- enable-mbstring \

-- With-openssl \

-- With-mysql \

-- With-mysqli -- with-mysql-sock \

-- With-gd -- with-jpeg-dir =/usr/lib \

With-bz2 \

-- With-pdo-mysql \

-- With-gettext \

-- With-curl \

-- With-pdo-mysql \

-- Enable-sockets \

-- Enable-bcmath \

-- Enable-xml \

-- Enable-zip \

-- Enable-gd-native-ttf \

-- Enable-pdo \

-- Enable-fpm \

-- Enable-freetype

4. Compile encountered problems: error: xml2-config not found. solution:

(1) Go to the official website http://xmlsoft.org/sources/ download source code. I used libxml2-2.9.0.tar.gz, decompress it to/usr/src, and run the command: sudo tar-zxvf libxml2-2.9.0.tar.gz-C/usr/src

(2) enter the directory/usr/src/libxml2-2.9.0, run under the root or use the sudo command to execute: sudo. /configure -- prefix =/usr/local/libxml2/; make install

(3) add -- with-libxml-dir =/usr/local/libxml2 to the php Directory during compilation.

5. Re-compile and encountered a problem: checking if the location of ZLIB install directory is defined... no; configure: error: Cannot find libz. solution:

(1) Go to the URL http://www.zlib.net/download zlib source code. I'm going to unzip zlib-1.2.7.tar.gz to/usr/src and execute the command: sudo tar-zxvf zlib-1.2.7.tar.gz-C/usr/src

(2) enter the directory/usr/src/zlib-1.2.7/and execute the command: sudo./configure -- prefix =/usr/local/zlib; make install

(3) enter the php Directory to recompile and add the new parameter -- with-zlib-dir =/usr/local/zlib

6. Re-compile and encountered a problem: error: Please reinstall the BZip2 distribution. solution:

(1) go to the website http://www.bzip.org/downloads.html to download the source code. I am using bzip2-1.0.6.tar.gz, run the command: sudo tar-zxvf bzip2-1.0.6.tar.gz-C/usr/src

(2) enter the directory/usr/src/bzip2-1.0.6/, sudo method to execute: make; make install (the source code below does not configure)

(3) recompile without adding new parameters

7. Re-compile and encountered problems:

Checking if we shocould use cURL for url streams... no checking for cURL in default path... not found

Configure: error: Please reinstall the libcurl distribution-easy. h shoshould be in <curl-dir>/include/curl/

The solution is to reinstall libcurl.

(1) go to the website http://curl.haxx.se/download/ to download the libcurl source code. I'm using curl-7.28.0.tar.gz, run the command: sudo tar-zxvf curl-7.28.0.tar.gz-C/usr/src

(2) enter the/usr/src/curl-7.28.0 directory and run the command:./configure -- prefix =/usr/local/curl; make install

(3) re-compile php and add the parameter -- with-curl =/usr/local/curl

8. Re-compile and encountered a problem: configure: error: Release Lib. h not found. solution:

(1) go to the website http://www.ijg.org/download source code. I am using mongosrc.v8d.tar.gz and run the following command: sudo tar-zxvf mongosrc.v8d.tar.gz-C/usr/src.

(2) Go to the/usr/src/Composer src. v8d directory and run the sudo command: sudo./configure -- prefix =/usr/local/jpeg; make install;

(3) re-compile php and add the parameter -- with-jpeg-dir =/usr/local/jpeg.

9. Re-compile and encountered the problem: configure: error: png. h not found.

(1) go to the website http://www.libpng.org/pub/png/libpng.html download source code, I use libpng-1.5.13.tar.gz, run the command: sudo tar-zxvflibpng-1.5.13.tar.gz-C/usr/src

(2) enter the/usr/src/libpng-1.5.13 directory and run the sudo command in sudo mode: sudo./configure -- prefix =/usr/local/png; make install;

(3) The configure: error: zlib not installed error is displayed. It indicates that it has been installed before, but an error is reported here. The solution is as follows:

3.1) enter the zlib source file directory (here I am/usr/src/zlib-1.2.7/), execute the command make clean, clear zlib;

3.2) Reconfigure./configure. Do not use the -- prefix parameter later;

3.3) make & make install;

3.4) Go to the libpng directory (My is/usr/src/libpng-1.5.13/) and execute the command./configure -- prefix =/usr/local/png;

3.5) make & make install;

(4) re-compile php and add the parameter -- with-png-dir =/usr/local/png.

10. Re-compile and encountered a problem: configure: error: mcrypt. h not found. Please reinstall libmcrypt.

(1) Go to the download source code of the website http://mcrypt.hellug.gr/lib/index.html, my download is libmcrypt-2.5.7.tar.gz; execute the command: sudo tar-zxvf libmcrypt-2.5.7.tar.gz-C/usr/src

(2) enter the/usr/src/libmcrypt-2.5.7 directory, run the sudo command:./configure prefix =/usr/local/libmcrypt/; make install

(3) re-compile php and add the parameter -- with-mcrypt =/usr/local/libmcrypt.

11. if you compile again, there will be no problem. Although configure: WARNING: unrecognized options: -- enable-freetype is displayed, the result is still Thank you for using PHP. the php compilation parameters are as follows:

(1) sudo. /configure -- prefix =/usr/local/php -- enable-fpm -- with-zlib -- enable-mbstring -- with-openssl -- with-mysql -- with-mysqli -- with-mysql- sock -- with-gd -- enable-gd-native-ttf -- enable-pdo -- with-pdo-mysql -- with-gettext -- with-curl -- with-pdo-mysql -- enable- sockets -- enable-bcmath -- enable-xml -- with-bz2 -- enable-zip -- enable-freetype -- with-libxml-dir =/usr/local/libxml2 -- with-zlib-dir =/ usr/local/zlib -- with-curl =/usr/local/curl -- with-jpeg-dir =/usr/local/jpeg -- with-png-dir =/usr/local /png -- with-mcrypt =/usr/local/libmcrypt -- with-apxs2 =/usr/local/apache2/bin/apxs

(Note: you must add this apxs-APache eXtenSion tool to create the DSO eXtenSion module of apache. To use this tool, you must add enable-so to support DSO when installing apache. without this, apache will only parse static pages. If this option is not added during the first compilation, the configuration will not work. If this option is added for the second compilation, it will be OK .)

(2) sudo make

(3) sudo make install

12. in order to directly use the php Command in the command line, edit sudo vim/etc/environment and add the php bin directory path. my options are/usr/local/php/bin, then reboot the machine

13. To enable Apache to support PHP, the solution is as follows:

(1) Go to the apache configuration directory and run the command cd/usr/local/apache2/conf. Edit the file: sudo vim httpd. conf

(2) Search for the string AddType and add

AddType application/x-httpd-php. php. php3. htm. phtml. php4

AddType application/x-httpd-php-source. phps
Add LoadModule php5_module modules/libphp5.so # unnecessary if necessary

Restart apache to make the configuration take effect.

(3) Search for the DirectoryIndex string and change it to DirectoryIndex index.html index. php3 index. php default. php.

14. Modify the php configuration.

(1) Go to the php source code directory and select php. ini-development copy to/usr/local/lib and change the name to php. ini open it with vim, find extension_dir, and change it to extension_dir = "D:/php/php5/ext". The reader configures the directory structure to find and php. ini is the same as the extension library in the ext folder in the directory.

(2) Find extension = php _, remove extension = php_curl.dll, extension = php_gd2.dll, extension = php_mbstring.dll, extension = php_mysql.dll, extension = php_mysqli.dll, extension = limit, the semicolon before extension = php_xmlrpc.dll. Search for short_open_tag = Off and change it to short_open_tag = On, so that it supports short labels (I think the comment is open by default ).

Php. ini configuration complete

Configure apache config

15. Search for the string DocumentRoot. You can set the Apache Virtual root directory.

16. Search for the ServerAdmin string and change it to your mailbox.

17. Add a test. php file to the apache Root file. <? Php phpinfo () ;?>, Access 127.0.0.1/test. php to view the result.

Compiled version

./Configure

-- Profix =/user/local/php

-- With-apxs2 =/usr/local/apache/bin/apxs

-- With-config-file-path =/usr/local/PHP/etc

-- With-mysql =/usr/local/mysql

-- With-mysqli =/usr/local/mysql/bin/mysql_config

-- With-libxml-dir = # libxml directory

-- With-zlib-dir = # zlib directory

-- Enable-sysvsem

-- Enable-sockets

-- Enable-pcntl

-- Enable-mbstring

-- Enable-mysqlnd

-- Enable-opcache

-- Enable-shmop

-- Enable-zip

-- Enable-ftp

-- Enable-gd-native-ttf

-- Enable-wddx

-- Enable-soap

-- Enable-fpm

 

 

 

Appendix: The compilation parameters for various php versions found online are as follows.

Fast-CGI:

. /Configure -- prefix =/usr/local/php -- enable-fastcgi -- enable-force-cgi-redirect -- with-config-file-path =/etc -- with-zlib -- -mysql -- with-xml -- with-gd -- enable-gd-native-ttf -- enable-gd-jis-conv -- with-freetype-dir -- with-jpeg-dir -- -png-dir -- enable-mbstring

PHP4-Server:

. /Configure -- prefix =/usr/local/php -- with-apxs2 =/usr/local/apache2/bin/apxs -- with-mysql -- with-config-file-path =/etc -- with-gd -- enable-gd-native-ttf -- enable-gd-jis-conv -- with-freetype-dir -- with-jpeg-dir -- with-png-dir --- zlib -- enable-xml -- enable-mbstring

PHP4-Max:

. /Configure -- prefix =/usr/local/php -- with-apxs2 =/usr/local/apache/bin/apxs -- mandir =/usr/share/man -- with-mysql =/usr /local/mysql -- with-config-file-path =/usr/local/php/etc -- with-openssl =/usr/local/openssl-0.9.7e -- with-gd -- enable-gd -native-ttf -- enable-gd-jis-conv -- with-freetype-dir -- with-jpeg-dir -- with-png-dir -- with-zlib -- with-bz2 -- with-inifile -- with-hyperwave -- enable-xml -- enable-track-vars -- enable-dba -- enable-dbase -- enable-filepro -- enable-ftp -- enable-versioning -- enable-memory-limit -- enable-calendar -- enable-session -- enable-sockets -- enable-sysmsg -- enable-sysvsem -- enable-sysvshm -- enable-tokenizer -- enable-overload -- enable-ctype -- enable-sigchild -- enable-magic-quotes -- enable-roxen-zts -- enable-fastcgi -- enable-dbx -- enable-dio -- enable-shmop -- enable-mbstring

PHP5-Server:

. /Configure -- prefix =/usr/local/php -- with-apxs2 =/usr/local/apache2/bin/apxs -- with-zlib-dir -- with-bz2 -- with-tiff-dir -- -libxml-dir -- with-gd -- with-freetype-dir -- with-jpeg-dir -- with-png-dir -- with-ttf -- enable-mbstring -- with-mysql =/ usr/lib/mysql -- with-config-file-path =/etc -- disable-ipv6 -- enable-gd-native-ttf

PHP5-Standard:

. /Configure -- prefix =/usr/local/php -- with-apxs2 =/usr/local/apache/bin/apxs -- mandir =/usr/share/man -- with-openssl =/usr /local/openssl-0.9.7e -- with-zlib -- with-bz2 -- with-tiff-dir -- with-libxml-dir -- enable-dio -- enable-ftp -- with-gd -- with-freetype-dir -- with-jpeg-dir -- with-png-dir -- with-zlib-dir -- with-bz2-dir -- with-ttf -- enable-mbstring -- with-mysql =/usr/local/mysql -- with-config-file-path =/usr/local/php/etc -- disable-ipv6 -- enable-gd-native-ttf

PHP5-Max:

. /Configure -- prefix =/usr/local/php -- with-apxs2 =/usr/local/apache/bin/apxs -- mandir =/usr/share/man -- with-openssl =/usr /local/openssl-0.9.7e -- with-zlib -- with-bz2 -- with-tiff-dir -- with-libxml-dir -- enable-dio -- enable-ftp -- with-gd -- with-freetype-dir -- with-jpeg-dir -- with-png-dir -- with-zlib-dir -- with-bz2-dir -- with-ttf -- with-inifile -- enable-dba -- enable-dbase -- enable-filepro -- enable-versioning -- enable-memory-limit -- enable-calendar -- enable-sockets -- enable-sysvsem -- enable-sigchild -- enable-magic-quotes -- enable-roxen-zts -- enable -fastcgi -- enable-dbx -- enable-shmop -- enable-mbstring -- with-mysql =/usr/local/mysql -- with-config-file-path =/usr/local/php /etc -- disable-ipv6 -- enable-gd-native-ttf

Deep understanding of ini configuration in PHP

Analyze the timeout mechanism of PHP scripts

Build a PHP development environment under Ubuntu 14.04 PDF

PHP 7 innovation and Performance Optimization

PHP 7, you deserve it

Experience PHP 7.0 on CentOS 7.x/Fedora 21

Install LNMP in CentOS 6.3 (PHP 5.4, MyySQL5.6)

Nginx startup failure occurs during LNMP deployment.

Ubuntu install Nginx php5-fpm MySQL (LNMP environment setup)

Detailed php hd scanning PDF + CD source code + full set of teaching videos

Configure the php lnmp development environment in CentOS 6

PHP details: click here
PHP: click here

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.