|| 安装所需各种依赖包
yum –y install
gcc gcc-c++ autoconf automake bison flex freetype freetype-devel fontconfig-devel gettext-devel libjpeg libjpeg-devel libpng libpng-devel libxml2 libxml2-devel libtool libtool-ltdl libtool-ltdl-devel libtiff-devel libXpm-devel libicu libicu-devel libidn libidn-devel libxslt libxslt-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers pcre pcre-devel pam-devel vim-enhanced mysql-devel
| 其它需要编译源码安装的依赖包
libivonv
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar -xzvf libiconv-1.14.tar.gz
./configure
make && make install
libmcrypt
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/old/libmcrypt-2.5.7.tar.gz
tar -xzvf libmcrypt-2.5.7.tar.gz
./configure
make&&make install
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make
make install
mhash
wget http://ncu.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.bz2
tar –xjvf mhash-0.9.9.9.tar.bz2
./configure
make
make install
cd ../
ln -s /usr/local/lib/libmcrypt.[la|so|so.4|so.4.4.8] /usr/lib/libmcrypt.[la|so|so.4|so.4.4.8]
ln -s /usr/local/lib/libmhash.[a|la|so|so.2|so.2.0.1] /usr/lib/libmhash .[a|la|so|so.2|so.2.0.1]
/sbin/ldconfconfig
mcrypt
wget http://ncu.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
tar –xzvf mcrypt-2.6.8.tar.gz
./configure
make
make install
||编译安装mysql略
||编译安装php Fast-CGI 模式(可以直接找高版本)
wget http://cn2.php.net/distributions/php-5.2.17.tar.bz2
tar -xjvf php-5.2.17.tar.bz2
wget http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz
gzip -cd php-5.2.17-fpm-0.5.14.diff.gz|patch -d php-5.2.17 -p1(此处为数字1,非L的小写)
cd php-5.2.17/
编译遇到最后error,查看缺哪些文件,直接yum
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/ --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap=/usr --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --without-pear
安装PHP时报错了:error: Cannot find OpenSSL's ,这个比较好解决,一定就是缺少包了。安装上即可,查了一下资料发现缺少了openssl包。在CentOs系统中可以通过YUM来安装:
<span class="pln" style="color: rgb(0, 0, 0);">yum install openssl openssl</span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">devel</span>
在CentOS编译PHP5的时候有时会遇到以下的一些错误信息,基本上都可以通过yum安装相应的库来解决。以下是具体的一些解决办法:
checking for BZip2 support… yes checking for BZip2 in default path… not found configure: error: Please reinstall the BZip2 distribution
Fix: yum install bzip2-devel
checking for cURL support… yes checking if we should use cURL for url streams… no checking for cURL in default path… not found configure: error: Please reinstall the libcurl distribution – easy.h should be in/include/curl/
Fix: yum install curl-devel
checking for curl_multi_strerror in -lcurl… yes checking for QDBM support… no checking for GDBM support… no checking for NDBM support… no configure: error: DBA: Could not find necessary header file(s).
Fix: yum install db4-devel
checking for fabsf… yes checking for floorf… yes configure: error: jpeglib.h not found.
Fix: yum install libjpeg-devel
checking for fabsf… yes checking for floorf… yes checking for jpeg_read_header in -ljpeg… yes configure: error: png.h not found.
Fix: yum install libpng-devel
checking for png_write_image in -lpng… yes If configure fails try –with-xpm-dir=
configure: error: freetype.h not found.
Fix: Reconfigure your PHP with the following option. --with-xpm-dir=/usr yum install freetype-devel
checking for png_write_image in -lpng… yes configure: error: libXpm.(a|so) not found.
Fix: yum install libXpm-devel
checking for bind_textdomain_codeset in -lc… yes checking for GNU MP support… yes configure: error: Unable to locate gmp.h
Fix: yum install gmp-devel
checking for utf8_mime2text signature… new checking for U8T_DECOMPOSE… configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing. This should not happen. Check config.log for additional information.
Fix: yum install libc-client-devel
checking for LDAP support… yes, shared checking for LDAP Cyrus SASL support… yes configure: error: Cannot find ldap.h
Fix: yum install openldap-devel
checking for mysql_set_character_set in -lmysqlclient… yes checking for mysql_stmt_next_result in -lmysqlclient… no checking for Oracle Database OCI8 support… no checking for unixODBC support… configure: error: ODBC header file ‘/usr/include/sqlext.h’ not found!
Fix:
yum install unixODBC-devel
checking for PostgreSQL support for PDO… yes, shared checking for pg_config… not found configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path
Fix: yum install postgresql-devel
checking for sqlite 3 support for PDO… yes, shared checking for PDO includes… (cached) /usr/local/src/php-5.3.7/ext checking for sqlite3 files in default path… not found configure: error: Please reinstall the sqlite3 distribution
Fix: yum install sqlite-devel
checking for utsname.domainname… yes checking for PSPELL support… yes configure: error: Cannot find pspell
Fix: yum install aspell-devel
checking whether to enable UCD SNMP hack… yes checking for default_store.h… no
checking for kstat_read in -lkstat… no checking for snmp_parse_oid in -lsnmp… no checking for init_snmp in -lsnmp… no configure: error: SNMP sanity check failed. Please check config.log for more information.
Fix: yum install net-snmp-devel
checking whether to enable XMLWriter support… yes, shared checking for xml2-config path… (cached) /usr/bin/xml2-config checking whether libxml build works… (cached) yes checking for XSL support… yes, shared configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
Fix: yum install libxslt-devel
configure: error: xml2-config not found. Please check your libxml2 installation.
Fix: yum install libxml2-devel
checking for PCRE headers location… configure: error: Could not find pcre.h in /usr
Fix: yum install pcre-devel
configure: error: Cannot find MySQL header files under yes. Note that the MySQL client library is not bundled anymore!
Fix: yum install mysql-devel
checking for unixODBC support… configure: error: ODBC header file ‘/usr/include/sqlext.h’ not found!
Fix: yum install unixODBC-devel
checking for pg_config… not found configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path
Fix:
yum install postgresql-devel
configure: error: Cannot find pspell
Fix: yum install pspell-devel
configure: error: Could not find net-snmp-config binary. Please check your net-snmp installation.
Fix: yum install net-snmp-devel
configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
Fix: yum install libxslt-devel
编译安装PDO_MYSQL拓展模块,总是提示
1
2
3
4
5
6
7
|
In
file
included from
/data0/software/PDO_MYSQL-1
.0.2
/pdo_mysql
.c:31:
/data0/software/PDO_MYSQL-1
.0.2
/php_pdo_mysql_int
.h:25:19: error: mysql.h: No such
file
or directory
In
file
included from
/data0/software/PDO_MYSQL-1
.0.2
/pdo_mysql
.c:31:
/data0/software/PDO_MYSQL-1
.0.2
/php_pdo_mysql_int
.h:36: error: expected specifier-qualifier-list before ‘MYSQL’
/data0/software/PDO_MYSQL-1
.0.2
/php_pdo_mysql_int
.h:48: error: expected specifier-qualifier-list before ‘MYSQL_FIELD’
/data0/software/PDO_MYSQL-1
.0.2
/php_pdo_mysql_int
.h:53: error: expected specifier-qualifier-list before ‘MYSQL_RES’
make
: *** [pdo_mysql.lo] Error 1
|
这是因为这是因为在编译时需要 MySQL 的头的文件。而它按默认搜索找不到头文件的位置,所以才出现这个问题。通过软连接把MySQL头文件对应到/usr/local/include/下就好
比如你的MySQL安装文件位于/usr/local/mysql,那么就执行以下命令:
# ln -s /usr/local/mysql/include/* /usr/local/include/
#make的时候加参数ZEND_EXTRA_LIBS='-liconv'是因为编译时需要iconv库, 但是configure的时候没有写到Makefile中, 还有一种方法是直接修改Makefile, 在链接库的地方(应该在100行左右)加上-liconv
make ZEND_EXTRA_LIBS='-liconv'
http://blog.chinaunix.net/uid-26466663-id-3290438.html http://blog.csdn.net/shanshu12/article/details/8003240
make install
cp php.ini-dist /usr/local/php/etc/php.ini
||编译安装php扩展
|memcache
|安装依赖包libevent
1.yum install libevent
2.wget http://cloud.github.com/downloads/libevent/libevent/libevent-1.4.14b-stable.tar.gz
tar –xzvf libevent-1.4.14b-stable.tar.gz
cd libevent-1.4.14b-stable
./configure –prefix=/usr/local/libevent
make && make install
|wget http://memcached.googlecode.com/files/memcached-1.4.10.tar.gz
tar –xzvf memcached-1.4.10.tar.gz
cd memcached-1.4.10
./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent
make
make install
|wget http://lcmp.googlecode.com/files/memcache-2.2.6.tgz
tar –xzvf memcache-2.2.6.tgz
cd memcache-2.2.6
/usr/local/php/bin/phpize
./configure --prefix=/usr/local/memcache --with-php-config=/usr/local/php/bin/php-config --enable-memcache
make
make install
安装成功后提示如下:
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
成功后修改php.ini文件
vim /usr/local/php/etc/php.ini
extension_dir=”./” èextension_dir=”/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613”
extension = “memcache.so”
|安装eaccelerator
| eaccelerator是一个自由开放源码php加速器,优化和动态内容缓存,提高了性能php脚本的缓存性能,使得PHP脚本在编译的状态下,对服务器的开销几乎完全消除。 它还有对脚本起优化作用,以加快其执行效率。能使PHP程序代码执效率能提高1-10倍
|eAccelerator 通过把经过编译后的PHP代码缓存到共享内存中,并在用户访问的时候直接调用从而起到高效的加速作用。它的效率非常高,从创建共享内存到查找编译后的代码都在非常短的时间内完成,对于不能缓存到共享内存中的文件和代码,eAccelerator还可以把他们缓存到系统磁盘上。
|eAccelerator 只支持使用 mod_php 或者 fastcgi mode 安装的PHP
unzip eaccelerator-0.9.6.1.zip
cd eaccelerator-0.9.6.1
/usr/local/php/bin/phpize
./configure --prefix=/usr/local/eaccelerator --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
make
make install
安装成功后提示如下:
Installing shared extensions:/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
之后,修改php.ini文件:
vim /usr/local/php/etc/php.ini
找到extension_dir,在下面添加
extension = “eaccelerator.so”
配置eaccelerator加速php:
[eaccelerator]
zend_extension=” /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so”
eaccelerator.shm_size=”16” #共享内存设置,以M为单位,默认为0
eaccelerator.cache_dir = "/tmp/eaccelerator" #缓存目录
eaccelerator.enable = "1" #开启或关闭eaccelerator,1==开,0==关;默认为1
eaccelerator.optimizer = "1" #启动或关闭内部优化器,默认为1
eaccelerator.check_mtime = "1" #启动或关闭PHP的文件修改检查;默认为1
eaccelerator.debug = "0" #启动或关闭高度日志记录
eaccelerator.filter = "" #判断哪些 PHP 文件必须缓存。可以指定缓存和不缓存的文件类型(如 "*.php *.phtml"等),如果参数以 "!" 开头,则匹配这些参数的文件被忽略缓存。默认值为 "";即,所有 PHP 文件都将被缓存。
eaccelerator.shm_max = "0" #当使用 " eaccelerator_put() " 函数时禁止其向共享内存中存储过大的文件。该参数指定允许存储的最大值,单位:字节(10240, 10K, 1M)。"0" 为不限制。默认值为 "0"。
eaccelerator.shm_ttl = "0" #当 eAccelerator 获取新脚本的共享内存大小失败时,它将从共享内存中删除所有在最后 "shm_ttl" 秒内没有存取的脚本缓存。默认值为 "0",即:不从共享内春中删除任何缓存文件。
eaccelerator.prune_period = "0" #当 eAccelerator 获取新脚本的共享内存大小失败时,他将试图从共享内存中删除早于"shm_prune_period" 秒的缓存脚本。默认值为 "0",即:不从共享内春中删除任何缓存文件。
eaccelerator.shm_only = "0" #允许或禁止将已编译脚本缓存在磁盘上。该选项对 session 数据和内容缓存无效。默认值为 "0",即:使用磁盘和共享内存进行缓存
eaccelerator.compress = "1" #允许或禁止压缩内容缓存。默认值为 "1",即:允许压缩。
eaccelerator.compress_level = "9" #指定内容缓存的压缩等级。默认值为 "9",为最高等级。
eaccelerator.keys = "disk_only"
eaccelerator.session = "disk_only"
eaccelerator.content = "disk_only"
###设置内容缓存的存放的地方,可以设置为:
shm_and_disk 在共享缓存和硬盘(默认值)
shm 默认存在共享内存,如果共享内存已满或大小超过 "eaccelerator.shm_max" 的值,就存到硬盘
shm_only 只存放在共享内存
disk_only 只存放在硬盘
none 不缓存数据
eaccelerator.allowed_admin_path = "/var/www/html/21andy.com/eaccelerator"
###这是控制面板的地址 安装包里有个control.php,你把它复制到网站的任意目录,可以用它查看和管理,这个必须指定,否则查看缓存内容的时候会出错
||配置php-fpm
Nginx+PHP需要 PHP生成可执行文件才可以,所以要利用fastcgi技术来实现Nginx与PHP的整合,这个只要我们安装是启用FastCGI即可.这里,我们用php-fpm来管理FastCGI(php-fpm已以补丁的形式加入到PHP中).
编辑配置文件:
vim php-fpm.conf
大约63行,去掉相应注释,为FastCGI指定用户,可使用默认的nobody,也可另行指定。
Unix user of processes
nobody
Unix group of processes
nobody
|启动php-cgi进程
Ulimit –SHn 65535
/usr/local/php/sbin/php-fpm start
启动的时候可能出现的问题
####
|ulimit [-acdfHlmnpsStvw] [size]
参数介绍:
-H 设置硬件资源限制.
-S 设置软件资源限制.
-a 显示当前所有的资源限制.
-c size:设置core文件的最大值.单位:blocks
-d size:设置数据段的最大值.单位:kbytes
-f size:设置创建文件的最大值.单位:blocks
-l size:设置在内存中锁定进程的最大值.单位:kbytes
-m size:设置可以使用的常驻内存的最大值.单位:kbytes
-n size:设置内核可以同时打开的文件描述符的最大值.单位:n
-p size:设置管道缓冲区的最大值.单位:kbytes
-s size:设置堆栈的最大值.单位:kbytes
-t size:设置CPU使用时间的最大上限.单位:seconds
-v size:设置虚拟内存的最大值.单位:kbytes 5,简单实例:
||编译安装 Nginx
wget http://nginx.org/download/nginx-1.0.10.tar.gz
tar –xzvf nginx-1.0.10.tar.gz
cd nginx-1.0.10
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make
make install
|nginx.conf 配置
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
worker_rlimit_nofile 65535;
events {
use epoll;
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
#charset utf8;
server_names_hash_bucket_size 128;
client_header_buffer_size 32K;
large_client_header_buffers 4 32K;
client_max_body_size 8M;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
#keepalive_timeout 0;
keepalive_timeout 65;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64K;
fastcgi_buffers 4 64K;
fastcgi_busy_buffers_size 128K;
fastcgi_temp_file_write_size 128K;
gzip on;
gzip_min_length 1K;
gzip_buffers 4 16K;
gzip_http_version 1.0;
gzip_comp_level 9;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
access_log logs/localhost.access.log main;
root html;
index index.html index.htm index.php;
#配置nginx支持PHP
location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
#缓存图片
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
#缓存js/css相关信息
location ~ .*\.(js|css)?$
{
expires 1h;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
|Fastcgi.conf 配置 (该文件内容基本不要修改)
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
|启动nginx
/usr/local/nginx/sbin/nginx
|配置Nginx+php-fpm开机启动
vim /etc/rc.local
在末尾添加:
ulimit -SHn 65535
/usr/local/php/sbin/php-fpm start
/usr/local/nginx/sbin/nginx
保存退出
||在不停止Nginx服务的情况下平滑变更Nginx配置
在修改过配置文件nginx.conf后可用如下命令检查配置文件是否正确
/usr/local/nginx/sbin/nginx –t
如提示如下所示则说明修改成功:
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
输入如下命令查看Nginx主进程号:
ps aux|grep "nginx: master process"|grep -v "grep"|awk '{print $2}'
或者
cat /usr/local/nginx/logs/nginx.pid
找到主进程号后可通过如下命令使配置文件生效:
kill –HUP 主进程号
或者可以这样
kill –HUP ` ps aux|grep "nginx: master process"|grep -v "grep"|awk '{print $2}'`
kill –HUP ` cat /usr/local/nginx/logs/nginx.pid `
############
nginx可接受的信号如下:
TERM, INT Terminate the server immediately
QUIT Stop the server
HUP Configuration changes, start new workers, graceful stop of old workers
USR1 Reopen log files
USR2 Upgrade the server executable
WINCH Graceful Stop (parent process advise the children to exit)
kill -HUP pid 重新应用配置文件
kill -USR1 pid 重新刷新log
||日志轮询
cat log_rotation.sh
#!/bin/bash
LOG_DIR=”/usr/local/nginx/logs”
DATA_DIR=`date +%Y%m%d`
/bin/mkdir –p $LOG_DIR/$DATA_DIR > /dev/null 2>&1
/bin/mv $LOG_DIR/access.log $LOG_DIR/$DATA_DIR/access.log
kill –USR1 `cat /usr/local/nginx/logs/nginx.pid`
设定log_rotation.sh在每天的00:00:00运行:
crontab –e
59 23 * * * /bin/bash log_rotation.sh