php编译打包,解压即用,Ubuntu上Nginx/Apache/PHP编译打包

808f1183c21d4d8178fcec295aedace1.png

适用环境

: 64位Ubuntu14.04

下载地址(

22MB

):

http://pan.baidu.com/s/1o6FlEUQ

md5sum png.tar.xz aaa62279d036c3248fa503ce6e3cb87f

解压即用,跨Linux发行版

PHP7打包

http://my.oschina.net/eechen/blog/411534

解压即用,跨Linux发行版

HHVM打包

http://my.oschina.net/eechen/blog/371643

安装依赖包:

sudo apt-get -y install \

build-essential \

autoconf \

libtool \

libxml2-dev \

openssl \

libcurl4-openssl-dev \

libbz2-dev \

libjpeg-dev \

libpng12-dev \

libfreetype6-dev \

libldap2-dev \

libmcrypt-dev \

libmysqlclient-dev \

libxslt1-dev \

libxt-dev \

libpcre3-dev \

libreadline-dev

大约需要下载24MB的安装包.

创建运行用户:

sudo addgroup png --system

sudo adduser png --system --disabled-login --ingroup png --no-create-home --home /nonexistent --gecos "png user" --shell /bin/false

创建解压目录:

sudo mkdir /png

sudo chown $USER:$USER /png

解压到目录:

xz -d png.tar.xz && tar xf png.tar -C /

几个程序对应的目录:

/png/httpd/2.4.10/

/png/nginx/1.6.0/

/png/php/5.4.31/

网站根目录:

/png/www/

配置位置:

/png/httpd/2.4.10/conf/httpd.conf

/png/nginx/1.6.0/conf/nginx.conf

/png/php/5.4.31/lib/php.ini

/png/php/5.4.31/etc/php-fpm.conf

启动:

sudo /png/httpd/2.4.10/bin/apachectl start

sudo /png/nginx/1.6.0/png-nginx start

sudo /png/php/5.4.31/png-fpm start

top -n1 -b|egrep 'httpd|nginx|fpm'

测试:

curl -I 127.0.0.1/info.php

curl -I 127.0.0.1/fpm/info.php

curl -I 127.0.0.1:8080/info.php

开机自启动:

sudo ln -s /png/httpd/2.4.10/bin/apachectl /etc/init.d/png-httpd

sudo ln -s /png/nginx/1.6.0/png-nginx /etc/init.d/

sudo ln -s /png/php/5.4.31/png-fpm /etc/init.d/

sudo update-rc.d png-httpd defaults

sudo update-rc.d png-nginx defaults

sudo update-rc.d png-fpm defaults

使用service管理这几个服务:

sudo service png-httpd restart|stop|start

sudo service png-nginx restart|stop|start

sudo service png-fpm restart|stop|start

需要的话,可以这样删除启动项:

sudo update-rc.d -f png-httpd remove

sudo update-rc.d -f png-nginx remove

sudo update-rc.d -f png-fpm remove

配置环境变量:

sudo nano /etc/profile 在末尾加入:

export PATH=/png/nginx/1.6.0/sbin:/png/httpd/2.4.10/bin:/png/php/5.4.31/bin:$PATH

source /etc/profile 在当前终端生效,重启完全生效.

nginx -v && httpd -v && php -v

重启测试:

sudo shutdown -r now

(完)

附: 编译配置参考(授人以鱼&授人以渔)

NGINX编译配置:

编辑Nginx源代码包里的auto/cc/gcc,用"#"号注释掉CFLAGS="$CFLAGS -g",去除Debug信息,这样编译出来的Nginx体积小于1MB.

修改nginx的header信息:

src/core/nginx.h

#define NGINX_VERSION      "1.6.0"

#define NGINX_VER          "nginx/" NGINX_VERSION 其中nginx可以改为nginx_ubuntu_server

其中ngx_cache_purge是一个第三方模块,要使用的话请自行下载并用--add-module指定位置.

configure_nginx.sh

#!/bin/bash

./configure \

--prefix=/png/nginx/1.6.0 \

--sbin-path=/png/nginx/1.6.0/sbin/nginx \

