LNMP(Linux+Nginx+Mysql+PHP)的搭建

Lnmp

Linux+php+mysql+nginx

Nginxphp结合是靠fastcgi (端口9000

安装绿色版本mysql  端口 tcp 3306

1、groupadd –r mysql

useradd –r –g mysql mysql

tar zxvf –C /usr/local/

cd /usr/local/

ln -s /usr/local/mysql/include/ /usr/include/mysql 这里要用绝对路径

cd mysql

chown -R mysql.mysql .

scripts/mysql_install_db --user=mysql

chown –R root .

chown –R mysql date

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

cp support-files/mysql.server  /etc/init.d/mysqld

service mysqld start

chkconfig –add mysqld

chkconfig mysqld on

vim /etc/profile

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

. /etc/profile

Echo $PATH

vim /etc/ld.so.conf.d/mysql.conf

/usr/local/mysql/lib

Ldconfig

Ldconfig –pv |grep mysql

ln -s include /usr/include/mysql


安装nginx(需要先安装libeventpcre库)

1、tar zxvf libevent-2.0.21-stable.tar.gz  -C /usr/local/src/

cd /usr/local/src/libevent-2.0.21-stable/

./configure --prefix=/usr/local/libevent

Make  && make install

vim /etc/ld.so.conf.d/libevent.conf

/usr/local/libevent/lib

Ldconfig

ldconfig -pv |grep libevent

ln -s /usr/local/libevent/include/ /usr/include/libevent

rpm -ivh pcre-devel-6.6-2.el5_1.7.i386.rpm


tar zxvf nginx-1.5.11.tar.gz -C /usr/local/src/

groupadd -r nginx

useradd –r –g nginx nginx

cd /usr/local/src/nginx-1.5.11/

./configure  \

> --conf-path=/etc/nginx/nginx.conf \

> --error-log-path=/var/log/nginx/error.log \

> --http-log-path=/var/log/nginx/access.log \

> --pid-path=/var/run/nginx/nginx.pid \

> lock-path=/var/lock/nginx.lock \

> --user=nginx \

> --group=nginx \

> --with-http_ssl_module \

> --with-http_flv_module \

> --with-http_stub_status_module \

> --with-http_gzip_static_module \

> --http-client-body-temp-path=/var/tmp/nginx/client/ \

> --http-proxy-temp-path=/var/tmp/nginx/proxy/ \

>--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \

>--with-pcre


Make && make install

mkdir -pv /var/tmp/nginx/client/

编辑nginx脚本

vim /etc/init.d/nginx

chmod a+x /etc/init.d/nginx

#!/bin/bash

prog=/usr/local/nginx/sbin/nginx

pid=/var/run/nginx/nginx.pid

lock=/var/lock/nginx.lock


# chkconfig: - 61 52

# description: nginx is a httpd daemon, which is the program

start () {

[ -f $lock ] && echo "the nginx is started"&& exit


echo -n "the nginx is starting......"

sleep 1

$prog && echo "[ ok ]" && touch $lock  || "[ fail]"


}

stop () {

[ ! -f $lock ] && echo "the nginx is stoped " && exit

echo -n "the nginx is stoping ......."

sleep 1

$prog -s stop  && echo"[ ok ]" && rm -rf $lock || echo "[ fail ]"

}

status () {

[ -f $pid ] && echo "the nginx is run..... pid is `cat$pid`" ||

echo "the nginx isstoped "


}


case "$1" in

start)

start

;;

stop)

stop

;;

status)

status

;;

restart)

stop

start

;;

*)

echo "the usage {start|stop|status|restart}"

esac

chkconfig --add nginx

chkconfig  nginx on



安装php 支持fastcgi

1、tar zxvf php-5.5.9.tar.gz -C /usr/local/src/

cd /usr/local/src/php-5.5.9/

[root@wnt252php-5.5.9]# ./configure  \

>--prefix=/usr/local/php \

>--enable-fpm \

>--enable-sockets \

>--with-mysql=/usr/local/mysql \

>--with-mysqli=/usr/local/mysql/bin/mysql_config \

>--enable-mbstring \

>--enable-xml \

>--with-png-dir \

> --with-jpeg-dir \

>--with-zlib \

>--with-freetype-dir \

>--with-config-file-path=/etc/php \

>--with-config-file-scan-dir=/etc/php5.d


Make&& make install


vim/etc/profile

PATH=$PATH:/usr/local/mysql/bin:/usr/local/php/bin


mkdir -p /etc/php /etc/php5.d

Php.ini文件(php的初始文件)

         Cd /usr/local/src/php-5.5.9

Cpphp.ini-production /etc/php/php.ini

Php-fpm 的控制脚本

Cpsapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

Chmod a+x/etc/init.d/php.fpm

产生php-fpm的配置文件

Cd/usr/local/src/php

Cpphp-fpm.conf.default php-fpm.conf


Servicephp-fpm start

Netstat –tunlp|grep php-fpm

Chkconfig –add php-fpm

Chkconfigphp-fpm on



如果想让nginxphp-fpm相结合需要更改nginx的配置文件

Vim/etc/nginx/nginx.conf

location/ {

44            root   html;

45            index index.php index.html index.htm;

46        }

65         location ~ \.php$ {

66            root           html;

67            fastcgi_pass   127.0.0.1:9000;

68            fastcgi_index  index.php;

69      fastcgi_paramSCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;

70            include        fastcgi_params;

71        }


mysqladmin-u root -p password ‘123‘给数据库管理员一个口令

mv/usr/local/nginx/html/index.html /usr/local/nginx/html/index.php

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

<?php

phpinfo();

?>

用网页测试如果出现php信息说明nginxphp结合成功

在测试phpmysql结合是否成功

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

<?php

$link=mysql_connect("127.0.0.1","root","123");

if($link)

echo"ok";

else echo"fail";

?>

如果显示ok则表示与mysql结合成功


LNMP(Linux+Nginx+Mysql+PHP)的搭建,布布扣,bubuko.com

LNMP(Linux+Nginx+Mysql+PHP)的搭建

上一篇:Windows 8.1 新增控件之 CommandBar


下一篇:SQL语句优化策略