liuxiaoyun111 发表于 2018-12-11 13:34:01

Centos6.5 + Nginx +mysql + php 安装配置文档

  一、安装环境准备

  yum -y install vim lrzsz

http://s1.运维网.com/images/20180627/1530080291469405.png
  上传mysql、nginx、php安装包
  (1)Nginx的下载地址:

  http://nginx.org/en/download.html
http://s1.运维网.com/images/20180627/1530080810369217.png
  (2)PHP安装包的下载

  http://php.net/downloads.php
http://s1.运维网.com/images/20180627/1530081006793971.png       (3)MySQL的下载

  https://www.mysql.com/downloads/
http://s1.运维网.com/images/20180627/1530082041262442.png            (4)安装包上传到服务器 /usr/local/src文件夹目录下:
  mkdir -p /usr/local/src

  cd /usr/local/src

  ls

http://s1.运维网.com/images/20180627/1530083714966423.png
  

  二、Nginx 安装
  1、先安装一些nginx需要的软件包:

  yum -y install gcc gcc-c++ make tar pcre pcre-devel zlib zlib-devel openssl openssl-devel
http://s1.运维网.com/images/20180627/1530086687413193.png
  2、解压软件包并安装:

  cd /usr/local/src

  ls

  tar -zxvf nginx-1.14.0.tar.gz
http://s1.运维网.com/images/20180627/1530086820508084.png
  ls
  cd nginx-1.14.0
  ./configure --prefix=/usr/local/nginx --with-http_ssl_module
http://s1.运维网.com/images/20180627/1530089040622169.png
  make && make install

http://s1.运维网.com/images/20180627/1530089164543186.png
  查看是否安装成功,查看安装版本:

  /usr/local/nginx/sbin/nginx -V

http://s1.运维网.com/images/20180627/1530089241207574.png
  启动nginx服务,查看nginx服务进程:

  /usr/local/nginx/sbin/nginx         启动服务

  ps auxfw | grep nginx

http://s1.运维网.com/images/20180627/1530089773878706.png
http://s1.运维网.com/images/20180627/1530089839906984.png
  三、PHP的安装
  1、php的下载

  http://www.php.net/downloads.php
http://s1.运维网.com/images/20180627/1530090243250101.png
  2、上传PHP安装软件包并解压
  cd /usr/local/src

  ls

  tar -zxvf php-7.2.7.tar.gz
http://s1.运维网.com/images/20180627/1530090494410593.png
http://s1.运维网.com/images/20180627/1530090574726520.png
  3、提前安装一些 php需要用的的安装包:

  yum -y install epel-release gcc gcc-c++ make tar pcre pcre-devel zlib zlib-devel openssl openssl-devel libxml2 libxml2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel openldap openldap-devel libmcrypt libmcrypt-devel libldap*
http://s1.运维网.com/images/20180627/1530090827407975.png
  (备注:对于一次性安装较多软件包的时候,可多执行几次命令,直至出现:Nothing todo)
http://s1.运维网.com/images/20180627/1530091242698227.png
  

  4、安装PHP

  cd /usr/local/src/

  cd php-7.2.7
  cp -frp /usr/lib64/libldap* /usr/lib/      #将 /usr/lib64/libldap * 文件 复制到 /usr/lib/ 目录下
  ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-ctype --with-mysql=mysqlnd --with-mysqli=mysqlnd --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-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap
http://s1.运维网.com/images/20180627/1530092323594942.png
http://s1.运维网.com/images/20180627/1530092385113906.png
  然后进行 安装 编译

  make && make install

http://s1.运维网.com/images/20180627/1530093146291671.png
  查看是否安装成功及PHP安装的版本:
  /usr/local/php/bin/php -v

http://s1.运维网.com/images/20180627/1530093604365603.png
  

  四、测试nginx 连接php
  配置nginx.conf配置文件

  vim /usr/local/nginx/conf/nginx.conf
http://s1.运维网.com/images/20180628/1530168895800987.png
  vim /usr/local/php/etc/php-fpm.conf

http://s1.运维网.com/images/20180628/1530169654194429.png
              /usr/local/php/sbin/php-fpm

              http://s1.运维网.com/images/20180628/1530171272838616.png         出现这样的错误,是找不到相应的文件
        cd php-fpm.d/
        cp www.conf.default www.conf
  /usr/local/php/sbin/php-fpm
  

  vim /usr/local/nginx/html/test.php
http://s1.运维网.com/images/20180628/1530171592830239.png
http://s1.运维网.com/images/20180628/1530171928251899.png
  五、mysql的安装配置
  1、mysql的下载

  https://www.mysql.com/downloads/
http://s1.运维网.com/images/20180628/1530173022109930.png
  2、安装准备
  需要安装一下软件包:
  yum -y install gcc gcc-c++ make tar openssl openssl-devel cmake ncurses ncurses-devel
http://s1.运维网.com/images/20180628/1530173165998308.png
  3、上传数据库安装文件包

  cd /usr/local/src/
  ls

  tar -zxvf mysql-5.7.22.tar.gz
  cd mysql-5.7.22
  ls