--conf-path=/png/nginx/1.6.0/conf/nginx.conf \

--error-log-path=/png/nginx/1.6.0/var/log/error.log \

--http-log-path=/png/nginx/1.6.0/var/log/access.log \

--pid-path=/png/nginx/1.6.0/var/run/nginx.pid \

--lock-path=/png/nginx/1.6.0/var/run/nginx.lock \

--http-client-body-temp-path=/png/nginx/1.6.0/var/cache/client_temp \

--http-proxy-temp-path=/png/nginx/1.6.0/var/cache/proxy_temp \

--http-fastcgi-temp-path=/png/nginx/1.6.0/var/cache/fastcgi_temp \

--http-uwsgi-temp-path=/png/nginx/1.6.0/var/cache/uwsgi_temp \

--http-scgi-temp-path=/png/nginx/1.6.0/var/cache/scgi_temp \

--user=png \

--group=png \

--with-http_ssl_module \

--with-http_realip_module \

--with-http_addition_module \

--with-http_sub_module \

--with-http_dav_module \

--with-http_flv_module \

--with-http_mp4_module \

--with-http_gunzip_module \

--with-http_gzip_static_module \

--with-http_random_index_module \

--with-http_secure_link_module \

--with-http_stub_status_module \

--with-mail \

--with-mail_ssl_module \

--with-file-aio \

--with-ipv6 \

--add-module=/png/src/ngx_cache_purge-2.1

成功生成 Makefile 后便可以执行 make && make install 编译安装.

mkdir -p /png/nginx/1.6.0/var/cache/nginx

Nginx的服务管理脚本可以参考Nginx官方提供的Deb包里的脚本/etc/init.d/nginx:

http://nginx.org/packages/ubuntu/pool/nginx/n/nginx/

只需要修改脚本开始定义的几个值:

CONFFILE=/png/nginx/1.6.0/conf/nginx.conf

DAEMON=/png/nginx/1.6.0/sbin/nginx

PIDFILE=/png/nginx/1.6.0/var/run/$NAME.pid

SCRIPTNAME=/png/nginx/1.6.0/$NAME

我把修改好的服务管理脚本放到了/png/nginx/1.6.0/png-nginx

编辑 /png/nginx/1.6.0/conf/nginx.conf

去掉 location / 里的两行,然后在 location / 前添加:

# 定义根目录和索引文件

root   /png/www;

index  index.html index.htm index.php;

# 开启目录列表

autoindex on;

autoindex_exact_size off;

autoindex_localtime on;

在 location / 后添加:

# fpm目录下的PHP请求交由PHP-FPM处理

location ^~ /fpm {

location ~ \.php$ {

try_files $uri =404;

include fastcgi_params;

#fastcgi_pass 127.0.0.1:9000;

fastcgi_pass unix:/tmp/php-fpm.sock;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

}

}

# 其他PHP请求交由监听8080端口的Apache处理

location ~ \.php$ {

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $remote_addr;

proxy_set_header Host $host;

proxy_pass http://127.0.0.1:8080;

}

Apache编译配置:

修改httpd的header信息:

文件1: include/ap_release.h

#define AP_SERVER_BASEVENDOR "Apache Software Foundation"

#define AP_SERVER_BASEPROJECT "Apache HTTP Server"

#define AP_SERVER_BASEPRODUCT "Apache" 其中Apache可以改为Apache_Ubuntu_Server

#define AP_SERVER_MAJORVERSION_NUMBER 2

#define AP_SERVER_MINORVERSION_NUMBER 4

#define AP_SERVER_PATCHLEVEL_NUMBER   10

文件2: os/unix/os.h

#define PLATFORM "Unix" 其中Unix可以改为GNU/Linux

到 http://apr.apache.org/download.cgi 下载 apr 和 apr-util, 然后把它们解压到 httpd 的 srclib 目录:

/png/src/httpd-2.4.10/srclib/apr

/png/src/httpd-2.4.10/srclib/apr-util

注意 srclib 下的 apr 和 apr-util 不要保留版本号.

configure_httpd.sh

#!/bin/bash

./configure \

--prefix=/png/httpd/2.4.10 \

