前言

1.操作前提:

  • CentOS Linux release 7.5.1804;
  • sudo用户(需要root权限);

2.需要安装的组件:

  • nginx稳定版:nginx-1.14.0;
  • MariaDB 10.3.10 Stable;
  • PHP 7.2.11 Stable;

3.操作步骤:

  • 添加环境依赖包;
  • 安装libiconv,libmcrypt等;
  • 安装nginx;
  • 安装php;
  • 安装mariadb;

下载安装包

wget http://nginx.org/download/nginx-1.14.0.tar.gz &&  tar xzvf nginx-1.14.0.tar.gz 

wget http://am1.php.net/distributions/php-7.2.11.tar.gz && tar xzvf php-7.2.11.tar.gz

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz &&  tar xzvf libiconv-1.14.tar.gz

wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz && tar xzvf ./libmcrypt-2.5.8.tar.gz

删除不需要的源码包:

rm -rf *.tar.gz

添加环境依赖包

以下依赖包是整个Lnmp搭建过程中所需的基本依赖包,如果在安装过程中出现错误,提示缺少某依赖包,可以自己安装:

#执行下面这条命令,各参数之间以空格分开

sudo yum -y install zlib-devel pcre-devel openssl-devel gcc gcc-c++  ncurses-devel perl perl-devel perl-ExtUtils-Embedlibjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel  libxml2 libxml2-devel curl-devel libxslt libxslt-devel gd gd-devel GeoIP GeoIP-devel

编译nginx

为了使Nginx能够启用http/2,需要通过源码的方式安装nginx,并指定--with-openssl的版本在1.0.2版本以上,这里我将需要版本的依赖安装在/usr/local/src目录:

$ cd /usr/local/src/

# PCRE version 8.40
$ sudo wget https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz && sudo tar xzvf pcre-8.40.tar.gz # zlib version 1.2.11
$ sudo wget https://www.zlib.net/zlib-1.2.11.tar.gz && sudo tar xzvf zlib-1.2.11.tar.gz # OpenSSL version openssl-1.1.0h
$ sudo wget https://www.openssl.org/source/openssl-1.1.0h.tar.gz && sudo tar xzvf openssl-1.1.0h.tar.gz

删除不需要的包

sudo rm -rf *.tar.gz

编译nginx

cd ~/src/nginx-1.14.0
sudo ./configure --prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib64/nginx/modules \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--user=nginx \
--group=nginx \
--build=CentOS \
--builddir=nginx-1.14.0 \
--with-select_module \
--with-poll_module \
--with-threads \
--with-file-aio \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_xslt_module=dynamic \
--with-http_image_filter_module=dynamic \
--with-http_geoip_module=dynamic \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_auth_request_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_degradation_module \
--with-http_slice_module \
--with-http_stub_status_module \
--http-log-path=/var/log/nginx/access.log \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--with-mail=dynamic \
--with-mail_ssl_module \
--with-stream=dynamic \
--with-stream_ssl_module \
--with-stream_realip_module \
--with-stream_geoip_module=dynamic \
--with-stream_ssl_preread_module \
--with-compat \
--with-pcre=/usr/local/src/pcre-8.40 \
--with-pcre-jit \
--with-zlib=/usr/local/src/zlib-1.2.11 \
--with-openssl=/usr/local/src/openssl-1.1.0h \
--with-openssl-opt=no-nextprotoneg \
--with-debug

上面--prefix=/etc/nginx为安装目录。

sudo make && sudo make install

创建软链

sudo ln -s /usr/lib64/nginx/modules /etc/nginx/modules

这样就可以在nginx的配置文件中像这样加载动态模块:load_module modules/ngx_foo_module.so;。

查看编译信息

sudo nginx -V

修改/etc/nginx/nginx.conf

去掉 user nobody;一行的注释。

检查配置是否存在潜在错误

## 执行检查可能会报错
sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: [emerg] mkdir() "/var/cache/nginx/client_temp" failed (2: No such file or directory)
nginx: configuration file /etc/nginx/nginx.conf test failed ## 如果报上面的错误,则执行下面的代码
sudo mkdir -p /var/cache/nginx && sudo nginx -t

创建nginx系统服务单元

编辑文件:

sudo vi /usr/lib/systemd/system/nginx.service

将下面的内容复制进去

[Unit]
Description=nginx - high performance web server
Documentation=https://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target [Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID [Install]
WantedBy=multi-user.target

启动nginx并设置开机启动

sudo systemctl start nginx.service && sudo systemctl enable nginx.service

至此,nginx的安装到此结束,nginx的源码安装参考出处:centos7通过编译源码的方式安装nginx

