码迷,mamicode.com
首页 > 其他好文 > 详细

lnmp环境源码编译安装记录

时间:2014-08-04 18:18:29      阅读:402      评论:0      收藏:0      [点我收藏+]

标签:lnmp源码安装

系统:Cenos 6.5 X64

软件:

tengine-2.0.3.tar.gz

pcre-8.33.tar.bz2

mysql-5.6.12.tar.gz

php-5.5.14.tar.bz2




一、安装nginx

1.1 安装nginx所需的pcre-devel库,使nginx支持HTTP Rewrite模块

[root@node3pcre-8.33]# ./configure --prefix=/home/webserver/pcre  && make && make install

1.2 安装nginx

[root@node3 ~]# yum-y install openssl openssl-devel

[root@node3 ~]# tarzxf tengine-2.0.3.tar.gz

[root@node3 ~]# cdtengine-2.0.3

[root@node3tengine-2.0.3]# ./configure \

--prefix=/home/webserver/nginx\

 --with-http_stub_status_module  \

--with-pcre=/root/pcre8.33/ \

  --with-http_realip_module

#注意pcre不是安装到的位置,而是pcre源码包的位置

[root@node3tengine-2.0.3]# make && make install

二、安装Mysql:

2.1 安装mysql

[root@node3mysql-5.6.12]# useradd -s /sbin/nologin mysql

[root@node3mysql-5.6.12]# yum -y install cmake ncurses ncurses-devel

[root@node3mysql-5.6.12]# cmake . -DCMAKE_INSTALL_PREFIX=/home/webserver/mysql-DMYSQL_UNIX_ADDR=/home/webserver/mysql/mysql.sock -DDEFAULT_CHARSET=utf8-DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1-DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1-DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1-DMYSQL_DATADIR=/home/webserver/database -DMYSQL_USER=mysql

[root@node3mysql-5.6.12]# make && make install

[root@node3mysql-5.6.12]# chown  -R  mysql:mysql /home/webserver/mysql/

 

2.2 初始化数据库:

[root@node3mysql-5.6.12]# chmod  +xscripts/mysql_install_db

[root@node3mysql-5.6.12]# ./scripts/mysql_install_db --user=mysql --basedir=/home/webserver/mysql--datadir=/home/webserver/database

 

2.3 创建配置文件:

[root@node3 mysql-5.6.12]#cp support-files/my-default.cnf /etc/my.cnf

cp:是否覆盖"/etc/my.cnf"? y

 

2.4 创建启动脚本:

[root@node3mysql-5.6.12]# cp support-files/mysql.server /etc/init.d/mysqld

[root@node3mysql-5.6.12]# chmod +x /etc/init.d/mysqld

[root@node3mysql-5.6.12]# chkconfig --add mysqld

 [root@node3 mysql-5.6.12]# ckconfig mysqld on

[root@node3mysql-5.6.12]# chkconfig mysqld --list

mysqld          0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭

 

2.5 加mysql bin目录到$PATH中

[root@node3mysql-5.6.12]# echo ‘export PATH=$PATH:/home/webserver/mysql/bin‘ >>/etc/profile

[root@node3mysql-5.6.12]# source  /etc/profile

 

2.6 启动mysql:

[root@node3mysql-5.6.12]# /etc/init.d/mysqld start

Starting MySQL...SUCCESS!

 

2.7 设置mysql root用户密码:

[root@node3mysql-5.6.12]# mysqladmin  -u rootpassword ‘zrer90‘

三、安装PHP

3.1 安装php依赖库

3.1.1:安装jpeg9

[root@node3 ~]# wgethttp://www.ijg.org/files/jpegsrc.v9.tar.gz

[root@node3 ~]# tar-zxvf jpegsrc.v9.tar.gz

[root@node3 ~]# cdjpeg-9/

[root@node3 jpeg-9]#./configure  --prefix=/home/webserver/libs  --enable-shared --enable-static &&make && make install

3.1.2:安装png

