WEB环境配置

第一步:检查服务器编译环境

Debian系
dpkg --list | grep gcc gcc-c++ libpcre libncurses
 缺少依赖包使用aptitude install ...
Redhat系
rpm -qa | grep gcc gcc-c++ libpcre libncurses
 缺少依赖包使用yum install ...

第二步:安装nginx php mysql

安装nginx

1.添加系统用户

useradd -r nginx

2.下载并解包nginx

cd /tmp

wget -c http://nginx.org/download/nginx-1.0.2.tar.gz

tar -xvf nginx-1.0.2.tar.gz

3.编译并安装nginx

cd nginx-1.0.2
./configure --prefix=/usr/local/nginx  --user=nginx --group=nginx
make
make install
安装mysql

1.添加系统用户

useradd -r -u 27 mysql

 

2.下载并解包mysql

cd /tmp

wget -c http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.57.tar.gz/from/http://mysql.cs.pu.edu.tw/

tar -xvf mysql-5.1.57.tar.gz

 

3.编译并安装mysql

cd mysql-5.1.57

export CFLAGS="-O2 -DHAVE_DLOPEN=1"
export CXXFLAGS="-O2 -DHAVE_DLOPEN=1"
./configure \    
--prefix=/usr/local/mysql/ \    
--without-debug \    
--with-unix-socket-path=/tmp/mysql.sock \    
--with-client-ldflags=-all-static \    
--enable-assembler \    
--with-extra-charsets=gbk,gb2312,utf8,ucs2 \    
--with-pthread \    
--enable-thread-safe-client \    
--with-readline \    
--with-charset=utf8 \    
--with-plugins=innodb_plugin,innobase,partition,myisam
make
make install
 
  1. ps:mysql5.5版本的编译方法从之前的configure更换成了cmake,编译前记得先yum安装cmake,然后使用cmake来编译
  2. cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk,gb2312 -DMYSQL_USER=mysql -DMYSQL_DATADIR=/data/mysql -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1
  3. scripts/mysql_install_db  --user=mysql  --basedir=/usr/local/mysql --datadir=/data/mysql/
  4. cp support-files/my-large.cnf /etc/my.cnf
  5. install -m 755 support-files/mysql.server /etc/init.d/mysql
  6. ps2:别忘记执行一步/usr/local/mysql/scripts/mysql_install_db .....
安装php

1.下载并解包php

cd /tmp

wget -c http://cn.php.net/get/php-5.3.6.tar.bz2/from/this/mirror
tar -xvf php-5.3.6.tar.bz2

2.编译并安装php

cd php-5.3.6
'./configure' \   
'--prefix=/usr/local/php' \   
'--enable-fpm' \   
'--with-curl' \   
'--with-curlwrappers' \   
'--with-libxml-dir' \   
'--with-gd' \   
'--with-imap' \   
'--enable-mbstring' \   
'--with-mysql=/usr/local/mysql/' \   
'--with-xsl' \   
'--enable-zip' \  
'--with-pear' \  
'--with-kerberos' \  
'--with-imap-ssl' \   
'--enable-bcmath' \   
'--with-libdir=lib64' \                                                 #64位系统需使用/lib64,32位系统无此目录
'--with-openssl' \  
'--with-zlib'
make
make install
 
  1. ps:php5.3.8版本在编译的时候记得最好加上"--with-config-file-path=..."这个选项,以免php找不到php.ini配置文件 

第三步:配置php-fpm

install -m 664 php.ini.production /usr/local/php/etc/php.ini
cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf

修改php-fpm.conf

#listen = 127.0.0.1:9000                                           #注释掉配置文件中这一行
listen = /dev/shm/php-fpm.sock                                     #新增该行
user = nginx
group = nginx
pm.max_children = 50                                               #取消注释
pm.start_servers = 20                                              #取消注释
pm.min_spare_servers = 5                                           #取消注释
pm.max_spare_servers = 35                                          #取消注释
 
  1. ps:修改php.ini文件,打开"short_open_tag=on

第四步:配置nginx

cd /usr/local/nginx/conf
cp nginx.conf.default nginx.conf

修改nginx.conf

修改第2行为

user nginx;

删除server字段大括中的所有内容,添加

listen      80 ;
server_name  ........;                          #用来访问的域名
index index.html index.php;
root  .........;                            #web根目录
 
location /
{   
    if (-f $request_filename) {       
        break;  
    }   
    if (!-f $request_filename) {       
        rewrite ^/(.+)$ /index.php?url=$1 last;       
        break;   
    }
}
 
location ~ .*\.(php|php5)?$
{   
      fastcgi_pass  unix:/dev/shm/php-fpm.sock;   
      fastcgi_index index.php;   
      include fastcgi.conf;
}
location /p_w_picpaths/ {   
      alias /var/www/p_w_picpaths/;
}
 
access_log  /var/log/nginx/.......log;

第五步:配置mysql

cd /tmp/mysql-5.1.57/support-files/
cp my-large.cnf /etc/my.cnf
install -m 755 mysql-server /etc/init.d/mysql
cd /usr/local/mysql/bin

第七步:启动mysql,php-fpm,nginx

使用mysql用户启动mysql服务,初始化root密码

su - mysql
/etc/init.d/mysql start
cd /usr/local/mysql/bin
./mysqladmin -u root password '...'

root用户启动php-fpm,nginx

/usr/local/php/sbin/php-fpm
/usr/local/nginx/sbin/nginx