http://blog.s135.com/nginx_php_v6/
http://www.phpchina.com/download/handbook/linux-html/301.html
http://blog.jiqila.com/post/188/
http://imcat.in/teach-you-step-by-step-install-nginx-php-mysql/
http://blog.fj18.com/
升级所需的程序库
Discuz:
yum install make openssl openssl-devel pcre pcre-devel libpng libpng-devel libjpeg-6b libjpeg-devel-6b freetype freetype-devel gd gd-devel zlib zlib-devel gcc gcc-c++ libXpm libXpm-devel ncurses ncurses-devel libmcrypt libmcrypt-devel libxml2 libxml2-devel imake autoconf automake screen sysstat compat-libstdc++-33 curl curl-devel
张宴:
yum install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-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 libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
编译安装MySQL 5.1.38
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
tar zxvf mysql-5.1.38.tar.gz
cd mysql-5.1.38/
./configure \
--prefix=/usr/local/mysql/ \
--enable-assembler \
--with-extra-charsets=complex \
--enable-thread-safe-client \
--with-charset=gbk \
--with-big-tables \
--with-readline \
--with-ssl \
--with-embedded-server \
--enable-local-infile \
--with-plugins=partition,innobase,myisammrg
make && make install
--with-charset=gbk \\指定默认字符集
configure的相关参数:
–prefix=/home/mysql/ 指定安装目录
–without-debug 去除debug模式
–with-extra-charsets=gbk,gb2312,utf8 添加gbk,gb2312,utf8中文字符支持
–with-pthread 强制使用pthread库(posix线程库)
–enable-assembler 使用一些字符函数的汇编版本
–enable-thread-safe-client 以线程方式编译客户端
–with-client-ldflags=-all-static 以纯静态方式编译客户端
–with-mysqld-ldflags=-all-static 以纯静态方式编译服务端
–without-isam 去掉isam表类型支持,现在很少用了,isam表是一种依赖平台的表
–without-innodb 去掉innodb表支持,innodb是一种支持事务处理的表,适合企业级应用
make
编译
make install
安装
cp support-files/my-medium.cnf /etc/my.cnf
将mysql的配置文件copy到/etc目录下,并更名为my.cnf
/home/mysql下面有5个my-xxxx.cnf文件
my-small.cnf 最小配置安装,内存<=64M,数据数量最少
my-large.cnf 内存=512M
my-medium.cnf 32M<内存<64M,或者内存有128M,但是数据库与web服务器公用内存
my-huge.cnf 1G<内存<2G,服务器主要运行mysql
my-innodb-heavy-4G.cnf 最大配置安装,内存至少4G
chown -R mysql:mysql /usr/local/mysql
cd /usr/local/mysql
./bin/mysql_install_db --user=mysql
cp share/mysql/mysql.server /etc/rc.d/init.d/mysqld
chmod 755 /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 3 mysqld on
cp share/mysql/my-huge.cnf /etc/my.cnf
#mv /usr/local/mysql/data /var/lib/mysql
chown -R mysql:mysql /var/lib/mysql
#/usr/local/mysql/bin/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/sqldata --user=mysql
\\basedir是mysql安装地址 datadir是指定数据库安装地址
编辑/etc/my.cnf
在 [mysqld] 段增加
datadir = /var/lib/mysql #数据库安装地址我的是/data/sqldata
skip-innodb
wait-timeout = 10
max_connections = 512
max_connect_errors = 10000000
在 [mysqld] 段修改
max_allowed_packet = 16M
thread_cache_size = CPU个数*2
将 log-bin 注释
service mysqld start
/usr/local/mysql/bin/mysqladmin -u root password 'password_for_root' 设置root密码
4、安装PHP和Zend
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
tar zxvf libiconv-1.13.tar.gz
cd libiconv-1.13/
./configure --prefix=/usr/local
make
make install
cd ../
wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure
make
make install
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make
make install
cd ../../
wget http://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz/download
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make
make install
cd ../
ln -s /usr/local/lib/libiconv.la /usr/lib/libiconv.la
ln -s /usr/local/lib/libiconv.so /usr/lib/libiconv.so
ln -s /usr/local/lib/libiconv.so.2 /usr/lib/libiconv.so.2
ln -s /usr/local/lib/libiconv.so.2.5.0 /usr/lib/libiconv.so.2.5.0
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
替代方法
echo /usr/local/lib >>/etc/ld.so.conf
ldconfig
ldconfig -p | grep libiconv.so.2
wget http://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz/download
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make
make install
cd ../
http://php-fpm.org/downloads/
http://www.php.net/downloads.php
tar zxvf php-5.2.13.tar.gz
gzip -cd php-5.2.13-fpm-0.5.13.diff.gz | patch -d php-5.2.13 -p1
cd php-5.2.13/
#./configure \
--prefix=/usr/local/php5 \
--with-config-file-path=/usr/local/php5/etc \
--enable-mbstring \
--with-mcrypt \
--enable-ftp \
--with-gd \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--enable-magic-quotes \
--with-mysql=/usr/local/mysql \
--with-pear \
--enable-sockets \
--with-ttf \
--with-freetype-dir=/usr \
--enable-gd-native-ttf \
--with-zlib \
--enable-sysvsem \
--enable-sysvshm \
--with-libxml-dir=/usr \
--enable-force-cgi-redirect \
--enable-fastcgi \
--with-xmlrpc \
--enable-zip \
--enable-fpm
#原始:
./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/local \
--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-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-ldap \
--with-ldap-sasl \
--with-xmlrpc \
--enable-zip \
--enable-soap
-------------推荐------------------
修改:
./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/local \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-discard-path \
--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-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap
[修改后的去掉了--with-ldap --with-ldap-sasl功能mhash可能需要安装软件包yum install mhash*]
[启动--enable-safe-mode安全模块后make test 的时候会出现错误]
--with-apxs2=/usr/local/apache/bin/apxs \ 如果需要apache支持php需要加装--with-apxs2参数后面写apache安装目录找apxs的地址即可
_________Apache的安装_________
#Apache的安装
# tar –zxvf httpd-2.2.15.tar.gz
# cd httpd-2.2.15
# ./configure --prefix=/usr/local/apache --enable-so
#//编译时加上加载模块参数--enable-so
# make
# make install
#vi /usr/local/apache/conf/httpd.conf
# //修改Apache配置文件,添加ServerName www.yourdomain.com (或ServerName 本机ip)
# vi /etc/rc.d/rc.local
#//在rc.local上加入一行/usr/local/apache/bin/apachectl –kstart,系统启动时启动Apache服务。
_______________________________
_________让PHP同时支持Nginx+Apache_________
apache --> nginx -->apache的php --> 打php-fpm补丁 --> php-fpm的php
先装apache和nginx 先装不打补丁的php 让apache支持 之后再装一个打补丁的给nginx??
[京]小毛(272544) 14:45:06
apache的php
php-fpm的php
这2个的参数基本一样。
但是有一点不同:
第一遍安装
apache的php多了一个--with-apxs2不加--enable-fpm参数
第二遍安装
php-fpm的php多了一个--enable-fpm不加--with-apxs2参数
___________________________________________
phpinfo文件写法:
<?php
phpinfo();
?>
___________________________________________
make ZEND_EXTRA_LIBS='-liconv'
make install
cp php.ini-dist /usr/local/php/etc/php.ini
#vi php-fpm.conf
Unix user of processes
<!-- <value name="user">nobody</value> -->
Unix group of processes
<!-- <value name="group">nobody</value> -->
[修改为:]
Unix user of processes
<value name="user">www</value>
Unix group of processes
<value name="group">www</value>
cd ../
编译安装PHP5扩展模块
-------------可选------------------
http://pecl.php.net/package/memcache
tar zxvf memcache-2.2.5.tgz
cd memcache-2.2.5/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ../
http://bart.eaccelerator.net/source/0.9.6/
tar jxvf eaccelerator-0.9.6.tar.bz2
cd eaccelerator-0.9.6/
/usr/local/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ../
-------------推荐------------------
http://pecl.php.net/package/PDO_MYSQL
tar zxvf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
make
make install
cd ../
http://www.imagemagick.org/script/download.php
tar zxvf ImageMagick.tar.gz
cd ImageMagick-6.6.0-6/
./configure
make
make install
cd ../
http://pecl.php.net/package/imagick
tar zxvf imagick-2.3.0.tgz
cd imagick-2.3.0/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ../
修改php.ini文件
手工修改:查找/usr/local/php/etc/php.ini中的extension_dir = "./"
修改为extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"
并在此行后增加以下几行,然后保存:
-------------可选------------------
extension = "memcache.so"
-------------推荐------------------
extension = "pdo_mysql.so"
extension = "imagick.so"
/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
groupadd www
useradd -g www www
echo 'ulimit -SHn 65535' >> /etc/rc.local
echo '/usr/local/php/sbin/php-fpm start' >> /etc/rc.local
注:/usr/local/php/sbin/php-fpm还有其他参数,包括:start|stop|quit|restart|reload|logrotate,修改php.ini后不重启php-cgi,重新加载配置文件使用reload。
-------------------------------
如果echo 'ulimit -SHn 65535' >> /etc/rc.local加入后查ulimit -n的时候不变,按照下面的方法进行添加。
* hard nofile 1024000 对用户文件数量限制是1024000个
* soft nofile 1024000
* hard nproc 102400 对用户的process最大102400个
* soft nproc 102400
把这个加入到
/etc/security/limits.conf
-------------------------------
http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
tar zxvf ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz
cd ZendOptimizer-3.3.9-linux-glibc23-x86_64/data/5_2_x_comp/
cp ZendOptimizer.so /usr/local/php5/include/
zend_extension=/usr/local/php5/include/ZendOptimizer.so 写入php.ini中
创建虚拟主机使用的目录{可选}
mkdir -p /data/htdocs/www
chmod +w /data/htdocs/www
chown -R www:www /data/htdocs/www
三、安装Nginx
1、安装Nginx所需的pcre库:
tar zxvf pcre-8.01.tar.gz
cd pcre-8.01/
./configure
make && make install
cd ../
2、安装Nginx
tar zxvf nginx-0.7.65.tar.gz
cd nginx-0.7.65
张宴:
./configure \
--user=www \
--group=www \
--prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
__________________________
--add-module=/usr/local/src/nginx-accesskey-2.0.3 #可以加入防盗链模块
__________________________
Discuz文档:
./configure \
--prefix=/usr/local/nginx \
--with-http_realip_module \
--with-http_addition_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_stub_status_module \
--with-http_ssl_module\
--with-http_sub_module \
--with-http_dav_module
make && make install
cd ../
3、创建Nginx日志目录{可选}
mkdir -p /data/logs
chmod +w /data/logs
chown -R www:www /data/logs
修改Nginx配置文件
nginx
#user nobody
删除前面的注释#,改成 user www
改:
location / {
root /usr/local/www/nginx;
index index.html index.htm;
}
在index.html前面添加一个index.php
新方法:
root /usr/local/nginx/html;
index index.php index.html index.htm;
if (-d $request_filename){
rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
}
改
#location ~ \.php$ {
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script.name;
# include fastcgi_params;
#}
将前面的#去掉,修改为
location ~ .*\.(php|php5)?$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
#如果要指定其他网站目录请把root html;换成相应的目录地址 如:/usr/local/nginx/html
#为了使SCRIPT_FILENAME 有效,更改php.ini里面的; cgi.fix_pathinfo 改成cgi.fix_pathinfo=1;(去掉前面的;)
如果关闭Nginx的版本号请在nginx.conf中的http区域加入server_tokens off;为关闭版本号显示