一、安装前的准备工作

1、yum update    #更新系统

  1.1)vi /etc/selinux/config  #  禁止SELINUX,设置SELINUX=disabled

2、yum install gcc gcc-c++ autoconf automake cmake bison m4 libxml2 systemd-devel libxml2-devel libcurl-devel libjpeg-devel libpng-devel libicu-devel    #安装php、MySQL、Nngix所依赖的包

3、下载以下包   #我把所有源文件都下载在root目录,读者可自行修改源文件存放目录

3.1 libmcrypt-2.5.8.tar.gz

3.2 mcrypt-2.6.8.tar.gz

3.3 mhash-0.9.9.9.tar.gz

3.4 zlib-1.2.8.tar.gz

解压并安装如:

#tar -zvxf  libmcrypt-2.5.8.tar.gz

#cd libmcrypt-2.5.8

#./configure

#make && make insatll

4、在安装软件时如果提示有什么依赖包没有安装的可以再执行yum install * -y (*表示相关包)


二、编译安装Nginx

1、去官网http://nginx.org/en/download.html下载最nginx-1.10.1.tar.gz的稳定版本

2、编译步骤如下

  1、通过winSCP上传nginx-1.10.1.tar.gz到/root目录下
    1.1 groupadd -r nginx                                 #新建nginx组
    1.2 useradd -r -g nginx -s /bin/false nginx    #新建无登录权限的nginx用户
    1.3 id nginx                                               #查看nginx组及用户

  2、tar -zvxf nginx-1.10.1.tar.gz

  3、cd nginx-1.10.1

  4、可通过./configure --help查看编译配置参数,也可参考http://nginx.org/en/docs/configure.html,下列参数要写在一行中
    ./configure
    --prefix=/usr/local/nginx
    --modules-path=/usr/local/nginx/modules
    --with-http_ssl_module
    --pid-path=/usr/local/nginx/nginx.pid
    --user=nginx
    --group=nginx

  5、make && make install   #编译并安装

  6、启动nginx
    6.1 cd /usr/local/nginx
    6.2 sbin/nginx     #启动,可使用sbin/nginx -?查看nginx相关操作命令

  7、在/usr/lib/systemd/system目录下新建nginx.service文件,这样就可以通过systemctl stop|start|reload nginx.service来操作nginx,也可参考https://www.nginx.com/resources/wiki/start/topics/examples/systemd/,内容如下:
    [Unit]
    Description=The NGINX HTTP and reverse proxy server
    After=syslog.target network.target remote-fs.target nss-lookup.target

    [Service]
    Type=forking
    PIDFile=/usr/local/nginx/nginx.pid
    ExecStartPre=/usr/local/nginx/sbin/nginx -t
    ExecStart=/usr/local/nginx/sbin/nginx
    ExecReload=/usr/local/nginx/sbin/nginx -s reload
    ExecStop=/usr/local/nginx/sbin/nginx -s stop
    PrivateTmp=true

    [Install]
    WantedBy=multi-user.target


三、编译安装MySQL

1、去官网http://dev.mysql.com/Downloads/MySQL-5.7/mysql-boost-5.7.14.tar.gz下载带boost的5.7.14版本

