CentOS+Nginx+PHP+MySQL详细配置

CentOS+Nginx+PHP+MySQL详细配置

一、MySql安装前准备工作:

yum -y install gcc gcc-c++

首先需要保证自己的开发工具包已安装;未安装使用

yum  groupinstall  'Develop Tools '  -y

这样就不会出现缺少gcc和  No curses/termcap library found

安装过程出现configure: WARNING: unrecognized options: --with-innodb

需要更改参数。如下

二、软件包为mysql-5.1.52.tar.gz

放在/root下面。

vi mysql.sh

#!/bin/sh
groupadd mysql;
useradd mysql -g mysql -s /sbin/nologin -d /dev/null -M -c "just for mysql";
cd /root/
tar -zxvf mysql-5.1.52.tar.gz;
cd mysql-5.1.52;
./configure --prefix=/usr/local/mysql     \
                    --without-debug                   \
                    --with-pthread                    \
          --with-plugins=partition,blackhole,heap,innobase,myisam,ndbcluster            \
                    --with-big-tables                 \
                    --with-extra-charsets=all         \
                    --with-mysqld-ldflags=-rdynamic  \
                    --with-client-ldflags=-all-static \
                    --enable-assembler                \
                    --enable-local-infile             \
                    --enable-thread-safe-client      \
           
make ; make install;
/usr/local/mysql/bin/mysql_install_db  --user=mysql; chown -R root /usr/local/mysql;
chown -R mysql /usr/local/mysql/var;
chgrp -R mysql /usr/local/mysql;
cp /root/mysql-5.1.52/support-files/mysql.server /etc/init.d/mysqld;
chmod 755 /etc/init.d/mysqld;
chkconfig --add mysqld;
service mysqld restart;
/usr/local/mysql/bin/mysqladmin -u root password '123456';

cp mysql-5.1.52/support-files/my-medium.cnf /etc/my.cnf


安装好后vi  /etc/profile

export PATH=/usr/local/mysql/bin:$JAVA_HOME/bin:$PATH

保存退出

source /etc/profile




三、安装pcre

wget http://blog.s135.com/soft/linux/nginx_php/pcre/pcre-8.10.tar.gz

tar zxvf pcre-8.10.tar.gz
#cd pcre-8.10
#./configure //配置PCRE,因为PCRE是一个库,而不是像pache、php、postfix等这样的程序,所以我们安装时选择默认路径即可,这样会在后面安装其它东西时避免一些不必要的麻烦,执行完这部后会显示出下图,上面显示了我们对PCRE的配置

#make && make install

四、安装Nginx

在网上,看到不少人装Nginx 时非常麻烦,配置时用了一大堆选项,请问你们真实现那么多功能么?害的我越看越郁闷。此次安装Nginx如果是按着上面笔者的步骤一步步走下来,安装Nginx时只需指定Nginx的安装路径即可
wget http://blog.s135.com/soft/linux/nginx_php/nginx/nginx-0.8.46.tar.gz

#tar zxvf nginx-0.8.46.tar.gz

#cd nginx-0.8.46

#./configure --prefix=/usr/local/nginx //此处在本环节只需指定一个路径

#make && make install

#/usr/local/nginx/sbin/nginx //启Nginx

#echo "/usr/local/nginx/sbin/nginx" >>/etc/rc.local

Nginx启动后有两个进程,master为主进程,worker为工作进程

五、插件下载及安装:
wget http://nchc.dl.sourceforge.net/project/libpng/libpng14/1.4.11/libpng-1.4.11.tar.gz
wget ftp://ftp.usa.openbsd.org/pub/OpenBSD/distfiles/by_cipher/rmd160/GN/GNMaJsRHVkwlim9jV+kAJTbJq5Y=/jpegsrc.v8b.tar.gz
wget ftp://ftp.kfki.hu/pub/Sun/freeware/SOURCES/freetype-2.4.2.tar.gz
wget ftp://ftp.demos.ru/pub/sunfreeware/SOURCES/autoconf-2.57.tar.gz
wget http://google-desktop-for-linux-mirror.googlecode.com/files/gd-2.0.35.tar.gz
wget ftp://ftp.kfki.hu/pub/Sun/freeware/SOURCES/fontconfig-2.8.0.tar.gz
wget ftp://ftp.is.co.za/mirror/php.net/distributions/php-5.3.6.tar.gz

1、安装libpng
[root@localhost src]# cd libpng-1.4.11
[root@localhost libpng-1.4.11]# ./configure --prefix=/usr/local/png
[root@localhost libpng-1.4.11]#make; make install
2、安装jpeg

