Compile and install php5.6.5 under CentOS 6.5 (64-bit)

Keywords: PHP yum Nginx curl

I. Download the relevant installation packages

Download php
http://cn2.php.net/distributions/php-5.6.5.tar.gz

Download libmcrypt (php extension)
http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz

Download yasm (php extension)
http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz

Download t1lib (php extension)
ftp://sunsite.unc.edu/pub/Linux/libs/graphics/t1lib-5.1.2.tar.gz

Download the gd library installation package
https://bitbucket.org/libgd/gd-libgd/downloads/libgd-2.1.0.tar.gz

Download libvpx (gd library needs)
http://anduin.linuxfromscratch.org/sources/other/libvpx-v1.3.0.tar.xz
or
https://webm.googlecode.com/files/libvpx-v1.3.0.tar.bz2

Download tiff (gd library needs)
http://download.osgeo.org/libtiff/tiff-4.0.3.tar.gz

Download libpng (gd library needs)
http://downloads.sourceforge.net/libpng/libpng-1.6.16.tar.xz

Download freetype (gd library needs)
http://ring.u-toyama.ac.jp/archives/graphics/freetype/freetype2/freetype-2.5.4.tar.gz

Download jpegsrc (gd library needs)
http://www.ijg.org/files/jpegsrc.v9a.tar.gz

2. Install compiler tools and library files (install using yum command)

yum install -y  zlib-devel fontconfig fontconfig-devel libXpm* libtool* libxml2 libxml2-devel curl curl-devel libvpx-devel

It is recommended to install all of them.

yum install -y apr* autoconf automake bison bzip2 bzip2* cloog-ppl compat* cpp 
yum install -y curl curl-devel fontconfig fontconfig-devel freetype freetype* 
yum install -y freetype-devel gcc gcc-c++ gtk+-devel gd gettext gettext-devel 
yum install -y glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel 
yum install -y libcom_err-devel libpng libpng* libpng-devel libjpeg* libsepol-devel 
yum install -y libselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel libXpm* libX* 
yum install -y libtiff libtiff* make mpfr ncurses* ntp openssl nasm nasm* 
yum install -y openssl-devel patch pcre-devel perl php-common php-gd 
yum install -y policycoreutils ppl telnet t1lib t1lib* wget zlib-devel libvpx-devel

III. Start Installation

1. Install yasm

cd /home 
tar zxvf yasm-1.3.0.tar.gz 
cd yasm-1.3.0 
./configure 
make && make install

2. Install libmcrypt

cd /home
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make && make install

3. Install libvpx

cd /home

xz -d libvpx-v1.3.0.tar.xz
tar -xvf libvpx-v1.3.0.tar

cd libvpx-v1.3.0

./configure --prefix=/usr/local/libvpx --enable-shared --enable-vp9

make && make install

4. Installation of tiff

cd /home

tar zxvf tiff-4.0.3.tar.gz

cd tiff-4.0.3

./configure --prefix=/usr/local/tiff --enable-shared

make && make install

5. Installation of libpng

cd /home

xz -d libpng-1.6.16.tar.xz

tar -xvf libpng-1.6.16.tar

cd libpng-1.6.16

./configure --prefix=/usr/local/libpng --enable-shared

make && make install

6. Install freetype

cd /home

tar zxvf freetype-2.5.4.tar.gz

cd freetype-2.5.4

./configure --prefix=/usr/local/freetype --enable-shared --without-png

make && make install

7. Installing jpeg

cd /home

tar zxvf jpegsrc.v9a.tar.gz

cd jpeg-9a

./configure --prefix=/usr/local/jpeg --enable-shared

make && make install

8. Installation of libgd

cd /home

tar zxvf libgd-2.1.0.tar.gz

cd libgd-2.1.0

