当前位置首页 > Nginx知识

LNMP(Linux+Nginx+MySQL+PHP)centos6.4安装

阅读次数:243 次  来源:admin  发布时间:

ginx命令

停止nginx服务:# /etc/init.d/nginx sto

启动nginx服务:# /etc/init.d/nginx start

编辑nginx配置文件:# vim /etc/nginx/nginx.conf

/etc/init.d/php-fpm restart

ervice php-fpm start

最后只要 yum -y update 一下,全是最新的

别忘了开机启动

chkconfig --level 345 mysqld o

chkconfig --level 345 php-fpm o

chkconfig --level 345 nginx o

你可以用下列方法检查配置文件是否有语法错误

# /etc/init.d/nginx configtest

问题:

1.打开phpmyadmin时出现mysqli扩展

设置:extension_ext = "/var/lib64/php/modules"

2.打开phpmyadmin时,出现:Error during session start; please check your PHP and/or webserver log file and configure your PHP installation properly. Also ensure that cookies are enabled in your browser.

首先看session.auto_start = 0,如果设置0不行,就设置1.

如果还不行,看session.save_path,看看这个路径有没有权限。

1.MySQL

yum源:http://dev.mysql.com/downloads/repo/yum/

配置yum源:http://dev.mysql.com/doc/mysql-repo-excerpt/5.6/en/linux-installation-yum-repo.html

# yum -y install mysql-server

# chkconfig mysqld o

# service mysqld start

2.Nginx.

在/etc/yum.repos.d/目录下建立一个nginx.repo软件源配置文件。命令如下:

# cd /etc/yum.repos.d/

# vim

然后填写如下文件内容

[nginx] 
name=nginx repo 
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ 
gpgcheck=0 
enabled=1

