candy 发表于 2015-11-15 13:17:21

CentOS配置LAMP

   1.前奏:安装rarlinux
  事先将LAMP所用到的tar包打包成了rar文件,要在linux下解压缩得用到rarlinux,在winrar官网可下载( http://www.rarlab.com/download.htm)
  解包后就可以直接使用rar命令了

    2.前奏:fencview.vim插件
  之前有个LAMP.txt文件,记录了安装LAMP的过程。
  但是用vim打开会出现乱码问题
  可以去下载fencview.vim这个插件(http://www.vim.org/scripts/script.php?script_id=1708)
  下载后直接放到/usr/share/vim/vim72/plugin/目录下就可以
  再用vim打开,文件的编码就会自动识别成功了

    3.安装:apache
         3.1 安装apr-1.4.5:
  configure时报错:configure: error: no acceptable C compiler found in $PATH
                  尼玛,安装系统时竟然没有安装gcc
  yuminstall gcc先安装gcc再说
  gcc 安装成功后再configure、make、make install就行了
  #./configure --prefix=/app/apr-1.4.5
  mm(之前已定义 alias mm='make && make install')

          3.2 安装apr-util-1.5.2:
  configure时要记得 --with-apr=刚才安装的apr路径
  # ./configure --prefix=/app/apr-util-1.5.2 --with-apr=/app/apr-1.4.5
  # mm


          3.3 安装pcre-8.33
  # ./configure --prefix=/app/pcre-8.33
  这回又出现configure: error: You need a C++ compiler for C++ support.
                怎么连c++都没装
  yum install gcc-c++
  再次configure就成功了

  # mm
          3.4 安装apache(httpd-2.4.6)
  # ./configure --prefix=/app/httpd-2.4.6 --with-apr=/app/apr-1.4.5/ --with-apr-util=/app/apr-util-1.5.2/ --with-pcre=/app/pcre-8.33/ --enable-so --enable-rewrite --enable-cgi
  # mm
  安装成功后,可以把bin/apachectl放到/etc/init.d下面,这样就可一用service 、chkconfig命令管理apache了
  可是chkconfig --add apachectl后出现
  apachectl 服务不支持 chkconfig
                在apachectl的第一行下添加两行
  #chkconfig:345 61 61
                #description:Apache httpd
  然后chkconfig --add 就可以使用了
  如果启动apache时遇到
               AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 183.207.232.253. Set the 'ServerName' directive globally to suppress   this message
            只需去apaceh的配置文件 apache目录/conf/httpd.conf

  找到#ServerName
  在其下面添加一行 ServerName 域名:端口 就行了
   4.安装mysql
      4.1安装cmake

  tar xzf mysql-5.6.13.tar.gz后
  按照常规执行./configure命令

  出现错误bash: ./configure: 没有那个文件或目录
  原来从mysql5.5起,源码安装开始使用cmake了
  先找一下系统有没有cmake命令
  rpm -qa | grep cmake
  
            果然什么都没输出
  那就先安装cmake
  yum install cmake
      4.2 安装mysql
  cmake -DCMAKE_INSTALL_PREFIX=/app/mysql-5.6.13 -DDEFAULT_CHARSET=utf8

            注意cmake只定路径的方式和./configure不同
  之后安装就可以了

  安装比较慢         

      4.3配置mysql
                  4.3.1增加mysql用户和修改配置文件

               安装完成后,由于mysql需要一个默认的mysql用户

               所以先增加用户
               useradd -r mysql(-r设置是系统帐号)
               将mysql配置文件放到系统配置路径下
               # cp support-files/my-default.cnf/etc/my.cnf
               如果有提示是否覆盖就覆盖掉
             编辑/etc/my.cnf
               修改、添加内容:
            
             basedir = mysql安装目录
             datadir = mysql安装目录/data
             port = 3306
             server_id = 100
             socket = /tmp/mysql.sock
             default-storage-engine = MyISAM
             4.3.2安装默认的数据库
              # scripts/mysql_install_db --user=mysql --collation-server=utf8_general_ci
            如果在CMAKE阶段没有只定默认的字符集为utf8的话(-DDEFAULT_CHARSET=utf8),此时会有错误
              2013-10-23 23:28:27 18085 COLLATION 'utf8_general_ci' is not valid for CHARACTER SET 'latin1'
            2013-10-23 23:28:27 18085 Aborting
              解决方法是修改默认字符集
              vim /etc/my.cnf
              在中加上character-set-server = utf8
              如果还不行的话,就只好重新编译安装了      
          4.3.3更改mysql安装目录的属主和属组
  # chown -R mysql:mysql mysql安装目录/*
  4.3.4将mysql加入系统服务
  # cp support-files/mysql.server /etc/init.d/mysql
  # chkconfig --add mysql
  现在就可以用service和chkconfig来启动mysql了

      4.4增加mysql的root用户
             # bin/mysqladmin -u root password
             New password:
             Confirm new password:
  之后用
  # bin/mysql -u root -h localhost -p
             就可以连接上mysql了
      4.5关于在数据库中输出中文
  要在mysql中插入中文数据,有可能会出错
  类似:ERROR 1366 (HY000): Incorrect string value: '\xE6\x89\x80' for column 'name' at row 1

               解决方法
  在建表时在最后加上 default charset=utf8
  e.g
  create table person(
  name varchar(10),sex varchar(10)
  )default charset=utf8

  Query OK, 0 rows affected (0.11 sec)
               insert into person values('张三','男');
               Query OK, 1 row affected (0.00 sec)


      5.安装PHP
   5.1安装JPEG插件
  $ tar xzf jpegsrc.v7.tar.gz
                $ cd jpeg-7/
                $ ./configure --prefix=/app/jpeg-7 --enable-shared --enable-static
  $ mm
   5.2安装zlib
  # tar zxf zlib-1.2.8.tar.gz
                # cd zlib-1.2.8/
                # ./configure --prefix=/app/zlib-1.2.8
  $ mm
         5.3安装libpng
  # tar zxf libpng-1.6.6.tar.gz
                # cd libpng-1.6.6/
                # ./configure --prefix=/app/libpng-1.6.6
  $ mm
  5.4安装字体引擎freetype
  # tar xjf freetype-2.4.7.tar.bz2
                # cd freetype-2.4.7/
                # ./configure --prefix=/app/freetype-2.4.7
                $ mm                              
                此处安装的时候有提示错误
  rmdir: 删除 "/app/freetype-2.4.7/include/freetype2/freetype/internal" 失败: 没有那个文件或目录
                make: 错误 1 (忽略)
                貌似不要紧
  5.5安装GD库

  # tar zxf libgd-2.1.0.tar.gz
                # cd libgd-2.1.0/
                # ./configure --prefix=/app/libgd-2.1.0 --with-jpeg=/app/jpeg-7 --with-png=/app/libpng-1.6.6 --with-freetype=/app/freetype-2.4.7
                # mm
         5.6安装PHP
              # tar jxf php-5.5.5.tar.bz2
                # cd php-5.5.5/
                # ./configure --prefix=/app/php-5.5.5 --with-apxs2=/app/httpd-2.4.6/bin/apxs --with-mysql=/app/mysql-5.6.13 --with-gd=/app            /libgd-2.1.0 --with-jpeg-dir=/app/jpeg-7 --with-png-dir=/app/libpng-1.6.6 --with-freetype-dir=/app/freetype-2.4.7 --enable-mbstring
  出错:configure: error: xml2-config not found. Please check your libxml2 installation.
  查看下帮助
  # ./configure --help | grep libxml
            --disable-libxml      Disable LIBXML support
            --with-libxml-dir=DIR   LIBXML: libxml2 install prefix
            可知需要指定libxml的路径
  先看下本机主了没有

  # rpm -ql libxml
             package libxml is not installed
             那就装吧

  # yum install libxml2
  # yum install libxml2-devel
  很快就装好了
   再次执行# ./configure --prefix=/app/php-5.5.5 --with-apxs2=/app/httpd-2.4.6/bin/apxs --with-mysql=/app/mysql-5.6.13 --with-gd=/ap/libgd-2.1.0 --with-jpeg-dir=/app/jpeg-7 --with-png-dir=/app/libpng-1.6.6 --with-freetype-dir=/app/freetype-2.4.7 --enable-mbstring
   这回就成功了   
  之后
  # mm
             这回又报错了
  /home/quincy/lamp/php-5.5.5/ext/gd/gd.c:57:22: 错误:X11/xpm.h:没有那个文件或目录
            继续查看下帮助
            # ./configure --help |grep xpm
            --with-xpm-dir=DIR      GD: Set the path to libXpm install prefix
  查看下机子上有无此文件
  # rpm -ql libXpm
            package xpm is not installed
            那就装吧
  # yum install libXpm         

  # yum install libXpm-devel
  一般缺文件都是没装上XX-devel包         
            装好之后 重新# mm
  又有新的错误了
  /home/quincy/lamp/php-5.5.5/ext/gd/gd.c:1330: undefined reference to `XpmLibraryVersion'
            既然undefined了,那就需要明确指定libXpm的路径
  先查看libXpm的路径

  # rpm -ql libXpm
  /usr/lib/libXpm.so.4
            /usr/lib/libXpm.so.4.11.0
            /usr/share/doc/libXpm-3.5.10
            /usr/share/doc/libXpm-3.5.10/AUTHORS      
            /usr/share/doc/libXpm-3.5.10/COPYING
            /usr/share/doc/libXpm-3.5.10/ChangeLog
  libXpm的路径在/usr/lib下
            此时需要重新configure下,在原来的基础上要加上 --with-xpm-dir=/usr/lib

  # ./configure --prefix=/app/php-5.5.5 --with-apxs2=/app/httpd-2.4.6/bin/apxs --with-mysql=/app/mysql-5.6.13 --with-gd=/app/libgd-2.1.0 --with-jpeg-dir=/app/jpeg-7 --with-png-dir=/app/libpng-1.6.6 --with-freetype-dir=/app/freetype-2.4.7   --enable-mbstring--with-xpm-dir=/usr/lib
  之后
  # mm
  现在就安装成功了
       5.7配置
  将当前目录下的php.ini-production复制到安装php的目录下
  # cp php.ini-production/app/php-5.5.5/php.ini
  编译php.ini将将short_open_tag = Off 改为short_open_tag = On
            # vim /app/php-5.5.5/php.ini
            short_open_tag = On
            编辑apache的配置文件httpd.conf
  # vim /app/httpd-2.4.6/conf/httpd.conf
            找到LoadModule php5_module      modules/libphp5.so
  添加以下行:
            AddType application/x-httpd-php .php
            DirectoryIndex index.html index.php
      6.测试

           在apache的htdocs下建立测试网页test.php
           # vim /app/httpd-2.4.6/htdocs/test.php
         <?
   ​    ​    ​   phpinfo();
    ​    ​    ​?>
         启动apache服务
           ​# service apachectl start
         访问网页
           本机ip/test.php
           看到下面画面就说明lamp配置成功了

           

  

  


         版权声明:本文为博主原创文章,未经博主允许不得转载。
页: [1]
查看完整版本: CentOS配置LAMP