http://s1.运维网.com/images/20180628/1530173464335227.png
  4、安装mysql

  cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DMYSQL_DATADIR=/usr/local/mysql/mydata -DSYSCONFDIR=/etc -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_SSL=yes -DWITH_BOOST=/usr/local/boost/boost_1_59_0 -DMYSQL_USER=mysql
http://s1.运维网.com/images/20180628/1530173566864692.png
  错误提示,找不到boost,解决办法:

  (1)在/usr/local 下创建一个名为boost的文件夹
                  mkdir -p /usr/local/boost
  (2)进入这个新建的文件夹然后下载boost
                 yum -y install wget

                  wget http://www.sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
  (3)解压:

  tar -zxvf boost_1_59_0.tar.gz
                  ls

                  http://s1.运维网.com/images/20180628/1530173918353258.png
        (4)进行配置;

                  ./bootstrap.sh

        (5)编译

                  ./b2

        (6)安装

                  ./b2 install
              编译安装完成后,会把boost头文件拷贝到/usr/local/include/目录下,库文件在/usr/local/lib/下
      安装cmake(最新版本)
            (1) 获取源码:依然下载到/usr/local/src目录下,cd /usr/local/src,获取软件包:

                  wget https://cmake.org/files/v3.8/cmake-3.8.0.tar.gz
            (2)解压:
                  tar -zxvf cmake-3.8.0.tar.gz
             (3) 进入cmake目录:
                  cd cmake-3.8.0
                (4) ./bootstrap
                (5)gmake
                (6)gmake install
                (7) 添加环境变量(此步骤很重要,不然运行cmake的时候会提示找不到 CMAKE_ROOT)
                        用vi在文件/etc/profile 文件中增加变量,使其永久有效:

                        vi/etc/profile

                        在文件末尾追加以下两行代码:


                        PATH=/usr/local/src/cmake-3.8.0/bin:$PATH
                        export PATH
                  然后执行以下操作:

                        source /etc/profile          #使其生效

                         echo $PATH             #查看PATH值
  

      切换到MySQL目录,继续 cmake
      cd /usr/local/src/mysql-5.7.22
  cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DMYSQL_DATADIR=/usr/local/mysql/mydata -DSYSCONFDIR=/etc -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_SSL=yes -DWITH_BOOST=/usr/local/boost/boost_1_59_0 -DMYSQL_USER=mysql
http://s1.运维网.com/images/20180628/1530176451147227.png
  然后进行make&&make install   (编译 安装大概需要半个小时左右)
        http://s1.运维网.com/images/20180628/1530178526824492.png
      5、创建文件夹、用户等信息;

        mkdir -p /usr/local/mysql

        mkdir -p /usr/local/mysql/data
        groupadd mysql

        useradd -g mysql -M -s /sbin/nologin mysql

        http://s1.运维网.com/images/20180628/1530178792248709.png
      6、初始化数据库

        然后到mysql的安装目录bin下,初始化数据库:
            cd/usr/local/mysql/bin

            ./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data/ --basedir=/usr/local/mysql --socket=/usr/local/mysql/mysql.sock
            运行后最后一句 生成了一个mysql默认密码,复制到一个地方,保存下来
        http://s1.运维网.com/images/20180628/1530178958920371.png

        添加mysql服务,拷贝mysql配置文件:
   回到mysql安装目录 cd ..
   进入support-files目录 cd support-files
   复制启动文件 cp -a mysql.server /etc/init.d/mysql//-a 可以把原来的属性一起复制过来
        http://s1.运维网.com/images/20180628/1530179198857795.png   
      7、启动mysql
        service mysql start
        http://s1.运维网.com/images/20180628/1530180001560568.png

         出现上面的错误,需要修改 /etc/my.cnf配置文件
        http://s1.运维网.com/images/20180628/1530180154883159.png
              查找/usr/local/mysql 目录下面是不是有mysql.sock文件夹,有的话,需要删掉 ,就可以启动成功了
        每次出现这样的错误提示,可能有多种原因导致,需要查看mysql日志,确定错误的位置和类型

        more /var/log/mysql.log

        http://s1.运维网.com/images/20180629/1530271282508728.png
        具体问题,具体分析

        最后mysql启动成功:

        http://s1.运维网.com/images/20180629/1530271320966853.png
        

      8、修改数据库登录密码:

        登陆mysql:
      到 mysql安装目录下的bin目录下:

            cd /usr/local/mysql/bin
            ./mysql -uroot -p
            Enter password:            //输入之前保存的默认密码
        http://s1.运维网.com/images/20180629/1530271466971007.png

        修改root密码:

        SET PASSWORD = PASSWORD('mysql123');
           更新mysql的系统权限相关表;
            flush privileges;
        http://s1.运维网.com/images/20180629/1530271543790510.png

  

  六、测试PHP 连接mysql
        vim /usr/local/nginx/html/test_mysql.php
      http://s1.运维网.com/images/20180629/1530272230647250.png
        




页: [1]
查看完整版本: Centos6.5 + Nginx +mysql + php 安装配置文档