为了账号安全,请及时绑定邮箱和手机立即绑定

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

标签:
PHP

Lnmp

Linux+php+mysql+nginx

Nginx与php结合是靠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(需要先安装libevent和pcre库)

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



如果想让nginx与php-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信息说明nginx与php结合成功

在测试php与mysql结合是否成功

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结合成功


点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消