./configure \
--prefix=/usr/local/libgd \
--enable-shared \
--with-jpeg=/usr/local/jpeg \
--with-png=/usr/local/libpng \
--with-freetype=/usr/local/freetype \
--with-fontconfig=/usr/local/freetype \
--with-xpm=/usr/ \
--with-tiff=/usr/local/tiff \
--with-vpx=/usr/local/libvpx 

make && make install

9. Installation of t1lib

cd /home

tar zxvf t1lib-5.1.2.tar.gz

cd t1lib-5.1.2

./configure --prefix=/usr/local/t1lib --enable-shared

make without_doc

make install

10. Install php

Note: If the system is 64-bit, please execute the following two commands, otherwise installing php will make a mistake (32-bit system does not need to be executed)

cp -frp /usr/lib64/libltdl.so* /usr/lib/

cp -frp /usr/lib64/libXpm.so* /usr/lib/

cd /home

tar -zvxf php-5.6.5.tar.gz

cd php-5.6.5

export LD_LIBRARY_PATH=/usr/local/libgd/lib

# Check the path configuration for each installation. Some of them are with-mysql-sock=/tmp/mysqld.sock=/tmp/mysql.sock

./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-gd --with-png-dir=/usr/local/libpng \
--with-jpeg-dir=/usr/local/jpeg \
--with-freetype-dir=/usr/local/freetype \
--with-xpm-dir=/usr/ \
--with-vpx-dir=/usr/local/libvpx/ \
--with-zlib-dir=/usr/local/zlib \
--with-t1lib=/usr/local/t1lib \
--with-iconv \
--enable-libxml \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--enable-opcache \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--enable-ftp \
--enable-gd-native-ttf \
--with-openssl \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--without-pear \
--with-gettext \
--enable-session \
--with-mcrypt \
--with-curl \
--enable-ctype 

make && make install

CP php.ini-production/usr/local/php/etc/php.ini# Copy the PHP configuration file to the installation directory

rm -rf /etc/php.ini #Delete the system's own configuration file

ln -s /usr/local/php/etc/php.ini /etc/php.ini #Add soft links to / etc directory

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf #Copy template file as php-fpm configuration file

ln -s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf #Add soft connection to / etc directory
vi /usr/local/php/etc/php-fpm.conf #edit

# If there are no user WWW and group www, you need to create
groupadd www
useradd -g www www

user = www #Set php-fpm running account to www

group = www #Set the php-fpm runtime group to www

pid = run/php-fpm.pid #Cancel the previous semicolon

:wq! #Save exit

Setting php-fpm boot-up

cp /home/php-5.6.5/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm #Copy php-fpm to startup directory

chmod +x /etc/rc.d/init.d/php-fpm #Add Execution Permissions

chkconfig php-fpm on #Set up boot start
vi /usr/local/php/etc/php.ini #Editing configuration files

Find: disable_functions=

Revised to:

disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname

# List functions that PHP can disable. If some programs need to use this function, they can be deleted and disabled.

Find:; date.timezone=

Modified to: date.timezone = PRC # Set the time zone

Find: expose_php = On

Modified to: expose_php = Off # disables the display of PHP version information

Find: short_open_tag = Off

Modified to: short_open_tag = ON # Supports php short tags

Note: short_open_tag must be opened. After opening, you can use PHP segment tag:(

11. Configure nginx to support php

vi /usr/local/nginx/conf/nginx.conf

Modifying the / usr/local/nginx/conf/nginx.conf configuration file requires the following modifications

user www www; #The first line user removes the comment and modifies the Nginx runtime group to www; it must have the same user and group configuration as in / usr/local/php/etc/php-fpm.conf, otherwise PHP runs incorrectly

index index.html index.htm index.php; #Add index.php


 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

location ~ \.php$ {

root html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

# Cancel the comment on FastCGI server partial location and notice that the parameters of the fastcgi_param line are changed to document rootfastcgi_script_name, or absolute path is used.

/etc/init.d/nginx restart #Restart nginx

service php-fpm start #Start php-fpm

Posted by n00b Saibot on Wed, 29 May 2019 05:36:56 -0700