[root@localhost src]# mkdir -p /usr/local/jpeg/bin
[root@localhost src]# mkdir /usr/local/jpeg/include
[root@localhost src]# mkdir /usr/local/jpeg/lib
[root@localhost src]# mkdir -p /usr/local/jpeg/man/man1
[root@localhost jpeg-8b]# ./configure --prefix=/usr/local/jpeg/ --enable-shared --enable-static
[root@localhost jpeg-8b]# make ; make install
[root@localhost jpeg-8b]# ln -s /usr/local/jpeg/lib/* /usr/lib/
3、安装freetype
[root@localhost src]# cd freetype-2.4.2
[root@localhost freetype-2.4.2]# ./configure --prefix=/usr/local/freetype
[root@localhost freetype-2.4.2]#make ; make install
4、安装fontconfig
[root@localhost fontconfig-2.8.0]# ./configure  --prefix=/usr/local/fontconfig --with-freetype-config=/usr/local/freetype/bin/freetype-config
[root@localhost fontconfig-2.8.0]# make ; make install
5、安装GD
[root@localhost 2.0.35]# ./configure  --prefix=/usr/local/gd --with-png=/usr/local/png --with-jpeg=/usr/local/jpeg --with-freetype=/usr/local/freetype/ --with-fontconfig=/usr/local/fontconfig/
[root@localhost 2.0.35]# make ; make install
6\1、、安装PHP5.3
wget http://php-fpm.org/downloads/php-5.2.8-fpm-0.5.10.diff.gz
[root@localhost src]# tar -zxvf php-5.3.6.tar.gz
[root@localhost src]# gzip -cd php-5.2.8-fpm-0.5.10.diff.gz |patch -d php-5.3.6 -p1
[root@localhost php-5.3.6]# ./configure --prefix=/usr/local/php --with-gd=/usr/local/gd/ --with-jpeg-dir=/usr/local/jpeg/ --with-png-dir=/usr/local/png/ --with-freetype-dir=/usr/local/freetype/ --with-mysql=/usr/local/mysql/ --enable-fastcgi --enable-fpm

注:Nginx+PHP整合,在安装时必须启用--enable-fastcgi和 --enable-fpm

[root@localhost php-5.3.6]# make; make install

php-5.3会报以下错误:
[root@localhost php-5.3.6]/usr/local/php/sbin/php-fpm start
Usage: php-fpm [-n] [-e] [-h] [-i] [-m] [-v] [-t] [-p <prefix> ] [-c <file>] [-d foo[=bar]] [-y <file>]
  -c <path>|<file> Look for php.ini file in this directory
  -n               No php.ini file will be used

处理:
复制php.ini到配置文件目录及php-fpm 开机启动
cp php.ini-production /usr/local/php/etc/php.ini
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
这时候还不能使用/etc/init.d/php-fpm start启动,需修改一下php-fpm配置文件才可以,配置文件位置php安装目录 etc 目录下,默认有个参考文件.
cp php-fpm.conf.default php-fpm.conf
nano php-fpm.conf
,pm.start_servers = 20
,pm.min_spare_servers = 5
,pm.max_spare_servers = 35

[root@localhost sbin]# /etc/init.d/php-fpm start

可加到自动启动选项:
[root@localhost sbin]#echo "/etc/init.d/php-fpm start" /etc/rc.local


vi /usr/local/nginx/conf/nginx.conf //标的部分是我们后面要修改的
    location ~ \.php$ {
             root           html;
             fastcgi_pass   127.0.0.1:9000;
             fastcgi_index  index.php;
             fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;
             include        fastcgi_params;
         }
杀掉进程再重启一下ps -ef |grep nginx |awk '{print $2}' |xargs kill -9

#/usr/local/nginx/sbin/nginx //启Nginx

#echo "/usr/local/nginx/sbin/nginx" >>/etc/rc.local

test.php
<?php phpinfo(); ?>

可以打开页面进行测试

6\1、、安装PHP5.2
下载:
wget http://php-fpm.org/downloads/php-5.2.6-fpm-0.5.9.diff.gz
tar -zxvf php-5.2.6.tar.gz
gzip -cd php-5.2.6-fpm-0.5.9.diff.gz |patch -d php-5.2.6 -p1


[root@localhost ~]#./configure --prefix=/usr/local/php --with-gd=/usr/local/gd/ --with-jpeg-dir=/usr/local/jpeg/ --with-png-dir=/usr/local/png/ --with-freetype-dir=/usr/local/freetype/ --with-mysql=/usr/local/mysql/ --enable-fastcgi --enable-fpm
[root@localhost ~]#make; make install
[root@localhost ~]# /usr/local/php/sbin/php-fpm start
Starting php_fpm May 23 13:39:29.537803 [ERROR] fpm_unix_conf_wp(), line 124: please specify user and group other than root, pool 'default'

报错处理:
解决办法;
只需要修改php-fpm.conf
          Unix user of processes
<!--     <value name="user">nobody</value>   -->
          Unix group of processes
<!--     <value name="group">nobody</value>   -->
    
将<!– –>去掉即可。至于user/group根据实际情况修改(www)。
重新启动 /usr/local/webserver/php-fpm/sbin/php-fpm start 成功了!



你可能感兴趣的:(nginx)