[root@node3 ~]#     wgethttp://prdownloads.sourceforge.net/libpng/libpng-1.6.2.tar.gz

[root@node3 ~]# tarzxf libpng-1.6.2.tar.gz

[root@node3 ~]# cdlibpng-1.6.2

[root@node3libpng-1.6.2]# ./configure --prefix=/home/webserver/libs/ && make&& make install

3.1.3:安装freetype

[root@node3 ~]#      wgethttp://download.savannah.gnu.org/releases/freetype/freetype-2.4.12.tar.gz

[root@node3 ~]# tarzxf freetype-2.4.12.tar.gz

[root@node3 ~]# cdfreetype-2.4.12

[root@node3freetype-2.4.12]# ./configure --prefix=/home/webserver/libs && make&& make install

 

3.1.4:安装libmcrypt:

[root@node3 ~]#wget http://downloads.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz

[root@node3 ~]# tarzxf libmcrypt-2.5.8.tar.gz

[root@node3libmcrypt-2.5.8]# ./configure --prefix=/home/webserver/libs  && make && make install

[root@node3libmcrypt-2.5.8]# cd libltdl/

[root@node3libltdl]# ./configure --prefix=/home/webserver/libs/ --enable-ltdl-install  && make && make install

 

3.1.5:安装mhash:

[root@node3 ~]# wgethttp://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz

[root@node3 ~]# tarzxf mhash-0.9.9.9.tar.gz

[root@node3 ~]# cdmhash-0.9.9.9

[root@node3mhash-0.9.9.9]# ./configure --prefix=/home/webserver/libs/ && make&& make install

 

[root@node3 ~]#export LDFLAGS="-L/home/webserver/libs/lib -L/usr/lib"

[root@node3 ~]#export CFLAGS="-I/home/webserver/libs/include -I/usr/include"

###这命令的作用是把安装的lib库连接到/usr/lib下,因为php安装时默认只搜索/urs/lib,不设置的话可能会造成后面mcrypt编译的时候找不到mhash库.

 

3.1.6:安装mcrypt:

[root@node3 ~]# exportLD_LIBRARY_PATH=/home/webserver/libs/lib:/home/webserver/libs

##这命令的作用是设置gcc编译环境变量

[root@node3 ~]# wgethttp://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz

[root@node3mcrypt-2.6.8]# ./configure --prefix=/home/webserver/libs/  --with-libmcrypt-prefix=/home/webserver/libs  && make && make install

 

3.2 安装PHP:

[root@node3 ~]# yum-y install curl curl-devel  libxml2libxml2-devel zlib-devel  zlib 

[root@node3php-5.5.14]#./configure --prefix=/home/webserver/php --with-config-file-path=/home/webserver/php/etc--with-mysql=/home/webserver/mysql/--with-mysqli=/home/webserver/mysql/bin/mysql_config --with-iconv-dir--with-freetype-dir=/home/webserver/libs --with-jpeg-dir=/home/webserver/libs/--with-png-dir=/home/webserver/libs --with-zlib --with-libxml-dir=/usr/bin/xml2-config  --enable-xml --enable-bcmath--enable-sysvsem --enable-inline-optimization --with-curl --with-mhash --with-openssl--enable-shmop --enable-mbstring --with-gd --enable-gd-native-ttf --enable-pcntl--enable-sockets --with-xmlrpc --enable-zip--with-pdo-mysql=/home/webserver/mysql/ --with-mcrypt=/home/webserver/libs      --enable-fpm  --disable-rpath     --enable-mbregex    --enable-soap --enable-opcache

[root@node3php-5.5.14]# make && maek install

3.3 创建PHP配置文件,删除系统自带的配置文件,将配置文件做软连接到/etc/ php.ini

[root@node3php-5.5.14]# cp php.ini-production /home/webserver/php/etc/php.ini

[root@node3php-5.5.14]# rm -rf /etc/php.ini

[root@node3php-5.5.14]# ln -s /home/webserver/php/etc/php.ini  /etc/php.ini

3.4 修改PHP配置文件开启短标记,开启opcache