2、编译步骤如下

  1、用winSCP上传mysql-boost-5.7.14.tar.gz到/root目录下

  2、groupadd mysql

  3、useradd -r -g mysql -s /bin/false mysql

  4、用cmake编译mysql, 相关参数可以参考https://dev.mysql.com/doc/refman/5.7/en/source-configuration-options.html,下列参数要写在一行
    cmake
    -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
    -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock
    -DSYSCONFDIR=/usr/local/mysql/etc
    -DSYSTEMD_PID_DIR=/usr/local/mysql
    -DDEFAULT_CHARSET=utf8
    -DDEFAULT_COLLATION=utf8_general_ci
    -DWITH_INNOBASE_STORAGE_ENGINE=1
    -DWITH_ARCHIVE_STORAGE_ENGINE=1
    -DWITH_BLACKHOLE_STORAGE_ENGINE=1
    -DWITH_PERFSCHEMA_STORAGE_ENGINE=1
    -DMYSQL_DATADIR=/usr/local/mysql/data
    -DWITH_BOOST=boost
    -DWITH_SYSTEMD=1

  5、make && make install

  6、配置mysql并初始化数据库
    6.1 cd /usr/local/mysql     #进入编译目录
    6.2 chown -R mysql .       #修改目录所有者
    6.3 chgrp -R mysql .        #修改目录组
    6.4 cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld               #配置mysqld服务
    6.5 cp /usr/local/mysql/support-files/my-default.cnf /usr/local/mysql/my.cnf     #配置my.cnf
      6.5.1 复制以下内容到my.cnf文件中的[mysqld]下
           user = mysql
           basedir = /usr/local/mysql
           datadir = /usr/local/mysql/data
           port = 3306
           server_id = /usr/local/mysql/mysqld.pid
           socket = /usr/local/mysql/mysql.sock
    6.5 chkconfig mysqld on     #设置mysqld开机自启
    6.6 bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data      #初始化数据库
    6.7 bin/mysqld --user=mysql &    #启动mysql, 如果报Please read "Security" section of the manual to find out how to run mysqld as root!,就在my.cnf中加入user=root, 表示以root用户启动

  7、修改root用户登录密码并允许root用户远程登录
    7.1 mysql -u root --skip-password
    7.2 ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
    7.3 允许root用户远程登录
    7.3.1 use mysql;
    7.3.2 update user set host='%' where user='root' and host='localhost';      #允许
        (update user set host='localhost' where user='root';    #禁用)
    7.3.3 flush privileges;
    7.3.4 service mysqld restart

  8、解决service mysqld start|stop报MySQL server PID file could not be found!或者Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe), 其实可通过阅读此文件解决相关错误
    8.1 chmod 777 /usr/local/mysql         #因我设置mysqld.pid文件保存在/usr/local/mysql目录,所以保证其有可写权限
    8.2 通过winSCP修改/etc/init.d/mysqld文件
    8.2.1 basedir=/usr/local/mysql       #手动指定
    8.2.2 datadir=/usr/local/mysql/data     #手动指定
    8.2.3 mysqld_pid_file_path=/usr/local/mysql/mysqld.pid     #手动指定
    8.2.4 把此文件中所有未注释的含有mysqld_safe的字符替换成mysqld


四、编译安装php

1、去官网http://php.net/downloads.php下载php7.0.10版本

