lnmp环境搭建

1.nginx安装


1.1 由于nginx要pcre的支持所以先安装pcre
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.34.tar.bz2
tar jxf pcre-8.34.tar.bz2
cd pcre-8.34

./configure  

make && make install


1.2下载

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


1.3 安装

添加nginx用户

groupadd www

useradd -g www www

tar zxf nginx-1.5.10.tar.gz

cd nginx-1.5.10

./configure --prefix=/usr/local/nginx \

--group=www \

--user=www \

--with-http_stub_status_module

make && make install


1.3 nginx部分配置

location ~ \.php$ {

            root           html;

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

            include        fastcgi_params;

        }


2.mysql安装


2.1 下载MYSQL:

ftp://mirror.switch.ch/mirror/mysql/Downloads/MySQL-5.1/mysql-5.1.62.tar.gz


2.2 创建mysql用户

groupadd mysql

useradd -g mysql mysql


2.3 安装

tar zxf mysql-5.1.62.tar.gz

cd mysql-5.1.62

./configure --prefix=/usr/local/mysql \

--sysconfdir=/etc \

--localstatedir=/var/lib/mysql \

--with-tcp-port=3306 \

--with-unix-socket-path=/var/lib/mysql/mysqld.socket \

--with-mysqld-user=mysql \

--enable-assembler \

--with-charset=utf8 \

--with-extra-charsets=all \

--enable-thread-safe-client \

--with-big-tables \

--with-readline \

--with-ssl \

--with-embedded-server \

--enable-local-infile \

--with-client-ldflags=-all-static \

--with-mysqld-ldflags=-all-static \

--with-debug \

--with-plugins=partition,innobase,myisammrg,myisam

make && make install


2.4 善后处理

cp /usr/local/mysql/share/mysql/mysql.server /etc/rc.d/init.d/mysqld

cp /usr/local/mysql/share/mysql/my-huge.cnf /etc/my.cnf

chmod 700 /etc/rc.d/init.d/mysqld

chkconfig --add mysqld

chown -R mysql /usr/local/mysql

chgrp -R mysql /usr/local/mysql

/usr/local/mysql/bin/mysql_install_db --user=mysql

chown -R root /usr/local/mysql

/usr/local/mysql/bin/mysqld_safe --user=mysql &


3.php安装


3.1 下载安装php-fpm,php-fpm是php,fastcgi进程管理器,是php的一个补丁

要先将php-fpm patch到php源代码中,编译安装php后才可以使用。

wget http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz

wget http://museum.php.net/php5/php-5.2.17.tar.gz

tar zxf php-5.2.17.tar.gz

gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1

./configure --prefix=/usr/local/php \

--with-config-file-path=/usr/local/php/etc \

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

--with-mysqli \

--enable-sysvsem \

--enable-sysvshm \

--enable-pcntl \

--enable-mbregex \

--enable-zip \

--with-pcre-regex \

--with-libxml-dir \

--with-gd \

--with-jpeg-dir \

--with-png-dir \

--with-freetype-dir \

--with-iconv-dir \

--with-zlib-dir  \

--enable-sockets \

--enable-soap \

--enable-gd-native-ttf \

--enable-ftp \

--enable-mbstring \

--enable-exif \

--enable-zend-multibyte \

--disable-ipv6 \

--disable-debug \

--enable-fastcgi \

--enable-fpm

make && make install

cd 源码php解压后的目录

cp php.ini-dist /usr/local/php/etc/php.ini

3.2 修改php-fpm的用户,保持和nginx一致

vim /usr/local/php/etc/php-fpm.conf

Unix user of processes

<value name="user">www</value>

Unix group of processes

<value name="group">www</value>


3.3 启动php-fpm

/usr/local/php/sbin/php-fpm start


3.4 到此lnmp环境搭建完成,在/usr/local/nginx/html下新建文件phpinfo.php,用于测试

vim phpinfo.php

<?php

phpinfo();

?>

在浏览器中输入http://ip/phpinfo.php,如果出现下图所示页面则lnmp环境搭建成功


4.常见错误


4.1 inux下安装安装pcre-8.32 configure: error: You need a C++ compiler for C++ support

linux下安装安装pcre-8.32
./configure --prefix=/usr/local/pcre 出现以下错误 :

configure: error: You need a C++ compiler for C++ support

解决方法:

yum install -y gcc gcc-c++

4.2 zlib library not found解决方法

解决方法

yum install zlib-devel;


4.3 解决configure: error: OpenSSL Crypto library not found
crypto是什么呢? 是OpenSSL 加密库(lib), 这个库需要openssl-devel包 ,在ubuntu中就是 libssl-dev
RedHat Fedora 平台
yum -y install openssl-devel



Debian ,ubunu 平台

apt-get install libssl-dev


4.4 Nginx: error while loading shared libraries: libpcre.so.1解决
Shell代码  
[ew69@localhost conf]# /usr/local/nginx/sbin/nginx  
/usr/local/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory  
 
确认已经安装PCRE: 
Shell代码  
[ew69@SCLABHADOOP01 lib]$ cd /lib  
[ew69@SCLABHADOOP01 lib]$ ls *pcre*  
libpcre.so.0  libpcre.so.0.0.1  
[hadoop@SCLABCLUS01 nginx]$ find / -type f -name *libpcre.so.*   
添加软链接:
Shell代码  
[ew69@SCLABHADOOP01 lib]$ ln -s /lib/libpcre.so.0.0.1 /lib/libpcre.so.1  
前面在一般的linux上可以解决此问题.
 
注: 在有的操作系统上面,安装pcre后,安装的位置为/usr/local/lib/*pcre*
在redhat 64位机器之上有这样的情况.
在redhat 64位机器上, nginx可能读取的pcre文件为/lib64/libpcre.so.1文件.
所以在改用下面的软连接:
Shell代码  

[hadoop@SCLABHADOOP01 ~]$ ln -s /usr/local/lib/libpcre.so.1 /lib64/  


4.5 安装mysql,在./configure时出现错误:error: No curses/termcap library found的解决办法
解决办法:
下载安装相应软件包
一、如果你的系统是RedHat系列:
yum list|grep ncurses
yum -y install ncurses-devel
yum install ncurses-devel
二、如果你的系统是Ubuntu或Debian:
apt-cache search ncurses
apt-get install libncurses5-dev
4.6 /bin/rm: cannot remove `libtoolT’: No such file or directory 解决方案

这时直接打开 configure,把 $RM “$cfgfile” 那行删除掉,重新再运行 ./configure 就可以了。


4.6 安装PHP,Configure: error: XML configuration could not be found

yum install libxml2-devel


4.7 configure: error: libjpeg.(a|so) not found.

检查之后发现已经安装了libjpeg,但是在/usr/lib目录下没有libjpeg.so这个文件,在/usr/lib64下是有的,虽然使用–with-jpeg-dir=/usr/lib64 依然无效,最后用:

ln -s /usr/lib64/libjpeg.so /usr/lib/libjpeg.so


4.8 遇configure: error: libjpeg.(a|so) not found. 解决 

yum install libjpeg-devel 


4.9 Configure: error: libpng.(also) not found

yum install libpng libpng-devel


4.10 configure: error: freetype.h not found.

yum install freetype-devel


4.11 configure: error: Please reinstall the mysql distribution

yum install mysql-devel





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值