zoukankan      html  css  js  c++  java
  • CentOS 6.5安装配置LNMP服务器(Nginx+PHP+MySQL)

    CentOS 6.5安装配置LNMP服务器(Nginx+PHP+MySQL)
    一.准备篇:

    1 /etc/init.d/iptables stop          #关闭防火墙
    2 关闭SELINUX
    3 vi /etc/selinux/config
    4 #SELINUX=enforcing                  #注释掉
    5 #SELINUXTYPE=targeted             #注释掉
    6 SELINUX=disabled                     #增加
    7 :wq                                           
    8 shutdown -r now                       #重启系统  

    二.安装篇

    1.安装nginx

     1 yum remove httpd* php*           #删除系统自带的软件包
     2 安装步骤:
     3 因为nginx模块需要第三方库的支持,需要安装下列库.
     4  安装gcc编译器及相关工具
     5 #yum -y install gcc gcc-c++ autoconf automake make
     6 安装相关依赖的模块
     7 #yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel
     8 创建nginx系统账户:
     9 由于nginx是系统服务,运行此服务需要系统账户。
    10 # groupadd nginx
    11 # useradd -r -g nginx -s /sbin/nologin -M nginx
    12 软件源码包存放位置:/opt/
    13 #cd /opt/
    14 # tar -zxvf nginx-1.2.4.tar
    15 #cd nginx-1.2.4
    16 #./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module         //通过编译源码的方式进行安装 
    17 #make
    18 #make install         
    19  启动Nginx
    20 #启动nginx
    21 #/usr/local/nginx/sbin/nginx -t
    22 显示以下信息为正确的
    23 
    24 the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok configuration file /usr/local/nginx/conf/nginx.conf test is successful
    25 #/usr/local/nginx/sbin/nginx

    启动成功后,查看nginx进程信息: # ps -ef | grep nginx ,看是否存在nginx的进程来确认是否成功启动。

    2.安装MySQL(也可以使用系统自带mysql)

    1、安装MySQL

     1 yum install mysql mysql-server                   #输入Y即可自动安装,直到安装完成
     2 /etc/init.d/mysqld start                                #启动MySQL
     3 
     4 chkconfig mysqld on                                    #设为开机启动
     5 
     6 cp /usr/share/mysql/my-medium.cnf    /etc/my.cnf     #拷贝配置文件(注意:如果/etc目录下面默认有一个my.cnf,直接覆盖即可)
     7 为root账户设置密码
     8 
     9 mysql_secure_installation
    10 
    11 #回车,根据提示输入Y,输入2次密码,回车,根据提示一路输入Y,最后出现:Thanks for using MySQL!
    12 
    13 MySql密码设置完成,重新启动 MySQL:
    14 
    15 /etc/init.d/mysqld restart      #重启
    16 
    17 /etc/init.d/mysqld stop         #停止   
    18 
    19 /etc/init.d/mysqld start        #启动      

    3、安装PHP5

    1、安装PHP5

     1 yum install php php-fpm                      #根据提示输入Y直到安装完成
     2 
     3 2、安装PHP组件,使 PHP5 支持 MySQL
     4 
     5 yum install php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt  php-bcmath php-mhash libmcrypt
     6 
     7 #这里选择以上安装包进行安装,根据提示输入Y回车
     8 
     9 chkconfig php-fpm on                          #设置php-fpm开机启动
    10 
    11 /etc/init.d/php-fpm start                      #启动php-fpm

    配置篇

    一、配置nginx支持php

     1 cp  /usr/local/nginx/conf/nginx.conf   /usr/local/nginx/conf/nginx.confbak       #备份原有配置文件
     2 vim /usr/local/nginx/conf/nginx.conf                                                                                  
     3 user www ;          #修改nginx运行账号为:www用户
     4 :wq                      #保存退出
     5 vim  /usr/local/nginx/conf/nginx.conf                                                            
     6 
     7 index  index.php index.html index.htm;          #增加index.php
     8 
     9 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    10 #
    11 location ~ .php$ {
    12 root html;
    13 fastcgi_pass 127.0.0.1:9000;
    14 fastcgi_index index.php;
    15 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    16 include fastcgi_params;
    17 }
    18 
    19 #取消FastCGI server部分location的注释,并要注意fastcgi_param行的参数,改为$document_root$fastcgi_script_name,或者使用绝对路径
    20 service nginx  restart     #重启nginx

    二、php配置

     1 vi /etc/php.ini  
     2 
     3 date.timezone = PRC    #在946行 把前面的分号去掉,改为date.timezone = PRC
     4 
     5 disable_functions =
     6 
     7 passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,ope
     8 
     9 nlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdns
    10 
    11 rr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd,
    12 
    13 posix_getegid,posix_geteuid,posix_getgid,
    14 
    15 posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,
    16 
    17 posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty,
    18 
    19 posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,
    20 posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname
    21 #在386行列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。
    22 找到:date.timezone =
    23 修改为:date.timezone = PRC       #设置时区
    24 找到:expose_php = On
    25 修改为:expose_php = OFF          #禁止显示php版本的信息
    26 找到:short_open_tag = Off
    27 修改为:short_open_tag = ON     #支持php短标签
    28 :wq!                                              #保存退出

    测试篇

    cd  /usr/local/nginx/html
    vim  index.php
    
    <?php
    
     echo phpinfo();
    ?>
    
    :wq!
    
    chown www.www  /usr/local/nginx/html -R   #设置权限
    service nginx restart  #重启nginx
    service php-fpm restart  #重启php-fpm

    在客户端浏览器输入服务器IP地址,可以看到相关的配置信息!

    说明lnmp配置成功!
    至此,CnetOS 6.4安装配置LNMP(Nginx+PHP+MySQL)配置完成。

     号外:

    PHP启动脚本:对照自己的目录,直接放置在/etc/init.d/下给执行权限即可运行.

    #! /bin/sh
    #
    # chkconfig: - 84 16
    # description:    PHP FastCGI Process Manager
    # processname: php-fpm
    # config: /etc/php-fpm.conf
    # config: /etc/sysconfig/php-fpm
    # pidfile: /var/run/php-fpm/php-fpm.pid
    #
    ### BEGIN INIT INFO
    # Provides: php-fpm
    # Required-Start: $local_fs $remote_fs $network $named
    # Required-Stop: $local_fs $remote_fs $network
    # Short-Description: start and stop PHP FPM
    # Description: PHP FastCGI Process Manager
    ### END INIT INFO
    
    # Standard LSB functions
    #. /lib/lsb/init-functions
    
    # Source function library.
    . /etc/init.d/functions
    
    # Check that networking is up.
    . /etc/sysconfig/network
    
    # Additional environment file
    if [ -f /etc/sysconfig/php-fpm ]; then
          . /etc/sysconfig/php-fpm
    fi
    
    if [ "$NETWORKING" = "no" ]
    then
        exit 0
    fi
    
    RETVAL=0
    prog="php-fpm"
    pidfile=${PIDFILE-/var/run/php-fpm/php-fpm.pid}
    lockfile=${LOCKFILE-/var/lock/subsys/php-fpm}
    
    start () {
        echo -n $"Starting $prog: "
        dir=$(dirname ${pidfile})
        [ -d $dir ] || mkdir $dir
        daemon --pidfile ${pidfile} /usr/sbin/php-fpm --daemonize
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch ${lockfile}
    }
    stop () {
        echo -n $"Stopping $prog: "
        killproc -p ${pidfile} php-fpm
        RETVAL=$?
        echo
        if [ $RETVAL -eq 0 ] ; then
            rm -f ${lockfile} ${pidfile}
        fi
    }
    
    restart () {
            stop
            start
    }
    
    reload () {
        echo -n $"Reloading $prog: "
        if ! /usr/sbin/php-fpm --test ; then
                RETVAL=6
                echo $"not reloading due to configuration syntax error"
                failure $"not reloading $prog due to configuration syntax error"
        else
            killproc -p ${pidfile} php-fpm -USR2
            RETVAL=$?
        fi
        echo
    }
    
    
    # See how we were called.
    case "$1" in
      start)
        start
        ;;
      stop)
        stop
        ;;
      status)
        status -p ${pidfile} php-fpm
        RETVAL=$?
        ;;
      restart)
        restart
        ;;
      reload|force-reload)
        reload
        ;;
      configtest)
         /usr/sbin/php-fpm --test
        RETVAL=$?
        ;;
      condrestart|try-restart)
        [ -f ${lockfile} ] && restart || :
        ;;
      *)
        echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart|try-restart|configtest}"
        RETVAL=2
            ;;
    esac
    
    exit $RETVAL
    PHP启动脚本
  • 相关阅读:
    linux常用快捷键
    msf远程调用OpenVAS
    (三)漏洞平台搭建-xssplatform
    (二)漏洞平台搭建-sql-lab
    (一)漏洞平台搭建-DVWA
    msf永恒之蓝漏洞利用命令总结
    解决kali无法全屏问题
    centos7源码安装mysql数据库
    【多数人的误区】十二生肖属相不是从春节开始算的!
    python元组不可变是指什么不可变
  • 原文地址:https://www.cnblogs.com/saneri/p/4990027.html
Copyright © 2011-2022 走看看