LNMP环境搭建

1. 安装mysql

cd /usr/local/src/

yum install �Cy wget   安装wget

yum install �Cy vim-enhanced安装vim

wget http://syslab.comsenz.com/downloads/linux/mysql-5.1.40-linux-i686-icc-glibc23.tar.gz

注意:上面的地址是32位机器用的,如果你的机器是64位,下载这个包(http://syslab.comsenz.com/downloads/linux/mysql-5.1.40-linux-x86_64-icc-glibc23.tar.gz)安装方法是一样的。

tar zxvf/usr/local/src/mysql-5.1.40-linux-i686-icc-glibc23.tar.gz

mv mysql-5.1.40-linux-i686-icc-glibc23/usr/local/mysql

useradd -s /sbin/nologin mysql

cd /usr/local/mysql              

mkdir -p /data/mysql

chown -R mysql:mysql /data/mysql

./scripts/mysql_install_db --user=mysql--datadir=/data/mysql

出现两个OK即为成功,或可以用echo$?查看反回值是否为0

cp support-files/my-large.cnf /etc/my.cnf (实际生产环境内存比较大为support-files/my-huge.cnf)MYSQL的配置文件,提示否覆盖,选择覆盖

cp support-files/mysql.server /etc/init.d/mysqld  MYSQL服务的启动文件

chmod 755 /etc/init.d/mysqld  给mysqld文件赋予权限

vim /etc/init.d/mysqld  

 #修改datadir和basedir如右     datadir=/data/mysql     basedir=/usr/local/mysql 然后保存退出。

chkconfig --add mysqld

chkconfig mysqld on

service mysqld start 会提示“Starting MySQL.. SUCCESS!”

 

2. php安装

Wget   http://cn2.php.net/distributions/php-5.4.37.tar.bz2

tar jxfphp-5.4.37.tar.bz2

useradd -s/sbin/nologin php-fpm

cd php-5.4.37

./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

make &&make install

cpphp.ini-production /usr/local/php/etc/php.ini

拷贝启动脚本:cp /usr/local/src/php-5.4.37/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

mv/usr/local/php/etc/php-fpm.conf.default  /usr/local/php/etc/php-fpm.conf

chmod 755/etc/init.d/php-fpm

chkconfig --addphp-fpm

service php-fpmstart

chkconfig php-fpmon

3. 安装nginx

cd /usr/local/src/

wget   http://nginx.org/download/nginx-1.8.0.tar.gz

tar zxvf nginx-1.8.0.tar.gz

cd nginx-1.8.0

yum  install -y pcre-devel

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

显示:

  nginx path prefix:"/usr/local/nginx"

  nginx binary file:"/usr/local/nginx/sbin/nginx"

  nginx configuration prefix:"/usr/local/nginx/conf"

  nginx configuration file:"/usr/local/nginx/conf/nginx.conf"

  nginx pid file:"/usr/local/nginx/logs/nginx.pid"

  nginx error log file:"/usr/local/nginx/logs/error.log"

  nginx http access log file:"/usr/local/nginx/logs/access.log"

  nginx http client request body temporaryfiles: "client_body_temp"

  nginx http proxy temporary files:"proxy_temp"

  nginx http fastcgi temporary files:"fastcgi_temp"

  nginx http uwsgi temporary files:"uwsgi_temp"

  nginx http scgi temporary files:"scgi_temp"

make && makeinstall

启动nginx: 

/usr/local/nginx/sbin/nginx

4. 编写nginx启动脚本

vim/etc/init.d/nginx  //加入如下内容

#!/bin/bash

# chkconfig: - 3021

# description:http service.

# Source FunctionLibrary

./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 a+x/etc/init.d/nginx

chkconfig --addnginx

chkconfig nginx on

 

5. 配置解析php

vim  /usr/local/nginx/conf/nginx.conf  //把下面的配置,前面的#删除,并更改红色部分

 

1.   

2.          location / {

3.              root   html;

4.              index  index.html index.htm index.php;

5.          }

6.    #中间省略…………

 

7.         location ~ \.php$ {

8.             root        /usr/local/nginx/html;

9.             fastcgi_pass   127.0.0.1:9000;

10.           fastcgi_index  index.php;

11.           fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;

12.                    

13.           include        fastcgi_params;

14.        }

15. 

###上面红色的/usr/local/nginx/html站点所在的目录

重新加载/usr/local/nginx/sbin/nginx -s  reload

 

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

增加  

< ?php

   phpinfo();

?>

 

测试: curllocalhost/1.php



件根据网络相关信息结合实际应用演义

 


你可能感兴趣的:(环境搭建,LNMP)