--enable-mods-shared=most \

--enable-ssl=shared \

--with-ssl=/usr \

--with-included-apr \

--with-mpm=prefork

成功生成 Makefile 后便可以执行 make && make install 编译安装.

编辑/png/httpd/2.4.10/conf/httpd.conf

在末尾添加:

# 把以.php结尾的文件交由php模块处理,可以替代AddHandler application/x-httpd-php .php

setHandler application/x-httpd-php

# 添加index.php,不存在index.html时则载入index.php

DirectoryIndex index.html index.php

# 修饰列表

Include conf/extra/httpd-autoindex.conf

# 设置列表编码(默认是ISO-8859-1)

IndexOptions Charset=UTF-8

# 显示详尽的服务器信息

ServerSignature On

ServerTokens Full

# 隐藏版本信息

#ServerSignature Off

#ServerTokens Prod

# 设置Prefork MPM进程数

Include conf/extra/httpd-mpm.conf

修改运行用户:

把:

User daemon

Group daemon

改为:

User png

Group png

因为Nginx和PHP编译配置时用参数指定了Nginx和PHP-FPM的运行用户,所以Nginx和PHP-FPM的运行用户就不需要手动修改了.

修改Apache的根目录:

搜索 /png/httpd/2.4.10/htdocs, 替换为 /png/www, 有2处.

开启.htaccess重写支持:

把里的AllowOverride None改为AllowOverride All

修改监听端口:

把 Listen 80 改为 Listen 8080

把 ServerName www.example.com:80 改为 ServerName 127.0.0.1:8080

PHP编译配置:

注意顺序,先编译Apache,后编译PHP,因为编译PHP时需要使用--with-apxs2=/png/httpd/2.4.10/bin/apxs构建Apache的PHP模块libphp5.so.

编译PHP之前先做好ldap库的软链接,否则--with-ldap参数会导致configure和make失败.

64位这样软链接:

sudo ln -s /usr/lib/x86_64-linux-gnu/libldap.so /usr/lib/

sudo ln -s /usr/lib/x86_64-linux-gnu/liblber.so /usr/lib/

sudo ln -s /usr/lib/x86_64-linux-gnu/libXpm.so /usr/lib/

sudo ln -s /usr/include/x86_64-linux-gnu/gmp.h /usr/include/gmp.h

32位这样软链接:

sudo ln -s /usr/lib/i386-linux-gnu/libldap.so /usr/lib/

sudo ln -s /usr/lib/i386-linux-gnu/liblber.so /usr/lib/

sudo ln -s /usr/lib/i386-linux-gnu/libXpm.so /usr/lib/

sudo ln -s /usr/include/i386-linux-gnu/gmp.h /usr/include/gmp.h

configure_php.sh

#!/bin/bash

./configure \

--prefix=/png/php/5.4.31 \

--enable-fpm \

--enable-pdo \

--enable-sockets \

--enable-exif \

--enable-soap \

--enable-ftp \

--enable-wddx \

--enable-pcntl \

--enable-soap \

--enable-bcmath \

--enable-mbstring \

--enable-dba \

--enable-gd-native-ttf \

--enable-gd-jis-conv \

--enable-zip \

--enable-calendar \

--enable-shmop \

--enable-sysvmsg \

--enable-sysvsem \

--enable-sysvshm \

--with-mysql \

--with-mysqli \

--with-pdo-mysql \

--with-pdo-sqlite \

--with-iconv \

--with-gmp \

--with-pspell \

--with-xmlrpc \

--with-openssl \

--with-mhash \

--with-mcrypt \

--with-xsl \

--with-curl \

--with-pcre-regex \

--with-gd \

--with-jpeg-dir=/usr \

--with-png-dir=/usr \

--with-zlib-dir=/usr \

--with-xpm-dir=/usr \

--with-freetype-dir=/usr \

--with-gettext=/usr \

--with-zlib=/usr \

--with-bz2=/usr \

--with-recode=/usr \

--with-ldap \

--with-pear \

--with-readline \

--with-fpm-user=png \

--with-fpm-group=png \