2、编译步骤如下

  1、用winSCP上传php-7.0.10.tar.gz到/root目录下

  2、tar -zvxf php-7.0.10.tar.gz    #解压

  3、配置编译php参数, 可使用./configure --help命令查看所有编译配置项目, 下列参数要写在一行中
    ./configure
    --prefix=/usr/local/php
    --exec-prefix=/usr/local/php
    --datadir=/usr/local/php
    --with-config-file-path=/usr/local/php/etc
    --with-mysqli=mysqlnd
    --with-pdo-mysql=mysqlnd
    --with-fpm-user=nginx
    --with-fpm-group=nginx
    --with-gd
    --with-iconv
    --enable-mbstring
    --enable-fpm
    --enable-mysqlnd

  4、make && make install    #编译并安装

  5、cd /usr/local/php    #进入编译目录

  6、修改相关配置文件
    6.1 cp /usr/local/php/etc/php.ini.default /usr/local/php/etc/php.ini      #php.ini中相关配置依项目需要自行修改,配置nginx支持php参考http://php.net/manual/zh/install.unix.nginx.php
    6.2 cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf     #去掉[global]项下pid前的;
    6.3 cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf     #大致在23、24行修改user和group如:user = nginx,group = nginx

  7、chmod 777 /usr/local/php/var/run     #默认PID文件是写在/usr/local/php/var/run这个目录中,所以修改目录权限

  8、sbin/php-fpm     #启动php, 可通过sbin/php-fpm -h 查看相关操作命令列表

  9、在/usr/lib/systemd/system目录下新建php-fpm.service文件,这样就可以通过systemctl stop|start|reload php-fpm.service来操作php-fpm,内容如下:
    [Unit]
    Description=The PHP FastCGI Process Manager
    After=syslog.target network.target
    Before=nginx.service

    [Service]
    Type=forking
    PIDFile=/usr/local/php/var/run/php-fpm.pid
    ExecStart=/usr/local/php/sbin/php-fpm
    ExecStop=/bin/kill -QUIT `cat /usr/local/php/var/run/php-fpm.pid`
    ExecReload=/bin/kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`
    PrivateTmp=true

    [Install]
    WantedBy=multi-user.target

  10、安装php相关扩展, 下面以编译mysqli为例
    10.1 cd /root/php-7.0.10/ext/mysqli #首先必须进入php源文件解压后所在目录,不然在执行phpize时会报Cannot find config.m4
    10.2 /usr/local/php/bin/phpize #执行phpize,/usr/local/php/bin这个目录是编译后php所在目录
    10.3 ./configure --with-php-config=/usr/local/php/bin/php-config
    10.4 make && make install #执行完这一步后,会在/usr/local/php/lib/php/extensions/no-debug-non-zts-20151012目录下生成mysqli.so文件
    10.5 vi /usr/local/php/etc/php.ini #在php.ini[Dynamic Extensions]下新增extension=mysqli.so
    10.6 重启Nginx/Apache、重启php-fpm


五、安装redis及phpredis扩展

1、用winSCP上传redis-3.0.0.tar.gz到/root目录下

2、tar -zvxf redis-3.0.0.tar.gz -C /usr/local     #解压到/usr/local目录下

3、yum install tcl -y     #redis-test依赖此包

4、cd /usr/local/redis-3.0.0

5、chmod 777 .    #当前目录可写,我把redis.pid文件指定到了/usr/local/redis-3.0.0下

6、make && make install

7、vi /usr/local/redis-3.0.0/redis.conf     #修改redis配置文件
  7.1 daemonize yes
  7.2 pidfile /usr/local/redis/redis.pid

8、src/redis-server & #启动redis
   src/redis-cli shutdown #关闭redis
   src/redis-server --help #查看相关帮助命令

9、在/usr/lib/systemd/system目录下新建redis.service文件,这样就可以通过systemctl stop|start redis.service来操作redis,内容如下:
  [Unit]
  Description=The Redis 3.0.0 Service
  After=syslog.target

  [Service]
  Type=forking
  PIDFile=/usr/local/redis/redis.pid
  ExecStartPre=/usr/local/redis/src/redis-server /usr/local/redis/redis.conf
  ExecStart=/usr/local/redis/src/redis-server /usr/local/redis/redis.conf
  ExecStop=/usr/local/redis/src/redis-cli shutdown
  PrivateTmp=true

  [Install]
  WantedBy=multi-user.target

10、安装phpredis扩展,下载地址:https://github.com/phpredis/phpredis/releases
  10.1 用winSCP上传phpredis-3.0.0.tar.gz到/root目录下
  10.2 tar -zvxf phpredis-3.0.0.tar.gz -C /usr/local #解压到/usr/local目录下
  10.3 cd /usr/local/phpredis-3.0.0
  10.4 /usr/local/php/bin/phpize
  10.5 ./configure --with-php-config=/usr/local/php/bin/php-config
  10.6 make && make install
  10.7 在php.ini文件中添加extension=redis.so
  10.8 重启Nginx/Apache、重启php-fpm


六、至此在我的VirturBox中CentOS7.2下成功搭建了LNMP环境

CentOS 7.2mini版本下编译安装php7.0.10+MySQL5.7.14+Nginx1.10.1的更多相关文章

  1. CentOS 7.2mini版本下编译安装php7.0.10+MySQL5.7.14+Nginx1.10

    一.安装前的准备工作 1.yum update    #更新系统 2.yum install gcc gcc-c++ autoconf automake cmake bison m4 libxml2  ...

  2. centos7下编译安装php-7.0.15(PHP-FPM)

    centos7下编译安装php-7.0.15(PHP-FPM) 一.下载php7源码包 http://php.net/downloads.php 如:php-7.0.15.tar.gz 二.安装所需依 ...

  3. CentOS 7.2下编译安装PHP7.0.10+MySQL5.7.14+Nginx1.10.1

    一.安装前的准备工作 1.yum update    #更新系统 2.yum install gcc gcc-c++ autoconf automake cmake bison m4 libxml2  ...

  4. centos7.5环境下编译安装php7.0.30并安装redis和mongo扩展

    .安装php7..30的脚本 # vim install_php.sh #!/bin/bash # 安装基本依赖 yum install -y gcc gcc-c++ htop telnet ioto ...

  5. Linux Centos7.2 编译安装PHP7.0.2

    操作环境: 1.系统:Centos7.2 2.服务:Nginx 1.下载PHP7.0.2的安装包解压,编译,安装: $ cd /usr/src/ $ wget http://cn2.php.net/d ...

  6. CentOS7下编译安装redis-5.0.9

    CentOS7下编译安装redis-5.0.9 本文地址http://yangjianyong.cn/?p=171转载无需经过作者本人授权 下载redis #code start wget https ...

  7. 【安装PHP】如何在openSUSE42.1下编译安装PHP7

    首先推荐一篇文章PHP 7 Release Date Arrived: Will Developers Adopt PHP 7? - PHP Classes blog. 里面说到是否会去使用PHP7, ...

  8. centos7.6下编译安装zabbix4.0.10长期支持版

    一.安装数据库,这里使用的是percona-server5..24版本 配置如下 [root@zabbix4_clone:~]# cat /etc/my.cnf # Example MySQL con ...

  9. centos6.5下编译安装mariadb-10.0.20

    源码编译安装mariadb-10.0.20.tar.gz 一.安装cmake编译工具 跨平台编译器 # yum install -y gcc* # yum install -y cmake 解决依赖关 ...

随机推荐

  1. 响应式Web设计-一种优雅的掌上展现

    入门 flat - style (too many ad.) writeshell

  2. jedis 连接redis

    一,  单机版连接 @Test public void testJedis() { //1. 创建jedis 对象 Jedis jedis = new Jedis("192.168.88.1 ...

  3. LINQ入门教程之各种标准查询操作符(二)

    续上篇LINQ入门教程之各种标准查询操作符(一) LINQ入门教程之各种标准查询操作符(二) 7.  聚合操作符 8.  集合操作符 9.  生成操作符 #region 生成操作符 即从现有序列的值中 ...

  4. SpringSecurity自定义用户登录

    根据上一节的配置,默认在服务开启的时候会被要求自动的进行表单登陆.用到的用户名只能是一个固定的用户名user,它的密码是每次启动的时候服务器自动生成的.最常见的场景是我们的用户是从数据库中获取的. 1 ...

  5. 【es6】变量解构赋值

    1.数组解构赋值 let [a,b,c]=[1,2,3];//数组解构赋值,注意:左右两边格式需一致 let [a,b]=[1,2,3];//不完全解构,取位置靠前的值 let [a=1,b]=[un ...

  6. Types的Type访问模式

    在Types类中定义的访问都类如下: 1.MapVisitor类 2.SimpleVisitor 3.UnaryVisitor 4.TypeRelation

  7. ZOJ 2971 Give Me the Number

    Give Me the Number Numbers in English are written down in the following way (only numbers less than  ...

  8. docker 常见操作

    docker rm $(docker ps -a -q --filter status=exited)   // 删除不在运行的 镜像

  9. Postgresql 连接更新

    update dbo.m_role_fun a set role_code = b.rsc from (select rsc, fun_code from dbo.m_fun) b where a.f ...

  10. SQL Serever学习15——进阶

    特别说明:在sqlserver2014中,不区分大小写,也就是说,SQL是大小写不敏感的 数据库模型3类: 层次模型 网状模型 关系模型 关系型数据库语言3种: DDL数据定义语言 CREATE(创建 ...