1. 程式人生 > >centos7.4 編譯安裝php5.6 (LNMP)

centos7.4 編譯安裝php5.6 (LNMP)

location -i free lar gin 啟動 b- png ()

centos7.4

前提:

1、需要提前安裝msyql數據庫(yum,二進制,自己編譯都行)

2、需要自己編寫windows的hosts文件,綁定域名和ip

3、nginx使用yum安裝

4、php使用5.6源碼編譯安裝

5、centos7.4 需要配置好EPEL源


編譯安裝php5.6 步驟:


1、安裝各種基礎庫,包

yum -y install gcc gcc-c++ libxml2 libxml2-devel openssl-devel

yum install autoconf automake libtool re2c bison -y

yum install zlib-devel libxml2-devel libjpeg-turbo-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libmcrypt-devel mhash mcrypt -y

yum install -y nginx


2、編譯安裝libiconv

wget http://ftp.gnu.org/gnu/libiconv/libiconv-1.14.tar.gz

tar -zxvf libiconv-1.14.tar.gz

cd libiconv-1.14

./configure -prefix=/usr/local/libiconv


make

如果報錯,error: ‘gets’ undeclared here (not in a function)

則修改 libiconv-1.14/srclib/stdio.in.h中的如下


_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");

為:

#if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16)

_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");

#endif

make install


3、編譯安裝php5.6

wget http://cn2.php.net/get/php-5.6.33.tar.gz/from/this/mirror

tar -zxvf php-5.6.33.tar.gz

cd php-5.6.33

./configure \

--prefix=/usr/local/php \

--with-mysql=mysqlnd \

--with-mysqli=mysqlnd \

--with-pdo-mysql=mysqlnd \

--with-iconv-dir=/usr/local/libiconv \

--with-freetype-dir \

--with-jpeg-dir \

--with-png-dir \

--with-zlib \

--with-libxml-dir=/usr \

--enable-xml \

--disable-rpath \

--enable-bcmath \

--enable-shmop \

--enable-sysvsem \

--enable-inline-optimization \

--with-curl \

--enable-mbregex \

--enable-ftp \

--enable-mbstring \

--with-mcrypt \

--with-gd \

--enable-gd-native-ttf \

--with-openssl \

--with-mhash \

--enable-pcntl \

--enable-sockets \

--with-xmlrpc \

--enable-zip \

--enable-soap \

--enable-short-tags \

--enable-static \

--with-xsl \

--with-fpm-user=nginx \

--with-fpm-group=nginx \

--enable-ftp \

--enable-fpm

make

make install


4、配置php,php-fpm

cp php.ini-production /usr/local/php/lib/php.ini

cd /usr/local/php/etc

cp php-fpm.conf.default php-fpm.conf

5、啟動php服務(FastCGI方式)

/usr/local/php/sbin/php-fpm

檢查php-fpm進程,以及偵聽端口

ps -ef | grep php-fpm

netstat -tnlp | grep php-fpm

6、配置Nginx,設置測試頁index.php,test_mysql.php

[root@centos7-1 conf.d]# cat benet3.com.conf

server {

listen 80;

server_name www.benet3.com benet3.com;

location / {

root /data/www/www.benet3.com;

index index.html index.php index.htm;

}

location ~* .*\.(php|php5)$ {

root /data/www/www.benet3.com;

fastcgi_pass127.0.0.1:9000;

fastcgi_indexindex.php;

includefastcgi.conf;

}

}


[root@centos7-1 www.benet3.com]# ll

total 12

-rw-r--r-- 1 root root 24 Feb 11 16:33 index.html

-rw-r--r-- 1 root root 21 Feb 11 16:36 index.php

-rw-r--r-- 1 root root 138 Feb 11 16:54 test_mysql.php


[root@centos7-1 www.benet3.com]# cat index.php

<?php

phpinfo();

?>

[root@centos7-1 www.benet3.com]# cat test_mysql.php

<?php


$conn = @ mysql_connect("192.168.52.132", "root", "123456a-j") or die("數據庫連接錯誤");


echo "數據庫連接成功";


?>


win10客戶端測試訪問

www.benet3.com

www.benet3.com/index.php

www.beent3.com/test_mysql.php






centos7.4 編譯安裝php5.6 (LNMP)