系统版本centos6.5


一、安装MySQL

1.下载MySQL

 wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz

2.解压MySQL

 tar -zxvf mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz

3.将解压出的数据移到/usr/local/mysql

mv mysql-5.6.26-linux-glibc2.5-x86_64 /usr/local/mysql

4.建立MySQL用户

useradd -s /sbin/nologin mysql

5.初始化

[root@localhost src]# cd /usr/local/mysql
[root@localhost mysql]# mkdir -p /data/mysql ; chown -R mysql:mysql /data/mysql
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
6.修改环境配置
[root@localhost mysql]# cp support-files/my-default.cnf /etc/my.cnf
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
# chmod 755 /etc/init.d/mysqld
# vim /etc/init.d/mysqld
修改basedir=/usr/local/mysql
    datadir=/data/mysql
#vim /etc/my.cnf
修改basedir = /usr/local/mysql
    datadir = /data/mysql
    port = 3306
    socket = /tmp/mysql.sock
    server_id = 1
7.启动MySQL
service mysqld start

二、安装PHP

1.下载php源码包

#cd /usr/local/src/

#wget http://au1.php.net/distributions/php-5.4.44.tar.bz2

2.解压源码包,创建账号

# tar jxf php-5.4.44.tar.bz2 # useradd -s /sbin/nologin php-fpm 该账号用来运行php-fpm服务,在LNMP环境中,php是以一个服务来提供服务的。 

3.配置编译选项 

#cd php-5.4.44

# ./configure --prefix=/usr/local/php  --with-config-file-path=/usr/local/php/etc  --enable-fpm   --with-fpm-user=php-fpm  --with-fpm-group=php-fpm   --with-mysql=/usr/local/mysql  --with-mysql-sock=/tmp/mysql.sock  --with-libxml-dir  --with-gd   --with-jpeg-dir   --with-png-dir   --with-freetype-dir  --with-iconv-dir   --with-zlib-dir   --with-mcrypt   --enable-soap   --enable-gd-native-ttf   --enable-ftp  --enable-mbstring  --enable-exif    --disable-ipv6     --with-curl

编译过程中会碰到下面这些错误:

checking for cc... no

checking for gcc... no

configure: error: in `/usr/local/src/php-5.4.37':

configure: error: no acceptable C compiler found in $PATH

See `config.log' for more details

解决办法:yum install -y gcc

②configure: error: xml2-config not found. Please check your libxml2 installation.

解决办法:yum install -y libxml2-devel

③configure: error: Please reinstall the libcurl distribution -

    easy.h should be in <curl-dir>/include/curl/

解决办法:yum install -y curl-devel

④configure: error: jpeglib.h not found.

解决办法:yum install -y libjpeg libjpeg-devel

⑤configure: error: png.h not found.

解决办法:

yum install -y libpng libpng-devel

⑥configure: error: freetype-config not found.

解决办法:yum install -y freetype freetype-devel

⑦configure: error: mcrypt.h not found. Please reinstall libmcrypt.

解决办法:因为yum库是没有这个包的,所以要去下载个第三方yum源

rpm -ivh "http://www.aminglinux.com/bbs/data/p_w_upload/forum/month_1211/epel-release-6-7.noarch.rpm"

然后yum install -y  libmcrypt-devel

3.make && make install

4.修改配置文件

[root@localhost php-5.4.37]# cp php.ini-production /usr/local/php/etc/php.ini

[root@localhost php-5.4.37]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

[root@localhost php-5.4.37]# mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

[root@localhost php-5.4.37]# chmod 755 /etc/init.d/php-fpm

5.启动php

service php-fpm start

三、安装nginx

  1. 下载nginx源码包

#wget http://nginx.org/download/nginx-1.6.3.tar.gz

2.解压

# tar -zxvf nginx-1.6.3.tar.gz

3.cd nginx-1.6.3

# ./configure   --prefix=/usr/local/nginx   --with-pcre

可能会碰到

./configure: error: the HTTP rewrite module requires the PCRE library.

You can either disable the module by using --without-http_rewrite_module

option, or install the PCRE library into the system, or build the PCRE library

statically from the source with nginx by using --with-pcre=<path> option.

解决办法:yum install -y pcre pcre-devel

4.make && make install

5.编译启动脚本

vim /etc/init.d/nginx

写入以下内容:

#!/bin/bash

# chkconfig: - 30 21

# description: http service.

# Source Function Library

. /etc/init.d/functions

# Nginx Settings


NGINX_SBIN="/usr/local/nginx/sbin/nginx"

NGINX_CONF="/usr/local/nginx/conf/nginx.conf"

NGINX_PID="/usr/local/nginx/logs/nginx.pid"

RETVAL=0

prog="Nginx"


start() {

        echo -n $"Starting $prog: "

        mkdir -p /dev/shm/nginx_temp

        daemon $NGINX_SBIN -c $NGINX_CONF

        RETVAL=$?

        echo

        return $RETVAL

}


stop() {

        echo -n $"Stopping $prog: "

        killproc -p $NGINX_PID $NGINX_SBIN -TERM

        rm -rf /dev/shm/nginx_temp

        RETVAL=$?

        echo

        return $RETVAL

}


reload(){

        echo -n $"Reloading $prog: "

        killproc -p $NGINX_PID $NGINX_SBIN -HUP

        RETVAL=$?

        echo

        return $RETVAL

}


restart(){

        stop

        start

}


configtest(){

    $NGINX_SBIN -c $NGINX_CONF -t

    return 0

}


case "$1" in

  start)

        start

        ;;

  stop)

        stop

        ;;

  reload)

        reload

        ;;

  restart)

        restart

        ;;

  configtest)

        configtest

        ;;

  *)

        echo $"Usage: $0 {start|stop|reload|restart|configtest}"

        RETVAL=1

esac

exit $RETVAL

保存后

# chmod 755 /etc/init.d/nginx

6.配置解析php

vim /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;

        }


7.重新加载

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

8.测试是否解析php文件

# vim /usr/local/nginx/html/1.php

<?php

    phpinfo();

?>

~

9.curl localhost/1.php或者web浏览器上http://本机ip/1.php

如果解析,LNMP搭建成功