--with-apxs2=/png/httpd/2.4.10/bin/apxs

成功生成 Makefile 后便可以执行 make && make install 编译安装.

编译好PHP后,会自动在/png/httpd/2.4.10/conf/httpd.conf中载入PHP模块,不用手动添加:

LoadModule php5_module modules/libphp5.so

安装常用扩展:

/png/php/5.4.31/bin/pecl install ZendOpcache-7.0.3 xdebug memcache redis

PHP配置文件php.ini:

cp /png/src/php-5.4.31/php.ini-* /png/php/5.4.31/lib/

cp /png/php/5.4.31/lib/php.ini-development /png/php/5.4.31/lib/php.ini

在/png/php/5.4.31/lib/php.ini末尾加入:

;zend_extension=/png/php/5.4.31/lib/php/extensions/no-debug-non-zts-20100525/opcache.so

;opcache.memory_consumption=128

;opcache.interned_strings_buffer=8

;opcache.max_accelerated_files=4000

;每60秒验证php文件时间戳是否更新

;opcache.revalidate_freq=60

;opcache.fast_shutdown=1

;opcache.enable_cli=1

;关闭PHP文件验证

;opcache.validate_timestamps=Off

;设置不缓存的黑名单

;opcache.blacklist_filename=/png/www/blacklist

;默认opcache是开启的,对应phpinfo()里Zend OPcache下的Master Value值.

;opcache.enable=On

;权限设置 chmod 777 /png/xdebug

;使用nginx+php-fpm时要在php-fpm.conf里配置request_terminate_timeout,使用httpd+php时要在php.ini里配置max_execution_time,以免Debug超时.

;xdebug(php-fpm)会连接Netbeans或Eclipse监听的9001端口进行调试会话(session) 执行命令可见: sudo lsof -i :9001 或 sudo netstat -antp|grep 9001

;Netbeans在进行Xdebug调试时才会监听9001端口,不调试时是不监听这个端口的.

zend_extension=/png/php/5.4.31/lib/php/extensions/no-debug-non-zts-20100525/xdebug.so

xdebug.remote_enable = on

xdebug.remote_handler = dbgp

xdebug.remote_host = 127.0.0.1

xdebug.remote_port = 9001

xdebug.remote_log="/png/xdebug/xdebug.log"

;可以只开分析器profiler

;xdebug.profiler_enable = 1

;xdebug.profiler_output_dir = "/png/xdebug/"

extension=memcache.so

extension=redis.so

把 date.timezone 的值设为 Asia/Shanghai

PHP-FPM配置文件和服务管理脚本:

cp /png/php/5.4.31/etc/php-fpm.conf.default /png/php/5.4.31/etc/php-fpm.conf

cp /png/src/php-5.4.31/sapi/fpm/init.d.php-fpm /png/php/5.4.31/png-fpm

PHP-FPM默认监听9000端口进行通信,也可以改用Unix Sock通信:

把 listen = 127.0.0.1:9000 改为 listen = /tmp/php-fpm.sock

并开启:

listen.owner = png

listen.group = png

listen.mode = 0660

编译时间对比:

time nice -20 make -j4 (Ubuntu 14.04 使用 i5-3230M 编译 Nginx 1.6.0 耗时 14 秒, 编译过程中 CPU 空闲值几乎为 0)

time nice -20 make (Ubuntu 14.04 使用 i5-3230M 编译 Nginx 1.6.0 耗时 32 秒, 编译过程中 CPU 空闲值在 73% 左右)

time nice -20 make (Ubuntu 14.04 使用 i5-3230M 编译 Apache 2.4.10 耗时 2 分钟 20 秒, 编译过程中 CPU 空闲值在 73% 左右)

time nice -20 make (Ubuntu 14.04 使用 i5-3230M 编译 PHP 5.4.31 耗时 5 分钟 50 秒, 编译过程中 CPU 空闲值在 73% 左右)

像MySQL,Memcached,Redis这样的数据存储服务我一般使用apt-get安装,方便快捷:

sudo apt-get install mysql-server memcached redis-server

展开阅读全文

© 著作权归作者所有

举报

打赏

13 赞

67 收藏

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值