接下来进行源码编译安装Php的操作。

编译安装php

php需要libiconv、libmcrypt等依赖,下面进行编译:【阅读原文

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

  1. 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 ...

  2. 用源码搭建LNMP环境+部署WordPress

    首先要做的是就是关闭Centos7.4的防火墙及selinux #systemctl stop firewalld #systemctl disable firewalld #sed -ri 's/^ ...

  3. 源码搭建LNMP

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

  4. Centos 7 下yum搭建lnmp环境(yum安装方式)

    我们都知道linux下安装软件主要有三种方式: 1.源码编译安装,即下载软件源代码,利用gcc g++ make 等编译工具进行编译安装: 此方式的优点:可以指定软件版本,可选择性好:编译时可以手动指 ...

  5. CentOS 6.5 下源码搭建LAMP环境

    参考网站: http://wenku.baidu.com/link?url=Cvkqss2E9mnxXOZigMWPaCfqwsBxnm0sZ4aKE2oLAgQ888XxeC0DWOChxVqiHz ...

  6. 源码搭建lnmp平台

    lnmp平台是指利用linux操作系统,nginx服务器,mysql数据库和php语言搭建高性能web服务器,负载均衡器和邮件代理服务器. 原理图:‘

  7. CentOS 下源码安装LAMP环境

    一.简介 什么是LAMP    LAMP是一种Web网络应用和开发环境,是Linux, Apache, MySQL, Php/Perl的缩写,每一个字母代表了一个组件,每个组件就其本身而言都是在它所代 ...

  8. centos上源码安装clang 3.8

    之前想在centos系统上安装clang 3.6版本,由于yum上版本太低,想通过源码编译安装.按照网上说的源码安装步骤,下好llvm.clang.clang-tools-extra和compiler ...

  9. 终于完成了 源码 编译lnmp环境

    经过了大概一个星期的努力,终于按照海生的编译流程将lnmp环境源码安装出来了 nginx 和php 主要参考 http://hessian.cn/p/1273.html mysql 主要参考 http ...

随机推荐

  1. Html和Css学习笔记-css进阶-盒模型

    我的邮箱地址:zytrenren@163.com欢迎大家交流学习纠错! 此篇博客是我的复习笔记,html和css学的时间太久了,忘得差不多了,最近要使用一下,所以重新打开html的书略读,后记录了标签 ...

  2. dsu on tree入门

    先瞎扯几句 说起来我跟这个算法好像还有很深的渊源呢qwq.当时在学业水平考试的考场上,题目都做完了不会做,于是开始xjb出题.突然我想到这么一个题 看起来好像很可做的样子,然而直到考试完我都只想出来一 ...

  3. 前端加密传输 crypto-js AES 加密和解密

    配置: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8 ...

  4. MongoDB的存储结构及对空间使用率的影响

    MongoDB的存储结构及对空间使用率的影响 使用MongoDB一段时间的同学肯定会发现,MongoDB往往会占用比实际数据大小多不少空间的问题.如果利用db.stats()命令去查看,会发现Mong ...

  5. Android .9.png 的介绍

    概述 .9.PNG是安卓开发里面的一种特殊的图片,这种格式的图片通过ADT自带的编辑工具生成,使用九宫格切分的方法.点九图是一种可拉伸的位图,android会自动调整它的大小,来使图像在充当背景时可以 ...

  6. MongoDB 如何实现备份压缩

    背景及原理 数据库的备份是灾难恢复的最后一道屏障,不管什么类型的数据库都需要设置数据库备份,MongoDB也不例外.MongoDB 3.0 后 ,数据库可以采用Wiredtiger存储引擎后(3.2 ...

  7. 爬虫基础--IO多路复用单线程异步非阻塞

    最近一直的学习爬虫  ,进行基础的学习 性能相关 参考 https://www.cnblogs.com/wupeiqi/p/6229292.html # 目标:单线程实现并发HTTP请求 # # so ...

  8. mysql安装和配置(windowns||centos)

    windows10版本安装 1.获取mysql压缩包 https://dev.mysql.com/downloads/mysql/ 2.解压并配置文件my.ini .解压的文件路径 D:\Progra ...

  9. PostgreSql 查询表结构和说明

    select (select relname from pg_class where oid=a.attrelid) relname , () as comment from pg_class whe ...

  10. RHEL6 删除软RAID

    停止使用RAID: 1.umount raid组上的硬盘的所用的分区 若使用raid组创建vg,需要删除或去激活VG 2.停止raid服务 mdadm -S /dev/md0 3.清除MBR # md ...