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

下载地址(60MB)
:
http://pan.baidu.com/s/1kTieHzL

md5sum png.tar.gz 547e261ef268d267799add5e2ffa4f34

安装依赖包:

sudo apt-get -y install \

build-essential \

autoconf \

libtool \

libxml2 \

libxml2-dev \

openssl \

libcurl4-openssl-dev \

libbz2-1.0 \

libbz2-dev \

libjpeg-dev \

libpng12-dev \

libfreetype6 \

libfreetype6-dev \

libldap-2.4-2 \

libldap2-dev \

libmcrypt4 \

libmcrypt-dev \

libmysqlclient-dev \

libxslt1.1 \

libxslt1-dev \

libxt-dev \

libpcre3-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

解压到对应的目录即可:

tar xzf png.tar.gz -C /png

/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 编译安装.

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   9

文件2: os/unix/os.h

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

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

<FilesMatch \.php$>

setHandler application/x-httpd-php

</FilesMatch>

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

<IfModule dir_module>

DirectoryIndex index.html index.php

</IfModule>

# 修饰列表

Include conf/extra/httpd-autoindex.conf

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

IndexOptions Charset=UTF-8

# 显示详尽的服务器信息

ServerSignature On

ServerTokens Full

# 隐藏版本信息

#ServerSignature Off

#ServerTokens Prod

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重写支持:

把<Directory "/png/www">里的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失败.

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/

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/

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-zip \

--enable-calendar \

--enable-shmop \

--enable-sysvmsg \

--enable-sysvsem \

--enable-sysvshm \

--with-mysql \

--with-mysqli \

--with-pdo-mysql \

--with-pdo-sqlite \

--with-iconv \

--with-zlib \

--with-bz2 \

--with-gettext \

--with-xmlrpc \

--with-openssl \

--with-mhash \

--with-mcrypt \

--with-xsl \

--with-curl \

--with-pcre-regex \

--with-gd \

--with-freetype-dir=/usr \

--with-jpeg-dir=/usr \

--with-png-dir=/usr \

--with-ldap \

--with-pear \

--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/src/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这样的数据存储服务我一般使用apt-get安装,方便快捷:

sudo apt-get install mysql-server memcached

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

时间: 2024-07-30 13:37:09

解压即用,Ubuntu上Nginx/Apache/PHP编译打包的相关文章

如何在Ubuntu上安装Apache,MySQL,PHP,Nginx,HAProxy,以及如何在docker上安装LAMP

如何在Ubuntu上安装Apache,MySQL,PHP,Nginx,HAProxy,以及如何在docker上安装LAMP 在Ubuntu上安装LAMP: https://help.ubuntu.com/community/ApacheMySQLPHPhttps://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntuhttp://www.makete

Ubuntu上配置 Apache服务器和Tomcat服务器

                    Ubuntu上配置Apache服务器 1. 安装Apache sudo apt-get install apache2 Apache安装完成后,默认的网站根目录是 /var/www/html, 该目录下有一个index.html文件 (在浏览器中输入:127.0.0.1或localhost可以打开该页面) 2. 配置文件 Apache有两个配置文件: apache2.conf (/etc/apache2/apache2.conf); 和 000-defau

手把手教你在Ubuntu上安装Apache、MySql和PHP

1:首先安装apache:打开终端(ctrl+Alt+t), 输入命令:sudo apt-get install apache2即可安装, 安装完后,打开浏览器,在地址栏输入:localhost或者http://127.0.0.1 看到It works,表示安装成功! 默认根目录:/var/www/ 2:安装mysql: sudo apt-get install mysql-server-5.0 安装完后,会要你新设置mysql root密码,输入你自己的密码后enter键,再确认密码. 3:安

ubuntu 上android 源码编译 全过程(一)

1.安装ubuntu系统 2.安装jdk环境 3.配置编译环境 4.解决编译过程中遇到的问题 5.编译成功 问题解决总结: 资源版本 开始用的ubuntu 14.10 遇到一个大问题搞了两天没弄好,建议不要选择14.10 问题是 build/core/prebuilt.mk:143:*** recipe commences before first target.停止 遇到这个问题的绕道吧(个人建议) 现在的环境情况: ubuntu12.04 .jdk1.6.33.源码4.0.3 -------

Ubuntu下解决解压zip文件中文文件名乱码问题

在Ubuntu下解压Windows下压缩的zip文件时,会出现解压出的带中文文件名的文件名乱码,这是因为Ubuntu和Windows默认的编码不同,Ubuntu下默认的编码是UTF-8,而Windows下默认的编码是GBK.对于这个问题,主要有以下三种解决方法: 一.命令行指定解压字符集 在Ubuntu下解压来源于Windows的zip文件,中文文件名会出现乱码问题. 出现这个问题的原因是:Windows和Ubuntu使用的默认编码不相同,而且zip文件自身却不带有任何标识其编码的信息.解决方案

ubuntu解压zip文件中文乱码问题

通过unzip行命令解压,指定字符集 unzip -O CP936 xxx.zip 注:xxx.zip为需要解压的文件名 ubuntu解压zip文件中文乱码问题

apache 2.4 解压版 与 PHP解压版 的安装配置

apache 解压到指定目录后,修改httpd.conf  文件如下图: 使用cmd, 以管理员身份运行,执行以下命令安装apache服务: 安装成功后,启动apache服务,测试 是否成功,在浏览器地址栏输入 http://localhost 打开界面如下图: 下面安装PHP5.6 下载适合电脑的版本,解压到指定目录后 整合apache 与 php 操作如下: 在apache的httpd.conf 文件添加内容如下图: 然后修改php根目录里面的文件如下图: 找到下图右边的文件重命名为左边的图

解决ubuntu中zip解压的中文乱码问题

在解压windows传过来的zip文件时,才会出现乱码.所以,我用另一个方法解决中文乱码问题. 安装 代码: sudo apt-get install unar 12.04以下或者想编译安装的朋友请参考: 使用 代码: lsar foo.zip #列出所有文件 如果列出的文件名已经正确 代码: unar foo.zip #解压所有文件 如果列出的文件名还不正确 代码: lsar -e GB18030 foo.zip #指定使用GB18030编码列出所有文件 unar -e GB18030 foo

[转]Ubuntu 常用解压与压缩命令

.tar 文件(注:tar是打包,不是压缩!) # 仅打包,并非压缩 tar -xvf FileName.tar # 解包 tar -cvf FileName.tar DirName # 将DirName和其下所有文件(夹)打包 .gz文件 # .gz gunzip FileName.gz # 解压1 gzip -d FileName.gz # 解压2 gzip FileName # 压缩,只能压缩文件 .tar.gz文件. .tgz文件 # .tar.gz 和 .tgz tar -zxvf F