nginx php mysql安装和部署

安装mysql

安装mysql很简单,我用的是centos系统 安装mysql可以用yum命令安装

yum install -y mysql-server mysql-devel mysql

安装php

安装php麻烦的地方是在configure的时候选项的配置

如果php版本是5.2.x 还需要安装php-fpm

先下载php-fpm代码,解压之后给php源码打补丁

gzip -cd php-5.2.13-fpm-0.5.13.diff.gz | patch -d php-5.2.13 -p1 

在./configure的时候加上--enable-fpm选项

如果php是5.3.x以上版本,则不需要给php源码打补丁,只需要在./configure的时候加上--enable-fpm就可以了

由于我是64位系统 安装mysql的时候 *.so的文件会在lib64的文件夹下,在./configure时需要指明lib64,--with-libdir=lib64

./configure --prefix=/usr/local/php --enable-fpm  --with-mysql=/usr --with-pdo-mysql=/usr --with-libdir=lib64 --with-mysqli=/usr/bin/mysql_config

这里顺便说下 如果安装php的mysql驱动时 可以不需要使用mysql自带的libmysql驱动,也可以使用php自己的驱动

如果使用mysql的驱动,则./configure的时候需要加上选项

--with-mysql=/usr(注意如果系统是64位 还需要加上--with=libdir=64)

如果使用自带的mysql驱动 可以使用如下选项

--with-mysql=mysqlnd

--with-mysqli=mysqlnd

--with-pdo-mysql=mysqlnd  

完全命令就是

./configure --prefix=/usr/local/php --enable-fpm --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd

编译完之后

make
make install

这时候就可以在目录/usr/local/php中看到我们安装的php,但是现在还不能用php这个命令,需要设置PATH环境变量

vi /etc/profile

在文件末尾加上

export PHP_PATH=/usr/local/php
export PATH=$PATH:$PHP_PATH/bin:$PHP_PATH/sbin

添加完之后保存,输入一下命令生效

source /etc/profile  

安装nginx

安装nginx很简单,可以用yum install nginx ,也可以用nginx源码编译安装

从官方下载nginx源码

解压后进入文件夹下

./configure --prefix=/usr/local/nginx  
make   
make install

同样会在/usr/l vi /etc/profileocal/nginx下看到我们安装的nginx

设置下PATH环境变量

在文件末尾加上

export NGINX_PATH=/usr/local/nginx
export PATH=$PATH:$NGINX_PATH/sbin

添加完之后保存,输入一下命令生效

source /etc/profile 

配置nginx

nginx需要使用fastcgi来解析php程序,使用nginx之前 需要开启php-fpm程序
php-fpm
nginx.conf配置如下:

location / {  
        index  index.html index.php;  
        root   /opt/web/php/test;  
    }  

    #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;  
    }  

    location ~ \\.php$ {  
        root   /opt/web/php/test;  
        fastcgi_pass 127.0.0.1:9000;  
        fastcgi_index index.php;  
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;  
        include fastcgi_params;  
    }  

你可能感兴趣的:(nginx php mysql安装和部署)