zoukankan      html  css  js  c++  java
  • LNMP

     

    通过LNMP制作个人博客

    (1) 创建mysql用户的账号

     
    1. [root@localhost ~]# groupadd mysql
    2. [root@localhost ~]# useradd -s /sbin/nologin -g mysql -M mysql
    3. [root@localhost ~]# tail -1 /etc/passwd
    4. mysql:x:501:501::/home/mysql:/sbin/nologin
    5. [root@localhost ~]# id mysql
    6. uid=501(mysql) gid=501(mysql) groups=501(mysql)

    (2)获取MySQL二进制软件包

    百度云盘:http://pan.baidu.com/s/1hrBCzsC

    (3) 采用二进制方式安装MySQL

    1. [root@localhost ~]# tar xf mysql-5.5.32-linux2.6-x86_64.tar.gz -C /usr/local/
    2. [root@localhost ~]# cd /usr/local/
    3. [root@localhost local]# mv mysql-5.5.32-linux2.6-x86_64 mysql-5.5.32
    4. [root@localhost local]# ln -s mysql-5.5.32 mysql
    5. [root@localhost local]# ls
    6. bin  games    lib    libexec  mysql-5.5.32  nginx-1.10.2  share
    7. etc  include  lib64  mysql    nginx         sbin          src
    8. [root@localhost local]# cd /usr/local/mysql
    9. [root@localhost mysql]# ls
    10. bin      data  include         lib  mysql-test  scripts  sql-bench
    11. COPYING  docs  INSTALL-BINARY  man  README      share    support-files
    12. #提示:
    13. 二进制安装包,仅需要解压就可以了,不需要执行cmake/configure,make,make install等过程

    4)初始化MySQL配置文件my.cnf

    [root@localhost ~]# cd /usr/local/mysql

    [root@localhost mysql]# /bin/cp support-files/my-small.cnf /etc/my.cnf

    (5)初始化MySQL数据库文件

    1. [root@localhost ~]# mkdir -p /usr/local/mysql/data #建立MySQL数据文件目录
    2. [root@localhost ~]# chown -R mysql.mysql /usr/local/mysql #授权mysql用户管理MySQL的安装目录
    3. [root@localhost ~]# yum -y install libaio #光盘源安装依赖包,否则下一步的编译会报错
    4. [root@localhost ~]# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
    5. #初始化MySQL数据库文件,会有很多信息提示,如果没有ERROR级别的错误,会有两个OK的字样,表示初始化成功,否则就要解决初始化的问题

    配置并启动MySQL数据库

    (1)设置MySQL启动脚本,命令如下

    1. [root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
    2. #拷贝MySQL启动脚本到MySQL的命令路径
    3. [root@localhost mysql]# chmod +x /etc/init.d/mysqld
    4. #使脚本可执行
    5. (2)MySQL二进制默认安装路径是/usr/local/mysql,启动脚本里是/usr/local/mysql。如果安装路径不同,那么脚本里路径等都需要替换

      (3)启动MySQL数据库,命令如下:

       
      1. [root@localhost mysql]# /etc/init.d/mysqld start
      2. Starting MySQL.. SUCCESS!

      以上是启动数据库的规范方法之一,但还可以用如下方式启动,
      /usr/local/mysql/bin/mysqld_safe --user=mysql &
      这个命令结尾的“&”符号,作用是在后台执行MySQL服务,命令执行完还需要按下回车才能进入命令行状态。

      (4)检查MySQL数据库是否启动,命令如下:

       
      1. [root@localhost mysql]# netstat -antup | grep mysql
      2. tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 1702/mysqld
    6. 3.4 LNMP之PHP(FastCGI方式)服务的安装和准备

       

      3.4.1 检查Nginx及MySQL的安装情况

      (1)检查确认Nginx及MySQL的安装路径,命令如下:

       
      1. [root@localhost ~]# ls -ld /usr/local/nginx
      2. lrwxrwxrwx. 1 root root 24 Jul 9 14:31 /usr/local/nginx -> /usr/local/nginx-1.10.2/
      3. [root@localhost ~]# ls -ld /usr/local/mysql
      4. lrwxrwxrwx. 1 mysql mysql 12 Jul 14 07:13 /usr/local/mysql -> mysql-5.5.32

      (2)检查端口及启动情况,命令如下:

       
      1. [root@localhost ~]# netstat -antup | grep -E "80|3306"
      2. tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1193/nginx
      3. tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 1702/mysqld

      (3)测试访问Nginx及MySQL是否OK,命令如下:

       
      1. [root@localhost ~]# wget 127.0.0.1 #测试Nginx
      2. --2017-07-14 09:54:12-- http://127.0.0.1/
      3. Connecting to 127.0.0.1:80... connected.
      4. HTTP request sent, awaiting response... 200 OK
      5. Length: 624 [text/html]
      6. Saving to: index.html
      7. 100%[=========================================================================================>] 624 --.-K/s in 0s
      8. 2017-07-14 09:54:12 (2.12 MB/s) - index.html saved [624/624]
      9. [root@localhost ~]# mysql -uroot -p #测试MySQL
      10. Enter password:
      11. Welcome to the MySQL monitor. Commands end with ; or g.
      12. Your MySQL connection id is 6
      13. Server version: 5.5.32 MySQL Community Server (GPL)
      14. Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
      15. Oracle is a registered trademark of Oracle Corporation and/or its
      16. affiliates. Other names may be trademarks of their respective
      17. owners.
      18. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
      19. mysql> quit
      20. Bye

      如果访问结果和上述一致,就表明Nginx及MySQL的安装一切正常

       

      3.4.2 检查安装PHP所需的lib库

      PHP程序在开发及运行时会调用一些诸如zlib,gd等函数库,因此需要确认lib库是否已经安装,执行过程如下:

       
      1. [root@localhost ~]# rpm -qa zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel
      2. zlib-devel-1.2.3-29.el6.x86_64
      3. [root@localhost ~]# rpm -qa freetype-devel libpng-devel gd libcurl-devel libxsl

    3.4.2 检查安装PHP所需的lib库

    PHP程序在开发及运行时会调用一些诸如zlib,gd等函数库,因此需要确认lib库是否已经安装,执行过程如下:

     
    1. [root@localhost ~]# rpm -qa zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel
    2. zlib-devel-1.2.3-29.el6.x86_64
    3. [root@localhost ~]# rpm -qa freetype-devel libpng-devel gd libcurl-devel libxslt-devel

    执行下面命令安装相关的lib软件包

     
    1. [root@localhost ~]# yum -y install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel
    2. [root@localhost ~]# yum -y install freetype-devel libpng-devel gd libcurl-devel libxslt-devel

    安装后的结果如下:

     
    1. [root@localhost ~]# rpm -qa zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel
    2. zlib-devel-1.2.3-29.el6.x86_64
    3. libxml2-devel-2.7.6-14.el6.x86_64
    4. libjpeg-turbo-devel-1.2.1-1.el6.x86_64
    5. #这里仅缺少libiconv-devel包
    6. [root@localhost ~]# rpm -qa freetype-devel libpng-devel gd libcurl-devel libxslt-devel
    7. freetype-devel-2.3.11-14.el6_3.1.x86_64
    8. libpng-devel-1.2.49-1.el6_2.x86_64
    9. libcurl-devel-7.19.7-37.el6_4.x86_64
    10. libxslt-devel-1.1.26-2.el6_3.1.x86_64
    11. gd-2.0.35-11.el6.x86_64

    3.5.3 编译PHP

    正确执行前文配置PHP软件的./configure系列命令后,就可以编译PHP软件了,具体操作过程如下:

     
    1. [root@localhost php-5.3.28]# ln -s /usr/local/mysql/lib/libmysqlclient.so.18
    2. libmysqlclient.so.18 libmysqlclient.so.18.0.0
    3. [root@localhost php-5.3.28]# ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/
    4. [root@localhost php-5.3.28]# touch ext/phar/phar.phar
    5. [root@localhost php-5.3.28]# make
    6. #make最后的正确提示
    7. Build complete.
    8. Don't forget to run 'make test'.
     

    3.5.4 安装PHP生成文件到系统

    [root@localhost php-5.3.28]# make install

     

    3.5.5 配置PHP引擎配置文件php.ini

    (1)设置软链接以方便访问,命令如下:

     
    1. [root@localhost ~]# ln -s /usr/local/php5.3.28/ /usr/local/php
    2. [root@localhost ~]# ls -l /usr/local/php
    3. lrwxrwxrwx. 1 root root 21 Jul 14 13:06 /usr/local/php -> /usr/local/php5.3.28/

    (3)拷贝PHP配置文件到PHP默认目录,并更改文件名称为php.ini,命令如下:

     
    1. [root@localhost php-5.3.28]# cp php.ini-production /usr/local/php/lib/php.ini
    2. [root@localhost php-5.3.28]# ls -l /usr/local/php/lib/php.ini
    3. -rw-r--r--. 1 root root 69627 Jul 14 13:25 /usr/local/php/lib/php.ini
     

    3.5.6 配置PHP(FastCGI方式)的配置文件php-fpm.conf

     
    1. [root@localhost php-5.3.28]# cp php.ini-production /usr/local/php/lib/php.ini
    2. [root@localhost php-5.3.28]# ls -l /usr/local/php/lib/php.ini
    3. -rw-r--r--. 1 root root 69627 Jul 14 13:25 /usr/local/php/lib/php.ini
    4. [root@localhost php-5.3.28]# cd /usr/local/php/etc/
    5. [root@localhost etc]# ls
    6. pear.conf php-fpm.conf.default
    7. [root@localhost etc]# cp php-fpm.conf.default php-fpm.conf

    关于php-fpm.conf,暂时可用默认的配置,先把服务搭好,以后再进行优化。

    3.5.7 启动PHP服务(FastCGI方式)

    (1)启动PHP服务php-fpm,命令如下:

     
    1. [root@localhost etc]# /usr/local/php/sbin/php-fpm

    (2)检查PHP服务php-fpm的进程及启动端口的情况,命令如下:

     
    1. [root@localhost etc]# ps -ef | grep php-fpm
    2. root 126611 1 0 13:36 ? 00:00:00 php-fpm: master process (/usr/local/php5.3.28/etc/php-fpm.conf)
    3. nginx 126612 126611 0 13:36 ? 00:00:00 php-fpm: pool www
    4. nginx 126613 126611 0 13:36 ? 00:00:00 php-fpm: pool www
    5. root 126619 126548 0 13:39 pts/1 00:00:00 grep php-fpm
    6. [root@localhost etc]# lsof -i:9000 #默认9000端口提供服务
    7. COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
    8. php-fpm 126611 root 7u IPv4 136041 0t0 TCP localhost:cslistener (LISTEN)
    9. php-fpm 126612 nginx 0u IPv4 136041 0t0 TCP localhost:cslistener (LISTEN)
    10. php-fpm 126613 nginx 0u IPv4 136041 0t0 TCP localhost:cslistener (LISTEN)

    3.6 配置Nginx支持PHP程序请求访问

     

    3.6.1 修改Nginx配置文件

    (1)查看nginx当前的配置,命令如下

    最终blog虚拟机的完整配置如下:

     
    1. [root@localhost conf]# cat extra/blog.conf
    2. server {
    3. listen 80;
    4. server_name blog.yunjisuan.com;
    5. location / {
    6. root /var/www/html/blogcom;
    7. index index.html index.htm;
    8. }
    9. location ~ .*.(php|php5)?$ {
    10. root /var/www/html/blogcom;
    11. fastcgi_pass 127.0.0.1:9000;
    12. fastcgi_index index.php;
    13. include fastcgi.conf;
    14. }
    15. }
     

    3.6.2 检查并启动Nginx

    可通过如下命令检查Nginx配置文件的语法:

     
    1. [root@localhost conf]# /usr/local/nginx/sbin/nginx -t
    2. nginx: the configuration file /usr/local/nginx-1.10.2//conf/nginx.conf syntax is ok
    3. nginx: configuration file /usr/local/nginx-1.10.2//conf/nginx.conf test is successful
    4. [root@localhost conf]# /usr/local/nginx/sbin/nginx -s reload

     

     

  • 相关阅读:
    Python学习日志(三)
    Python学习日志(二)
    软件测试入门随笔——软件测试基础知识(八)
    软件测试入门随笔——软件测试基础知识(七)
    软件测试入门随笔——软件测试基础知识(六)
    fastcgi 性能初配 504 gateway time-out
    php 文件锁
    php sleep()的实时输出打印,清除ob缓冲区
    php用simplexml来操作xml
    PHP防SQL注入不要再用addslashes和mysql_real_escape_string
  • 原文地址:https://www.cnblogs.com/A6666/p/9930380.html
Copyright © 2011-2022 走看看