zoukankan      html  css  js  c++  java
  • linux-------lnmp安装

    一 环境准备

     

    1.系统环境

    [root@web02 ~]# cat /etc/redhat-release 
    CentOS release 6.5 (Final)
    [root@web02 ~]# uname -r
    2.6.32-431.el6.x86_64

     

     

     2.关闭selinux iptables

    [root@web02 ~]# getenforce 
    Disabled
    [root@web02 ~]# /etc/init.d/iptables status
    iptables: Firewall is not running.

     

     

    3.安装的位置目录,存放软件的目录

    mkdir -p /application/   /server/tools

     

     

    4.软件版本

    mysql-5.6.34        #二进制编译安装

    php-5.5.32      #编译安装

    wordpress-4.7  

    nginx-1.12.2         #编译安装

     

    二 部署nginx

     

    1  创建用户

    [root@web02 tools]# useradd www -s /sbin/nologin -M

     

    2 解压,编译安装

    tar -xf nginx-1.12.2.tar.gz
    cd nginx-1.12.2
    ./configure --prefix=/application/nginx-1.12.2 --user=www --group=www --with-http_ssl_module --with-http_stub_status_module
    make && make install 

     

    3 创建软连接

    ln -s /application/nginx-1.12.2 /application/nginx

     

    4 启动 精简配置文件

    [root@web02 nginx-1.12.2]# /application/nginx/sbin/nginx -t    #检查配置文件
    nginx: the configuration file /application/nginx-1.12.2/conf/nginx.conf syntax is ok
    nginx: configuration file /application/nginx-1.12.2/conf/nginx.conf test is successful
    [root@web02 nginx-1.12.2]# /application/nginx/sbin/nginx      #启动

     

     

    [root@web02 nginx-1.12.2]# grep -Ev "#|^$" /application/nginx/conf/nginx.conf.default   > /application/nginx/conf/nginx.conf
    
    [root@web02 nginx
    -1.12.2]# cat /application/nginx/conf/nginx.conf 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; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }

     

     

     

    三 部署mysql(二进制)

     

    mysql官方下载链接地址:ftp://ftp.jaist.ac.jp/pub/mysql/Downloads/MySQL-5.6/

    1.下载mysql

    mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz

     

    2.解压安装

    tar xf mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz
    
    mv mysql-5.6.34-linux-glibc2.5-x86_64 /application/mysql-5.6.34
    
    ln -sf /application/mysql-5.6.34/ /application/mysql

     

     

    3.创建用户

    useradd mysql -M -s /sbin/nologin 
    
    chown -R mysql.mysql /application/mysql/data/

     

     

    4.初始化数据库

    /application/mysql/scripts/mysql_install_db --basedir=/application/mysql --datadir=/application/mysql/data/ --user=mysql

     

     

    5.启动mysql服务

     

    cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld
    sed -ri 's#/usr/local#/application#g' /etc/init.d/mysqld /application/mysql/bin/mysqld_safe
    cp /application/mysql/support-files/my-default.cnf /etc/my.cnf
    /etc/init.d/mysqld start

     

     

    6.设置密码

    /application/mysql/bin/mysqladmin -uroot password "oldboy123"
    /application/mysql/bin/mysql -uroot -poldboy123

     

     

    7.设置MySQL开机自启动

    chkconfig --add mysqld
    
    chkconfig mysqld on

     

     

    8.配置环境变量

    echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile 
    
    source /etc/profile

     

     

    9.清理无用的MYsql用户及库

    mysql>  select user,host from mysql.user;
    +------+-----------+
    | user | host      |
    +------+-----------+
    | root | 127.0.0.1 |
    | root | ::1       |
    |      | localhost |
    | root | localhost |
    |      | web02     |
    | root | web02     |
    +------+-----------+
    6 rows in set (0.00 sec)

     

     

    mysql> drop user "root"@"::1";
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> drop user ""@"localhost";
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> drop user ""@"web02";
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> drop user "root"@"web02";
    Query OK, 0 rows affected (0.00 sec)
    
    mysql>  select user,host from mysql.user;
    +------+-----------+
    | user | host      |
    +------+-----------+
    | root | 127.0.0.1 |
    | root | localhost |
    +------+-----------+
    2 rows in set (0.00 sec)

     

    四 php编译安装

    FastCGI:
    FastCGI是一个可伸缩地,高速地在HTTP服务器和动态脚本语言间通信的接口(在LINUX下 FastCGI接口即为socket,这个socke可以是文件的socket,也可以是IP socket),主要的优点是把动态语言和HTTP服务器分离开来,多数流行的HTTP服务器都支持FastCGI,包括Apache nginx lighttpd。

    同时,FastCGI也是被许多的脚本语言支持,例如当前比较流行的PHP,FastCGI接口采用的是C/S架构,可以将HTTP服务器和脚本解析服务器分开,同时还能在脚本解析服务器上启动一个或多个脚本来解析守护进程,HTTP服务器遇到动态程序时,可以将其直接交付给FastCGI进程来执行,然后将得到的结果返回给浏览器。这种方式可以让HTTP服务器专一地处理静态请求,或者将动态脚本服务器的结果返回给客户端,这在很大的程度上提高整个应用系统的性能

    FastCGI的重要特点:
    1)http服务器和动态脚本语言通信的接口和工具
    2)可把动态语言解析和HTTP服务器分离开
    3)Apache nginx lighttpd,以及多个动态语言支持FastCGI
    4)FastCGI接口采用的是C/S架构 ,分为客户端和服务端
    5)HPH动态语言服务器可以启动多个FastCGI的守护进程
    6)http服务器通过(例如nginx fastcgi_pass) FastCGI客户端和动态语言FastCGI服务器端通信(例如php-fpm)

    1.安装依赖包

    yum install -y zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libmcrypt-devel mhash mcrypt

    2.安装libiconv软件

    tar zxf libiconv-1.14.tar.gz
    cd libiconv-1.14
    ./configure --prefix=/usr/local/libiconv
    make
    make install
    cd ../

    3.下载php包

    php-5.5.32.tar.gz

    4.安装php包

    cd /server/tools/
    tar xf php-5.5.32.tar.gz
    cd php-5.5.32
    ./configure 
    --prefix=/application/php-5.5.32 
    --with-mysql=/application/mysql-5.6.34 
    --with-pdo-mysql=mysqlnd 
    --with-iconv-dir=/usr/local/libiconv 
    --with-freetype-dir 
    --with-jpeg-dir 
    --with-png-dir 
    --with-zlib 
    --with-libxml-dir=/usr 
    --enable-xml 
    --disable-rpath 
    --enable-bcmath 
    --enable-shmop 
    --enable-sysvsem 
    --enable-inline-optimization 
    --with-curl 
    --enable-mbregex 
    --enable-fpm 
    --enable-mbstring 
    --with-mcrypt 
    --with-gd 
    --enable-gd-native-ttf 
    --with-openssl 
    --with-mhash 
    --enable-pcntl 
    --enable-sockets 
    --with-xmlrpc 
    --enable-soap 
    --enable-short-tags 
    --enable-static 
    --with-xsl 
    --with-fpm-user=www 
    --with-fpm-group=www 
    --enable-ftp 
    --enable-opcache=no

    防错(以下信息可以不进行配置了)

    ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib64/
    touch ext/phar/phar.phar
    make
    make install
    ln -s /application/php-5.5.32/ /application/php

    5.配置php

    cp php.ini-production /application/php-5.5.32/lib/php.ini
    
    cd /application/php/etc/
    
    cp php-fpm.conf.default php-fpm.conf

    6.启动php程序服务

    /application/php/sbin/php-fpm

    [root@web02 etc]# netstat -lntup|grep php
    tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      128497/php-fpm 



    7.修改nginx支持php解析

    [root@web02 html]# cat ../conf/nginx.conf
    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;
           root         html;
        index        index.php index.html index.htm;
        location ~* .*.(php|php5)?$ {
           fastcgi_pass   127.0.0.1:9000;
           fastcgi_index  index.php;
               include       fastcgi.conf;
        }
        }
    }

    8.php 测试页面

    [root@web02 html]# cat test_info.php 
    <?php 
            phpinfo(); 
    ?> 

    9.编写mysql的测试页面

    [root@web02 html]# cat mysql_info.php 
    <?php
    //$link_id=mysql_connect('主机名','用户','密码');
    //mysql -u用户 -p密码 -h 主机
    $link_id=mysql_connect('localhost','root','oldboy123') or mysql_error();
    if($link_id){
    echo "mysql successful by oldboy !
    ";
    }else{
    echo mysql_error();
    }
    ?>

    10. 编写php 启动脚本

    打开配置文件 (/application/php/etc/php-fpm.conf)

    打开 注释    pid = run/php-fpm.pid 

    编写/etc/init.d/php-fpm

    #!/bin/bash
    # php-fpm startup script for the php-fpm 
    # php-fpm version:5.5.32
    # chkconfig: - 85 15
    # description: php-fpm is very good
    # processname: php-fpm
    # pidfile: /application/php/var/run/php-fpm.pid
    # config: /application/php/etcphp-fpm.conf
      
    php_command=/application/php/sbin/php-fpm
    php_config=/application/php/etc/php-fpm.conf
    php_pid=/application/php/var/run/php-fpm.pid
    
    RETVAL=0
    prog="php-fpm"
      
    #start function
    php_fpm_start() {
        /application/php/sbin/php-fpm
    }
      
    start(){
        if [ -e $php_pid  ]
        then
        echo "php-fpm already start..."
        exit 1
        fi
        php_fpm_start
    }
      
    stop(){
        if [ -e $php_pid ]
        then
        parent_pid=`cat $php_pid`
        all_pid=`ps -ef | grep php-fpm | awk '{if('$parent_pid' == $3){print $2}}'`
        for pid in $all_pid
        do
                kill $pid
            done
            kill $parent_pid
        fi
        #exit 1
    }
    
    restart(){
        stop
        sleep 3
        start
    }
    
    case "$1" in
            start)
          start
        ;;
        stop)
          stop
        ;;
            restart)
              restart
                    ;;
            * )
        echo "Usage: $prog [start|stop|restart]"
          exit 1
           ;;
    esac
    ## 添加执行权限 
    chmod a+x /etc/init.d/php-fpm
    
    ## 加入服务
    chkconfig --add php-fpm
    
    ## 开机自启 
    chkconfig php-fpm on

    五 安装wordpress

    1.下载软件

    wordpress-4.7.3-zh_CN.tar.gz

    2. 安装 wordpress

    tar xf wordpress-4.7.3-zh_CN.tar.gz 
    mv wordpress/* /application/nginx/html/
    chown -R www.www /application/nginx/html/

    3.创建库 并授权

    create database wordpress;
    
    grant all on wordpress.* to 'wordpress'@'localhost' identified by 'oldboy123';
  • 相关阅读:
    P6585 中子衰变
    [APIO2020]有趣的旅途
    CF1354F Summoning Minions
    CF1361C Johnny and Megan's Necklace
    CF1368E Ski Accidents
    CF1458C Latin Square
    CF1368F Lamps on a Circle
    用户和组的管理
    Windows命令
    1
  • 原文地址:https://www.cnblogs.com/augustyang/p/10108766.html
Copyright © 2011-2022 走看看