以前LNMP环境是由运维搭建,自己搭建的时候查找了很多资料,这是我见过的最棒的资料,将过程记录下来分享给大家

  为啥使用LNMP而不是LAMP下面来谈谈Nginx的技能

   Nginx是一个小巧而高效的Linux下的Web服务器软件,是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,已经在一些俄罗斯的大型网站上运行多年,目前很多国内外的门户网站、行业网站也都在是使用Nginx,相当的稳定。Nginx相当的稳定、功能丰富、安装配置简单、低系统资源……

  Linux采用的是centOs,软件包统一放在/usr/local/src目录下,至于为啥放在这儿是一种约定俗成的东西,如果centOs源比较老,可以换成163的源。

  更换到163源 cd/etc/yum.repos.d/


  wget http://mirrors.163.com/.help/CentOS6-Base-163.repo

  mv CentOS-Base.repo CentOS-Base.repo.bak

  mv CentOS6-Base-163.repo CentOS-Base.repo


  安装一下工具 更新yum


  yum clean all

  yum makecache

  yum update

  yum -y install vim

  更多的yum命令使用 man yum

  采用yum包安装一些依赖关系的包

  yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers make cmake libtool* git tree


  下载LNMP需要的编译应用和包


  下载的文件都放在/usr/local/src目录下,使用wget下载,如果没有wget使用yum包安装 yum -y install wget,下面罗列软件包地址,可以依照地址修改文件名下载最新版本。exp:如果想下载mhash最新包,在浏览器搜索http://jaist.dl.sourceforge.net/project/mhash/mhash/

  

找到相应的软件包,替换名字就可以了。

  切换到/usr/local/src目录 cd /usr/local/src wget相应的软件包
所需要的软件包:

mhash-0.9.9.9
http://jaist.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz

mcrypt-2.6.8
http://jaist.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz

ncurses
http://down1.chinaunix.net/distfiles/ncurses-5.9.tar.gz

pcre-8.31.tar.bz2
http://exim.mirror.fr/pcre/pcre-8.31.tar.bz2

zlib-1.2.8.tar.gz
http://iweb.dl.sourceforge.net/project/libpng/zlib/1.2.8/zlib-1.2.8.tar.gz

freetype-2.3.5.tar.bz2
http://down1.chinaunix.net/distfiles/freetype-2.3.5.tar.bz2

openssl-1.0.1c.tar.gz
http://down1.chinaunix.net/distfiles/openssl-1.0.1c.tar.gz

php-5.5.29.tar.bz2
http://cn2.php.net/distributions/php-5.5.29.tar.bz2
安装libiconv

 cd /usr/local/src

  1. wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
  2. tar zxvf libiconv-1.14.tar.gz
  3. cd libiconv-1.14/
  4. ./configure --prefix=/usr/local
  5. make && make install

