您的位置:首页 > 运维架构 > Nginx

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

2014-03-07 23:59 567 查看
Lnmp
Linux+php+mysql+nginx
Nginx与php结合是靠fastcgi (端口9000)
安装绿色版本mysql 端口 tcp 3306
1、groupadd –r mysqluseradd –r –g mysql mysqltar zxvf –C /usr/local/cd /usr/local/ln -s /usr/local/mysql/include/ /usr/include/mysql 这里要用绝对路径cd mysqlchown -R mysql.mysql .scripts/mysql_install_db --user=mysqlchown –R root .chown –R mysql date cp support-files/my-medium.cnf /etc/my.cnfcp support-files/mysql.server /etc/init.d/mysqld service mysqld startchkconfig –add mysqldchkconfig mysqld onvim /etc/profilePATH=$PATH:/usr/local/mysql/bin. /etc/profileEcho $PATHvim /etc/ld.so.conf.d/mysql.conf/usr/local/mysql/libLdconfigLdconfig –pv |grep mysqlln -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/libeventMake && make installvim /etc/ld.so.conf.d/libevent.conf/usr/local/libevent/libLdconfigldconfig -pv |grep libeventln -s /usr/local/libevent/include/ /usr/include/libeventrpm -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 nginxuseradd –r –g nginx nginxcd /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 installmkdir -pv /var/tmp/nginx/client/编辑nginx脚本vim /etc/init.d/nginxchmod a+x /etc/init.d/nginx#!/bin/bashprog=/usr/local/nginx/sbin/nginxpid=/var/run/nginx/nginx.pidlock=/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)stopstart;;*)echo "the usage {start|stop|status|restart}"esacchkconfig --add nginxchkconfig nginx on

安装php 支持fastcgi1、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/profilePATH=$PATH:/usr/local/mysql/bin:/usr/local/php/bin
mkdir -p /etc/php /etc/php5.dPhp.ini文件(php的初始文件) Cd /usr/local/src/php-5.5.9
Cpphp.ini-production /etc/php/php.iniPhp-fpm 的控制脚本Cpsapi/fpm/init.d.php-fpm /etc/init.d/php-fpmChmod a+x/etc/init.d/php.fpm产生php-fpm的配置文件Cd/usr/local/src/phpCpphp-fpm.conf.default php-fpm.conf
Servicephp-fpm startNetstat –tunlp|grep php-fpm Chkconfig –add php-fpmChkconfigphp-fpm on

如果想让nginx与php-fpm相结合需要更改nginx的配置文件Vim/etc/nginx/nginx.conflocation/ { 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.phpvim/usr/local/nginx/html/index.php<?phpphpinfo();?>用网页测试如果出现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结合成功
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息