lionhg 发表于 2015-8-19 10:00:16

Linux下配置LAMP环境

  先准备相关软件,并确保服务器已经安装了gcc,gcc-c++,make三个软件,以便后续编译过程。
  首先安装,
  libxml2  ftp://xmlsoft.org/libxml2/
  下载最新版本(我的是2.9.1,并解压,然后进入解压后的目录,执行 ./configure --prefix=/usr/local/libxml2/
  然后make的时候,一直报错,大概看了下,应该是因为没有装python的编译器,因为我没接触过python,所以只能傻傻地yum install python*,安装了一大堆东西,make终于成功了,求大神告诉我python的编译器是什么。
  好,继续make install。
  接下来安装libmcrypt,我的版本libmcrypt-2.5.8.tar.gz
  libmcrypt  http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download
    先解压文件并进入安装目录,

     输入./configure --prefix=/usr/local/libmcrypt/
        make && make install
  然后进入libltdl目录,输入
      ./configure --enable-ltdl-install

        make && make install
    OK然后安装zlib (zlib-1.2.8.tar.gz)
    zlib  http://zlib.net/zlib-1.2.8.tar.gz

      ./configure   (因为zlib库会被很多其他库引用,所以建议不指定安装路径)
    make
    make install
    好了,下面安装libpng( libpng-1.6.9.tar.gz)

    libpng  ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng16/
    ./configure
   make prefix=/usr ZLIBINC=/usr/local/include ZLIBLIB=/usr/local/lib-f scripts/makefile.linux

    KO,下面安装jpeg库(jpegsrc.v9a.tar.gz)
    jpeg  http://www.ijg.org/files/jpegsrc.v9a.tar.gz
    mkdir /usr/local/jpeg9
  mkdir /usr/local/jpeg9/bin
  mkdir /usr/local/jpeg9/lib
  mkdir /usr/local/jpeg9/include
  mkdir -p /usr/local/jpeg9/man/man1
    ./configure --prefix=/usr/local/jpeg9/ --enable-shared --enable-static
  make
  make install
    好的,接下来安装freetype(freetype-2.5.2)
  freetype  http://download.savannah.gnu.org/releases/freetype/
    ./configure --prefix=/usr/local/freetype/
  make
  make install
    之后便是M4(m4-1.4.17)

    M4  ftp://ftp.gnu.org/gnu/m4/m4-latest.tar.gz
    ./configure
  make
  make install
    之后便是autoconf(autoconf-2.69 )
    autoconf  ftp://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz
    ./configure
  make
  make install
    OK接下来安装gd2(libgd-2.1.0.tar.gz)

    gd2  https://bitbucket.org/libgd/gd-libgd/downloads/libgd-2.1.0.tar.gz( 此网站被墙,需要代理,或者自己百度找其他人共享的)

     ./configure --prefix=/usr/local/gd2/ --with-jpeg=/usr/local/jpeg9/ --with-freetype=/usr/local/freetype/ --with-png=/usr/
  make

    make install  
    好了,各种准备工作终于做得差不多了,下面安装我们的主角Apache:
    Apache  http://apache.dataguru.cn//httpd/httpd-2.4.7.tar.gz

    ./configure --prefix=/usr/local/apache2/ --sysconfdir=/etc/httpd/ --with-included-apr --disable-userdir --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-static-support
    报错:configure: error: Bundled APR requested but not found at ./srclib/. Download and unpack the corresponding apr and apr-util packages to ./srclib/.
  于是下载:APR http://mirrors.cnnic.cn/apache//apr/apr-1.5.0.tar.gz 和apr-utilhttp://mirrors.cnnic.cn/apache//apr/apr-util-1.5.3.tar.gz并解压到 ./srclib/目录。

    在apr目录里执行:
    ./configure
  make
  make install
    在apr-util目录里执行
    ./configure--with-apr=/usr/local/apr/
  make
  make install
    然后返回Apache目录执行
    ./configure --prefix=/usr/local/apache2/ --sysconfdir=/etc/httpd/ --with-included-apr=/usr/local/apr/ --disable-userdir --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-static-support
  有蛋疼地报错,configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
  只能按照神的指示,到http://pcre.org/下载ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.34.tar.gz,然后解压

    ./configure
  make
  make install
    然后再进入apache目录,执行./configure --prefix=/usr/local/apache2/ --sysconfdir=/etc/httpd/ --with-included-apr=/usr/local/apr/ --disable-userdir --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-static-support,终于KO了。
    接着:
    make
  make install
    然后执行
     /usr/local/apache2/bin/apachectl start
  echo "/usr/local/apache2/bin/apachectl start" >> /etc/rc.d/rc.sysinit

    接下来下载
    ncurses  ftp://invisible-island.net/ncurses/ncurses.tar.gz

    ./configure --with-shared --without-debug --without-ada --enable-overwrite
  make
  make install
    之后便是MySQL
    MySQL  http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.16.tar.gz

    发现没有cmake,于是yum install cmake

    cmake .

    make
  make install
    cd /usr/local/mysql
  chown-R mysql .

    chgrp -R mysql .
  scripts/mysql_install_db--user=mysql
   chown -R root .
  chown -R mysql data
   bin/mysqld_safe --user=mysql &
  cp support-files/mysql.server /etc/init.d/mysql.server
  然后发现mysql启动不了,查看日志发现 Can't open the mysql.plugin table. Please runmysql_upgrade to create it.
  上网查找,发现是自己没配置好数据文件,于是
   vim /etc/my.cnf
  将下的datadir改成   datadir=/usr/local/mysql/data/
  OKmysqld可以启动了,下面用mysql客户端连接,又想死地提示: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
经过排查,发现应该在 /etc/my.cnf 下添加如下内容

    
  socket=/var/lib/mysql/mysql.sock
  成功解决。

  
    最后就剩PHP了:
    PHP  http://cn2.php.net/get/php-5.5.9.tar.bz2/from/this/mirror

     ./configure --prefix=/usr/local/php/ --with-config-file-path=/usr/local/php/etc/ --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql/ --with-libxml-dir=/usr/local/libxml2/ --with-jpeg-dir=/usr/local/jpeg9/ --with-freetype-dir=/usr/local/freetype/ --with-gd=/usr/local/gd2/ --with-mcrypt=/usr/local/libmcrypt/ --with-mysqli=/usr/local/mysql/bin/mysql_config --with-png-dir=/usr --with-zlib-dir=/usr/local/ --enable-soap --enable-mbstring=all --enable-sockets
  make
  make install

    又报错,error: X11/xpm.h: No such file or directory
  网上查找错误,尝试yum install libXpm* 重新配置
  ./configure --prefix=/usr/local/php/ --with-config-file-path=/usr/local/php/etc/ --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql/ --with-libxml-dir=/usr/local/libxml2/ --with-jpeg-dir=/usr/local/jpeg9/ --with-freetype-dir=/usr/local/freetype/ --with-gd=/usr/local/gd2/ --with-mcrypt=/usr/local/libmcrypt/ --with-mysqli=/usr/local/mysql/bin/mysql_config --with-png-dir=/usr --with-zlib-dir=/usr/local/ --with-xpm-dir=/usr/ --enable-soap --enable-mbstring=all --enable-sockets
  make && make install

    cp php.ini-production /usr/local/php/etc/php.ini
  echo "Addtype application/x-httpd-php .php .phtml" >> /etc/httpd/httpd.conf
  /usr/local/apache2/bin/apachectl restart

  
    终于完工了。
页: [1]
查看完整版本: Linux下配置LAMP环境