在我make && make install的时候出现错误了error: ‘gets’ undeclared here (not in a function)。如果你不要遇到遇到,如果遇到请做如下修改:(国外的这文章记录了http://www.itkb.ro/kb/linux/patch-libiconv-pentru-glibc-216

cd libiconv-1.14/srclib

编辑stdio.in.h文件,搜索这句话

  1. _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");

把这句注释()添加换成如下几句

  1. #if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16)
  2. _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
  3. #endif

然后重新编译安装

  1. cd ..
  2. make && make install

下载并安装libmcrypt

  1. cd /usr/local/src
  2. wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
  3. tar -zxvf libmcrypt-2.5.7.tar.gz
  4. cd libmcrypt-2.5.7
  5. ./configure
  6. make
  7. make install
  8. cd libltdl/
  9. ./configure --enable-ltdl-install
  10. make
  11. make install

安装mbash

  1. cd /usr/local/src
  2. tar -jxvf mhash-0.9.9.9.tar.bz2
  3. cd mhash-0.9.9.9
  4. ./configure
  5. make
  6. make install

下载并安装mcript

  1. cd /usr/local/src
  2. tar zxvf mcrypt-2.6.8.tar.gz
  3. cd mcrypt-2.6.8/

注意一下这步运行下,不然下面可能报错

  1. export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
  1. ./configure
  2. make
  3. make install
  4. ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
  5. ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
  6. ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
  7. ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
  8. ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
  9. ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
  10. ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
  11. ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
  12. ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
  13. ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config

安装mysql(mysql5.6.13)

先检查一下mysql是否已经存在了,如果存在就删除mysql

rpm -qa | grep mysql

我的显示如下(如果没有任何显示就表示没有mysql呢)

mysql-libs-5.1.73-3.el6_5.i686

如果存在就卸载mysql

rpm -e mysql-libs-5.1.73-3.el6_5.i686 --nodeps

此时再运行

rpm -qa | grep mysql

发现没有任何显示

添加一个mysql用户(nologin用户并且没有家目录)

useradd -M -s /sbin/nologin mysql

初次编译mysql的时候时间比较长,请耐心等待吧

  1. cd /usr/local/src
  2. tar -zxf mysql-5.6.13.tar.gz
  3. cd mysql-5.6.13

注意下面是cmake .注意点

  1. cmake .
  2. make && make install

复制mysql配置文件

  1. cp support-files/my-default.cnf /etc/my.cnf

创建系统数据库表

  1. cd /usr/local/mysql
  2. scripts/mysql_install_db --user=mysql

更改权限

  1. cd /usr/local/mysql
  2. chown -R root:mysql .
  3. chown -R mysql:mysql data

把mysql添加到系统服务中去

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

启动mysql启动的时候,一直不动的话按下enter.,就行了

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

查看mysql是否启动

netstat -tunpl | grep 3306

或者pstree,看到有mysqld进程也行

修改mysql密码

/usr/local/mysql/bin/mysqladmin -u root password "xxxxx"

进入mysql中删除空密码和匿名用户

  1. /usr/local/mysql/bin/mysql -u root -p
  2. select host,user,password from mysql.user;
  3. delete from mysql.user where password="" or user="";
  4. flush privileges;

也可以在mysql修改用户密码(只是说明一下)

set password form 'root'@'localhost' = password('123456');

关闭mysql的时候可以使用

/usr/local/mysql/bin/mysqladmin -u root -p shutdown

把mysql添加到开机启动

vim /etc/rc.local

在最后再加一行

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

最后做一个软链接方便使用mysql

ln -s /usr/local/mysql/bin/mysql /usr/bin/

nginx安装

nginx安装前编译安装pcre zlib openssl[openssl安装用./config]

pcre安装

  1. cd /usr/local/src
  2. tar -jxf pcre-8.31.tar.bz2
  3. cd pcre-8.31
  4. ./configure
  5. make && make install

zlib安装

  1. cd /usr/local/src
  2. tar -zxf zlib-1.2.8.tar.gz
  3. cd zlib-1.2.8
  4. ./configure
  5. make && make install

openssl安装

  1. cd /usr/local/src
  2. tar -zxf openssl-1.0.1c.tar.gz
  3. cd openssl-1.0.1c
  4. ./config
  5. make && make install

安装Nginx

  1. cd /usr/local/src
  2. useradd -M -s /sbin/nologin nginx

解压Nginx

  1. tar -zxf nginx-2.0.1.tar.gz
  2. cd tengine-2.0.1

注意的是with-pcre这些都指向/usr/local/src这种目录 (with-pcre指向安装目录,如果在安装的时候 --prefx=''更改了新的安装目录,在编译的时候要指向相应的安装目录)

  1. ./configure --with-pcre=/usr/local/src/pcre-8.31 --with-http_ssl_module --with-zlib=/usr/local/src/zlib-1.2.8 --with-openssl=/usr/local/src/openssl-1.0.1c

make && make install

做软链接方便nginx启动

ln -s /usr/local/nginx/sbin/nginx /usr/bin/

修改nginx配置文件

vim /usr/local/nginx/conf/nginx.conf
把#user nobody 改成 user nginx;

测试一下nginx配置文件

  1. nginx -t

启动nginx

  1. nginx

说一下nginx启动的一些事情

一般来说在nginx的配置文件修改后进行如下操作,nginx -t检测一下配置文件是否正确,如果正确的话

再使用nginx -s reload 使nginx平滑启动

把nginx添加到开机启动

vim /etc/rc.local

在最后新加一行

/usr/local/nginx/sbin/nginx

查看nginx是否启动

netstat -tunpl | grep 80
pstree 看下有没有nginx就行了

安装php

  1. cd /usr/local/src
  2. useradd -M -s /sbin/nologin php
  3. tar -jxf php-5.5.12.tar.bz2
  4. cd php-5.5.12
  1. ./configure --enable-opcache --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring=all --with-pdo-mysql --enable-sockets --enable-mbstring --enable-fpm --with-curl --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --enable-xml --with-gd --with-mcrypt --with-libxml-dir=/usr --enable-xml --with-openssl --with-iconv=/usr/local/iconv
  1. make ZEND_EXTRA_LIBS='-liconv'
  2. make install
  1. cp php.ini-development /usr/local/php/etc/php.ini

配置php-fpm

  1. cd /usr/local/php/etc
  2. cp php-fpm.conf.default php-fpm.conf
  3. vim php-fpm.conf


`user = nobody
group = nobody`
改为
`user = php
group = php`

启动php-fpm

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

把php-fpm添加到开机启动

vim /etc/rc.local

最后一行加上

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

修改nginx配置文件使之支持php

  1. vim /usr/local/nginx/conf/nginx.conf
  2. #location ~ \.php$ {
  3. # root html;
  4. # fastcgi_pass 127.0.0.1:9000;
  5. # fastcgi_index index.php;
  6. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  7. # include fastcgi_params;
  8. #}

修改为

  1. location ~ \.php$ {
  2. fastcgi_pass 127.0.0.1:9000;
  3. fastcgi_index index.php;
  4. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  5. include fastcgi_params;
  6. }

也顺便把gzip给开启下吧

gzip on前面的#去掉

修改完配置之后
nginx -s reload

ok,现在来测试一下环境

  1. cd /usr/local/nginx
  2. cd html
  3. vim test.php

写上

  1. <?php
  2. phpinfo();

然后访问一下localhost/test.php,正常的话,就一切正常了

如果出问题的话,请看nginx有没有启动,php-fpm有没有启动

注明几个问题如果修改php配置文件的时候,需要重启php-fpm就可以了

先关闭php-fpm

pkill php-fpm

然后运行

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

就可以了可以看到php-fpm就启动了pstree可以看到这个进程

pstree

为了更方便的使用php和php-fpm,我做了两个链链接

ln -s /usr/local/php/sbin/php-fpm /usr/bin/
ln -s /usr/local/php/bin/php /usr/bin/

nmp安装就彻底完成了,有什么问题可以联系我QQ1017109588 [这里没没讲到如何优化一些配置的问题,以后可以会写文章分析]

在些也特别说明一下nginx如何支持path_info这种形式。配置文件中可以这样写。当然可能对你不需要

  1. location ~ ^(.+\.php)(.*)$ {
  2. fastcgi_pass 127.0.0.1:9000;
  3. fastcgi_index index.php;
  4. fastcgi_split_path_info ^(.+\.php)(.*)$;
  5. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  6. fastcgi_param PATH_INFO $fastcgi_path_info;
  7. fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
  8. include fastcgi_params;
  9. }

LNMP环境搭建完成 你还可以装一些扩展 例如memcache redisd等

总结

  1. 总结:编译安装的过程中 操作系统环境不同 软件包依赖 可能会出现一些报错

  2. 遇到报错不要慌张 可以去Google一下 大部分的问题都可以解决

喝水不忘挖井人,感谢原文作者分享,原文请链接

https://wujunze.com/lnmp_compile_install.jsp转载请保留原文链接

参考

Nginx官方文档
MySQL官方文档
PHP官方文档


  

LNMP环境源码搭建的更多相关文章

  1. LNMP架构源码搭建(centos7)

    第一步:安装nginx 1.上传或下载nginx,并解压 yum -y install lrzsz rz .tar.gz 2.搭建nginx安装环境 yum -y install gcc-c++ zl ...

  2. Lnmp环境源码包编辑安装

    最近做了一个小工具可以方便的部署LNMP环境,有兴趣的同学可以尝试下: 这是一个集成的shell脚本,脚本将会自动安装好LNMP环境相关软件: 使用步骤 1.下载脚本源码到本地 git clone h ...

  3. centos下配置LNMP环境(源码安装)

    准备工作,安装依赖库 yum -y install gcc automake autoconf libtool make gcc-c++ glibc libxslt-devel libjpeg lib ...

  4. CentOS 7 源码搭建LNMP环境

    搭建 LNMP 环境 源码包版本 :  CentOS Linux  7 nginx-1.15.1.tar.gz  mysql-boost-5.7.21.tar.gz  php-7.2.7.tar.gz ...

  5. 源码搭建LNMP

      源码安装LNMP 作者:尹正杰   版权声明:原创作品,谢绝转载!否则将追究法律责任.       欢迎加入:高级运维工程师之路 598432640 前言:非常简单的一个平台LNMP,在生产实际环 ...

  6. ARL(资产侦察灯塔系统)-源码搭建

    freebuf能力中心开源了一套资产扫描系统(https://github.com/TophantTechnology/ARL),提供docker版,但并无源码搭建的文档(无完整文档).于是在星光哥及 ...

  7. LNMP架构——源码编译安装

    LNMP架构--源码编译安装 1.编译安装nginx服务 2.编译安装mysql服务 3.编译安装php解析环境 1.编译安装nginx服务: systemctl stop firewalld sys ...

  8. centos6.5环境源码编译安装mysql5.6.34

    centos6.5环境源码编译安装mysql5.6.34 源码下载地址http://dev.mysql.com/downloads/mysql/5.6.html#downloads 选择Generic ...

  9. 利用shell脚本去备份幸运28源码搭建下载所指定的数据库

    #! /bin/bash幸运28源码搭建下载Q[115288oo99]logintool=/home/yx/server/mysql/mysql/bin/mysqldumptool=/home/yx/ ...

随机推荐

  1. 介绍下Python的两个标准库 os 和 sys

    import sysprint(sys.path) #python 2 中报错 ....,打印的是绝对路径(***\\python\\lib\\site-packages# 第三方库,后退一级为标准库 ...

  2. Docker 入门实践

    欢迎大家前往腾讯云技术社区,获取更多腾讯海量技术实践干货哦~ 作者:张戈 导语 本文从新手视角记录了一个实际的Dokcer应用场景从创建.上传直到部署的详细过程,并简单的介绍了腾讯云容器服务的使用方法 ...

  3. spring事务失效情况分析

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt113 <!--[if !supportLists]-->一.&l ...

  4. 机器学习实战之 第10章 K-Means(K-均值)聚类算法

    第 10 章 K-Means(K-均值)聚类算法 K-Means 算法 聚类是一种无监督的学习, 它将相似的对象归到一个簇中, 将不相似对象归到不同簇中.相似这一概念取决于所选择的相似度计算方法.K- ...

  5. 图片懒加载Demo

    相关知识: [js获取元素位置+元素大小]全面总结

  6. js 实现 input type="file" 文件上传示例代码

    在开发中,文件上传必不可少但是它长得又丑.浏览的字样不能换,一般会让其隐藏点其他的标签(图片等)来时实现选择文件上传功能 在开发中,文件上传必不可少,<input type="file ...

  7. 团队作业4——第一次项目冲刺(Alpha版本) 1

    一.Daily Scrum Meeting照片 二.燃尽图 三.项目进展 1.完页面的设计 采用gui页面,现在也是最初的页面设计 2.完成接口的定义 与组员共同定义了接口 四.困难与问题 此次主要利 ...

  8. 201521123065 《Java程序设计》第3周学习总结

    1. 本周学习总结 2. 书面作业 Q1:代码阅读 public class Test1 { private int i = 1;//这行不能修改 private static int j = 2; ...

  9. 201521123086《JAVA程序设计》第一周学习总结

    本周学习总结 (1)初步了解java程序的运行环境,通过命令行语句编译简单的java程序 (2)使用notepad编写,cmd下进入文件夹编译程序 (3)学习使用各种快捷键补全代码 (4)能够区别jd ...

  10. How To:禁用ubuntu全局菜单(global menu)的方法

    刚从windows转过来的新手可用会觉得ubuntu unity下的全局菜单(global menu)用起来很不方便.下边是介绍去除全局菜单的方法 1.打开终端(可以去dash主页里面搜,也可以直接按 ...