源碼編譯安裝PHP Version 5.6.30------踩了無數坑,重裝了十幾回服務器纔會的,不容易啊!

1 環境準備php

yum install gcc bison bison-devel zlib-devel libmcrypt-devel mcrypt mhash-devel openssl-devel libxml2-devel libcurl-devel bzip2-devel readline-devel libedit-devel sqlite-devel jemalloc jemalloc-develhtml

yum install libpng
yum install libpng-devel
yum -y install libjpeg-devel
yum install freetype-develmysql

cd /usr/local/srcsql

wget http://cn2.php.net/distributions/php-5.6.30.tar.gzapache

tar zvxf php-5.6.30.tar.gzvim

cd php-5.6.30api

groupadd wwwbash

useradd -g www -s /sbin/nologin wwwapp

 

2 編譯安裝 (##編譯參數)curl

./configure --prefix=/usr/local/php \
--with-apxs2=/usr/local/apache/bin/apxs \
--with-config-file-path=/usr/local/php/etc \
--enable-inline-optimization --disable-debug \
--disable-rpath --enable-shared --enable-opcache \
--enable-fpm --with-fpm-user=www \
--with-png-dir \
--with-freetype-dir \
--with-jpeg-dir \
--with-gd \
--with-fpm-group=www \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-gettext \
--enable-mbstring \
--with-iconv \
--with-mcrypt \
--with-mhash \
--with-openssl \
--enable-bcmath \
--enable-soap \
--with-libxml-dir=/usr/ \
--enable-pcntl \
--enable-shmop \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-sockets \
--with-curl --with-zlib \
--enable-zip \
--with-bz2 \
--with-readline

 

##參數解釋
"" " 安裝路徑 " ""
--prefix= /usr/local/php56  \
"" " php.ini 配置文件路徑 " ""
--with-config- file -path= /usr/local/php56/etc  \
"" " 優化選項 " ""
-- enable -inline-optimization \
--disable-debug \
--disable-rpath \
-- enable -shared \
"" " 啓用 opcache,默認爲 ZendOptimizer+(ZendOpcache) " ""
-- enable -opcache \
"" " FPM " ""
-- enable -fpm \
--with-fpm-user=www \
--with-fpm-group=www \
"" " MySQL " ""
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
"" " 國際化與字符編碼支持 " ""
--with-gettext \
-- enable -mbstring \
--with-iconv \
"" " 加密擴展 " ""
--with-mcrypt \
--with-mhash \
--with-openssl \
"" " 數學擴展 " ""
-- enable -bcmath \
"" " Web 服務,soap 依賴 libxml " ""
-- enable -soap \
--with-libxml- dir  \
"" " 進程,信號及內存 " ""
-- enable -pcntl \
-- enable -shmop \
-- enable -sysvmsg \
-- enable -sysvsem \
-- enable -sysvshm \
"" " socket & curl " ""
-- enable -sockets \
--with-curl \
"" " 壓縮與歸檔 " ""
--with-zlib \
-- enable -zip \
--with-bz2 \
"" " GNU Readline 命令行快捷鍵綁定 " ""
--with-readline

 

3. 編譯安裝

make && make install

以下圖 ,不抱任何錯誤

 

4.配置服務

配置文件

cp php.ini-development /usr/local/php/etc/php.ini

php-fpm 服務
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm

chkconfig --add php-fpm
chkconfig on php-fpm

netstat -nltp|grep 9000
service php-fpm start
 
出現下圖 Starting php-fpm done時表示安裝成功
 
5.環境變量
PATH=$PATH: /usr/local/php/bin
export  PATH
 
6.配置httpd支持php
vim /usr/local/apache/conf/httpd.conf
搜索ServerName,把#ServerName www.example.com:80前面的#號去掉

a.找到:

AddType application/x-gzip .gz .tgz
在其下面添加:
AddType application/x-httpd-php .php //添加支持對php腳本解析

b. 找到:
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
把中間那一行改成:
DirectoryIndex index.html index.htm index.php //增長對php的索引

c.找到

<Directory />
  AllowOverride None
  Require all granted
</Directory>

d.找到/添加

LoadModule php5_module   modules/libphp5.so

LoadModule php5_module modules/libphp5.so在httpd.conf中爲何會有這行代碼

緣由:
在編譯php時,編譯參數--with-apxs2=/usr/local/apache/bin/apxs\

 

7.重啓apache ,

cd /usr/local/apache/bin/

./apachectl restart

到此爲止php已經編譯完成了。

接下來就是配置虛擬主機了

在/usr/local/apache/conf/httpd.conf中,以下配置

9.當把apache,mysql ,php所有編譯完成以後就出現

如今.lamp環境正式搭建完成....哈哈哈哈哈哈哈哈哈

相關文章
相關標籤/搜索