注意:一定要看这句话(参考:http://nginx.org/en/linux_packages.html#stable)

执行vim命令保存文件为nginx.repo完整路径是/etc/yum.repos.d/nginx.repo

:w

执行yum命令安装nginx

yum install nginx

添加防火墙

在安装完成nginx后,需要设置防火墙设置允许80端口,操作如下:

# vim /etc/sysconfig/iptable

添加一行

-A INPUT –m state –state NEW –m tcp –p tcp –dport 80 –j ACCEPT 

在修改完防火墙后需要执行如下命令重启防火

# /etc/init.d/iptables restart

紧接着启动nginx

# /etc/init.d/nginx start

然后保存并退出:wq

ginx伪静态:

1.将include /www/web1.nginx加入到nginx的虚拟机配置文件中,

加入到location / {}部分。

2.伪静态文件:

rewrite ^/about\.html$ /?do=profile last;

注意:1.前部分需要加根目录斜线"/"

2.将RewriteRule改成rewrite

3.末尾加上 last

编译安装:(参考:http://lxsym.blog.51cto.com/1364623/293096)

安装PHP(PHP5.3以后,php-fpm就是php的核心模块存在了)

这个地方是最重要的地方,因为默认情况下Nginx和PHP他俩之间是一点感觉没有的。在之前,很多朋友都搭建过Apache+PHP,Apache+PHP编译后生成的是模块文件,而Nginx+PHP需要PHP生成可执行文件才可以,所以要利用fastcgi技术来实现Nginx与PHP的整合,这个只要我们安装是启用FastCGI即可。此次我们安装PHP不仅使用了FastCGI,而且还使用了PHP-FPM这么一个东东,PHP-FPM说白了是一个管理FastCGI的一个管理器,它作为PHP的插件纯在,在安装PHP要想使用PHP-FPM时就需要把PHP-FPM以补丁的形式安装到PHP中,而且PHP要与PHP-FPM版本一致,这是必须的,切记!

整合Nginx与PHP

上面已经讲过,Nginx自己并不处理动态网页的请求,而且Nginx将得到的动态请求转交给PHP,下面我们打开Nginx的配置文件看一下

#vi /etc/nginx/conf.d/default.conf

看上图,Nginx已经知道怎么把得到的请求传达给PHP,Nginx在得到*.php请求时,会把请求通过9000端口传给PHP。

那么只有Nginx自己知道咋找PHP了还不行,还需要PHP知道咋找Nginx,PS:你见过大街上的JJMM约会时有不是相互认识对方,或者是不知道用啥方法和对方接头的?这点我们不需要担心,PHP-FPM已经在配置文件中定义了从哪接受PHP请求,我们可以打开配置文件看一下

#vi /etc/php-fpm.d/www.conf

如上图所示,我们在前面已经看到过Nginx是通过本机的9000端口将PHP请求转发给PHP的,而上图我们可以看到PHP自己是从本机的9000端口侦听数据 ,Nginx与PHP通过本机的9000端口完成了数据请求。

hp源码安装:

1.cd /usr/local/php/

wget http://cn2.php.net/distributions/php-5.6.8.tar.gz

2.

./configure --prefix=/usr/local/php --enable-fpm --enable-mbstring --with-mysql=/usr/local/mysql --with-iconv-dir=/usr/local --with-apxs2=/usr/local/apache2/bin/apxs

PHP编译安装出现的各种问题:

hp版本:php-5.4.3

安装前.先安装些软件和库文件

yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-server

领导要我们自己手动装 不允许我们直接用yum 所以上面的都没执行

编译安装PHP

进入php的解压目录

./configure --prefix=/usr/local/php --enable-fpm --with-mcrypt=/usr/local/libmcrypt --with-zlib --enable-mbstring --with-openssl --with-mysql --with-mysqli --with-mysql-sock --with-gd --with-jpeg-dir=/usr/lib --enable-gd-native-ttf --enable-pdo --with-pdo-mysql --with-gettext --with-curl --with-pdo-mysql --enable-sockets --enable-bcmath --enable-xml --with-bz2 --enable-zip --enable-freetype

运行之后遇到的问题:

error 1

checking for xml2-config path...

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

(看提示就明白 是一个lib库没装 先用 yum search 名字 看是否能搜到名字 ,找到名字后 把软件包 开发包装上)

解决办法

yum install libxml2-devel.x86_64

error 2

checking for pkg-config... /usr/bin/pkg-config

configure: error: Cannot find OpenSSL's <evp.h>

这是ssl没装

解决办法

yum install openssl.x86_64 openssl-devel.x86_64 -y

error 3

checking for BZip2 in default path... not found

configure: error: Please reinstall the BZip2 distributio

这是bzip2软件包没有安装

解决办法

yum install bzip2-devel.x86_64 -y

error 4

configure: error: Please reinstall the libcurl distribution -

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

curl和curl库文件没有安装

解决办法

yum install libcurl.x86_64 libcurl-devel.x86_64 -y

error 5

checking whether to enable JIS-mapped Japanese font support in GD... no

checking for fabsf... ye

checking for floorf... ye

configure: error: jpeglib.h not found

GD库没有安装

解决办法

yum install libjpeg.x86_64 libpng.x86_64 freetype.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64 -y

error 6

checking for stdarg.h... (cached) ye

checking for mcrypt support... ye

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

libmcrypt库没有安装 ,要是不能用yun安装的话 就要去下载个gz包 自己编译安装

(编译安装 ./configure --piefix=/usr/local/libmcrypt make && make install)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

要是错误里面含有mysql的 那是mysql-devel 没有安装

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

出现

Generating files configure: creating ./config.status creating main/internal_functions.c creating main/internal_functions_cli.c

编译PHP的--with-gd=/usr/include

错误提示:

configure: error: Unable to find gd.h anywhere under

表明已经装好GD库啦,把后面的路径取消就可以啦

--with-gd --with-jpeg --with-png

ok

上一篇:实现WIN2003IIS最小权限分配的批处理
下一篇:linux安装网卡驱动