环境:

centos 6.2 x64

nginx 1.2.3

mysql 5.5.19

php 5.3.16

一、安装mysql

安装cmake(mysql5.5以后是通过cmake来编译的)centos6.2已经自带略过

  1. wget http://www.cmake.org/files/v2.8/cmake-2.8.4.tar.gz


  2. tar zxvf cmake-2.8.4.tar.gz


  3. cd cmake-2.8.4


  4. ./configure && make && make install

创建用户和用户组

  1. useradd -M -s /sbin/nologin mysql

安装mysql

  1. 安装必须的包:

  2. yum -y install ncurses-devel

tar zxvf mysql-5.5.19.tar.gz
cd mysql-5.5.19
cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ \
-DMYSQL_DATADIR=/data/mysql \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_TCP_PORT=3306 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DMYSQL_USER=mysql \
-DWITH_DEBUG=0
/*出现警告:
CMake Warning:
      Manually-specified variables were not used by the project:
      MYSQL_USER
*/可以忽略……
make && make install


复制配置文件

  1. [root@mysql-5.5.11]# cp support-files/my-huge.cnf /etc/my.cnf


  2. [root@mysql-5.5.11]# cp support-files/mysql.server /etc/init.d/mysqld


  3. [root@mysql-5.5.11]# chmod 700 /etc/init.d/mysqld

初始化数据库:自动生成路径:/data/mysql,权限为700,属主mysql,属组root

  1. /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/

设置开机启动

chkconfig --add mysqld  ---默认2345启动

启动mysql

service mysqld start

为了方便使用mysql命令,执行以下操作

ln -s /usr/local/mysql/bin/* /usr/bin/

mysql修改密码(安装后默认密码为空)

进入到mysql修改

#mysql

mysql>set password=password('123456');

或,直接使用命令修改:

mysqladmin -u root password 123456

二、安装nginx

安装pcre(不安装直接配置nginx时指向pcre源码解压目录也可)

yum -y install pcre*

创建nginx用户

  1. useradd -M -s /sbin/nologin ngx

安装nginx

  1. tar -zxvf ...

  2. cd ...

  3. ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --user=ngx --group=ngx --with-pcre

  4. make && make install


nginx命令

  1. 启动

  2. /usr/local/nginx/sbin/nginx

  3. 停止

  4. /usr/local/nginx/sbin/nginx -s stop

  5. 重载

  6. /usr/local/nginx/sbin/nginx -s reload

  7. 帮助

  8. /usr/local/nginx/sbin/nginx -h

测试是否安装成功

三、安装php

安装必须的rpm包

  1. yum -y install mysql-devel libjpeg-devel libmcrypt-devel libmhash-devel gd-devel libpng-devel openssl-devel curl-devel freetype-devel libxml2-devel

安装libmcrypt

解决:configure: error: mcrypt.h not found. Please reinstall libmcrypt.

tar zxvf ...

cd ...

make && make install

安装php

tar zxvf ...
cd ...
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/lib \
--enable-mbstring \
--enable-ftp \
--with-gd \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-mcrypt \
--with-mhash \
--with-pear \
--enable-sockets \
--with-freetype-dir=/usr \
--enable-gd-native-ttf \
--with-zlib \
--with-libxml-dir=/usr \
--with-xmlrpc \
--enable-zip \
--enable-fpm \
--enable-xml \
--enable-sockets \
--with-gd \
--with-zlib \
--with-iconv \
--enable-zip \
--with-openssl \
--with-curl \
--enable-pcntl \
--enable-soap
make && make install

复制配置文件

  1. cp php.ini-production /usr/local/lib/php.ini

复制启动脚本,并添加执行权限

  1. cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

  2. chmod 700 /etc/init.d/php-fpm

修改PHP-FPM配置文件

  1. cd /usr/local/php/etc

  2. mv php-fpm.conf.default php-fpm.conf

  3. vi php-fpm.conf

  4. 去掉以下行首的分号:

  5. pid = run/php-fpm.pid

  6. log....


启动php-fpm

service php-fpm start

关闭php-fpm

service php-fpm stop

重载php-fpm

service php-fpm reload

添加开机启动:

[root@localhost etc]# chkconfig --add php-fpm

四、配置nginx支持php

部分配置参数如下:

user  ngx;
server {
    listen       80;
    server_name  www.test.com;
    root   /data/webroot/shopex;
    index  index.php;
    location ~ \.php$ {
                    root           /data/webroot/shopex;
                    fastcgi_pass   127.0.0.1:9000;
                    fastcgi_index  index.php;
                    fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
                    include        fastcgi_params;
                    include        fastcgi.conf;
     }
}

网站根目录默认为:/usr/local/nginx/html/

访问测试站点