[root@node3php-5.5.14]# vim /home/webserver/php/etc/php.ini

short_open_tag = on (默认为OFF)

display_errors = OFF

[opcache]

zend_extension="opcache.so"

opcache.enable=1

opcache.enable_cli=1

opcache.memory_consumption=128

opcache.optimization_level=1

opcache.interned_strings_buffer=8

opcache.max_accelerated_files=4096

opcache.revalidate_freq=60

opcache.fast_shutdown=1

[root@node3~]# cd /home/webserver/php/etc/

[root@node3etc]# cp php-fpm.conf.default php-fpm.conf

[root@node3etc]# vim php-fpm.conf

[global]

; Pid file

; Note: the defaultprefix is /home/webserver/php/var

; Default Value: none

;pid = run/php-fpm.pid

pid = run/php-fpm.pid   #开启php-fpm  pid文件

四、配置nginx和php

4.1 创建nginx运行用户www

[root@node3 ~]# useradd -s /sbin/nologin www

4.2 修改nginx配置文件 ,

 

user www;

worker_processes 1;

events {

   worker_connections  1024;

}

http {

   include       mime.types;

   default_type application/octet-stream;

   sendfile        on;

   keepalive_timeout  65;

  server {

       listen       80;

       server_name  localhost;

       location / {

           root   html;

           index  index.html index.htm;

        }

       location ~ .*\.(php|php5)?$ {

               fastcgi_pass    127.0.0.1:9000;

               fastcgi_index   index.php;

               include         fastcgi.conf; #将*.php 或者.php5的请求转交给本地php-fpm处理

        }

       error_page   500 502 503 504  /50x.html;

       location = /50x.html {

           root   html;

        }

}

}

4.3 使用nginx –t测试nginx配置文件

[root@node3 ~]# /home/webserver/nginx/sbin/nginx  -t

the configuration file/home/webserver/nginx/conf/nginx.conf syntax is ok

configuration file/home/webserver/nginx/conf/nginx.conf test is successful

 

4.4 启动nginx,启动php

[root@node3 ~]#/home/webserver/nginx/sbin/nginx  

[root@node3 ~]#/home/webserver/php/sbin/php-fpm

 

4.5 下载探针文件到nginx安装目录下的 html目录下。 

bubuko.com,布布扣

4.6  浏览器访问探针文件,查看lnmp安装情况,测试与mysql链接情况

bubuko.com,布布扣

bubuko.com,布布扣

bubuko.com,布布扣


4.7 所遇到的报错:

安装mcrypt时报错:

checking whether mhash >= 0.8.15...no

 

configure: error: "You need at leastlibmhash 0.8.15 to compile this program. http://mhash.sf.net/"

 

原因:

 

mhash编译默认安装路径是 /usr/local/,相关库在 /usr/local/lib 下。而 php 只搜索 /usr/lib/ 这个位置。所以会出现找不到 mhash 相关库的情况。

 

解决方法:

通过软链接的方法把 /usr/local/lib 目录下的 mhash 相关的库文件链接到 /usr/lib/ 目录下。

 

 

重装PHP报错:

configure: error: GD build test failed.Please check the config.log for details.

解决办法:

vim /etc/ld.so.conf  在这个文件里面加入configure所使用的lib路径 

ldconfig

 

 

报错:

checking for known struct flockdefinition... configure: error: Don‘t know how to define struct flock on thissystem, set --enable-opcache=no

解决办法:

ln -s/home/webserver/mysql/lib/libmysqlclient.so /usr/lib

ln -s/home/webserver/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18

vim /etc/ld.so.conf   在这个文件内加入软连接到的 /usr/lib路径

ldconfig


本文出自 “zrer(技术群:1991706)” 博客,请务必保留此出处http://zrer90.blog.51cto.com/8679896/1535543

lnmp环境源码编译安装记录,布布扣,bubuko.com

lnmp环境源码编译安装记录

标签:lnmp源码安装

原文地址:http://zrer90.blog.51cto.com/8679896/1535543

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!