Heim  >  Artikel  >  php教程  >  CentOS 7.2mini版本下编译安装php7.0.10+MySQL5.7.14+Nginx1.10.1

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

WBOY
WBOYOriginal
2016-09-02 08:42:561919Durchsuche

一、安装前的准备工作

1、yum update    #更新系统

2、yum install gcc gcc-c++ autoconf automake cmake bison m4 libxml2 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

 


 

五、安装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扩展
  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
  10.9 重启php-fpm

 


 

 

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

 

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn