CentOS7/RHEL7上源码搭建LAMP

很早就想写了,但一直没空整理,今天整理一下,源码搭建LAMP环境,这里的M指的是Mariadb。

要想编译安装,需先确保系统具有GCC开发环境,yum install -y gcc

  • 首先安装zlib,openssl,libevent这几个在之后大多数包编译时会用到:
    wget http://zlib.net/zlib-1.2.8.tar.gz
    tar zxf zlib-1.2.8.tar.gz -C /usr/local/src/
    cd /usr/local/src/zlib-1.2.8/
    CFLAGS="-fPIC -O3" ./configure --shared --64
    make -j `cat /proc/cpuinfo | grep processor | wc -l`;make install
    chcon -R -u system_u /usr/local/lib/libz.so*
    cd
    wget https://www.openssl.org/source/openssl-1.0.2d.tar.gz
    tar zxf openssl-1.0.2d.tar.gz -C /usr/local/src/
    cd /usr/local/src/openssl-1.0.2d/
    CFLAGS="-fPIC -O3" ./config --prefix=/usr/local/openssl --shared
    make -j `cat /proc/cpuinfo | grep processor | wc -l`;make install
    ln -s /usr/local/openssl/lib/* /usr/local/lib/
    ln -s /usr/local/openssl/lib/pkgconfig/* /usr/local/lib/pkgconfig/
    ln -s /usr/local/openssl/include/openssl/ /usr/local/include/
    echo /usr/local/lib >> /etc/ld.so.conf.d/complie.conf
    cd
    wget https://sourceforge.net/projects/levent/files/libevent/libevent-2.0/libevent-2.0.22-stable.tar.gz
    tar zxf libevent-2.0.22-stable.tar.gz -C /usr/local/src/
    cd /usr/local/src/libevent-2.0.22-stable/
    CPPFLAGS=-I/usr/local/openssl/include/ CFLAGS="-fPIC -O3" ./configure
    make -j `cat /proc/cpuinfo | grep processor | wc -l`;make install
  • 安装PCRE相关:
    cd
    wget http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gz
    tar zxf bzip2-1.0.6.tar.gz -C /usr/local/src/
    cd /usr/local/src/bzip2-1.0.6/
    sed -i 's/CC=gcc/CC=gcc\ -fPIC\ -O3/g' Makefile
    make -j `cat /proc/cpuinfo | grep processor | wc -l`;make install
    yum install -y ncurses-devel
    cd
    wget ftp://ftp.cwru.edu/pub/bash/readline-6.3.tar.gz
    tar zxf readline-6.3.tar.gz -C /usr/local/src/
    cd /usr/local/src/readline-6.3/
    CFLAGS="-fPIC -O3" ./configure --enable-multibyte --with-curses
    make SHLIB_XLDFLAGS=-lncurses;make install

    #系统开机时,lvm服务会调用Readline库,需特别注意
    ldd /usr/local/lib/libreadline.so.6
    chcon -R -u system_u /usr/local/lib/libreadline.so*
    ls -Z /usr/local/lib/libreadline.so.6
    cd
    wget http://thrysoee.dk/editline/libedit-20150325-3.1.tar.gz
    tar zxf libedit-20150325-3.1.tar.gz -C /usr/local/src/
    cd /usr/local/src/libedit-20150325-3.1/
    CFLAGS="-fPIC -O3" ./configure --enable-widec
    make -j `cat /proc/cpuinfo | grep processor | wc -l`;make install
    cd
    wget http://ncu.dl.sourceforge.net/project/pcre/pcre/8.37/pcre-8.37.tar.gz
    tar zxf pcre-8.37.tar.gz -C /usr/local/src/
    cd /usr/local/src/pcre-8.37/
    CFLAGS="-fPIC -O3" ./configure --enable-utf --enable-pcregrep-libz --enable-pcregrep-libbz2 --enable-pcretest-libreadline --enable-pcre16 --enable-pcre32 --enable-jit
    make -j `cat /proc/cpuinfo | grep processor | wc -l`;make install
    chcon -R -u system_u /usr/local/lib/libpcre*
  • 安装Mariadb:
    #Mariadb/Mysql编译需Cmake支持
    cd
    wget http://www.cmake.org/files/v3.3/cmake-3.3.1.tar.gz
    tar zxf cmake-3.3.1.tar.gz -C /usr/local/src/
    cd /usr/local/src/cmake-3.3.1/
    ./configure
    gmake;gmake install
    cd
    wget http://ftp.gnu.org/gnu/bison/bison-3.0.tar.xz
    tar Jxf bison-3.0.tar.xz -C /usr/local/src/
    cd /usr/local/src/bison-3.0/
    CFLAGS="-fPIC -O3" ./configure
    make -j `cat /proc/cpuinfo | grep processor | wc -l`;make install
    cd
    wget https://github.com/jemalloc/jemalloc/releases/download/3.6.0/jemalloc-3.6.0.tar.bz2
    tar jxf jemalloc-3.6.0.tar.bz2 -C /usr/local/src/
    cd /usr/local/src/jemalloc-3.6.0/
    CFLAGS="-fPIC -O3" ./configure
    make -j `cat /proc/cpuinfo | grep processor | wc -l`;make install
    cd
    wget http://sfo1.mirrors.digitalocean.com/mariadb/mariadb-10.0.19/source/mariadb-10.0.19.tar.gz
    tar zxf mariadb-10.0.21.tar.gz -C /usr/local/src/
    cd /usr/local/src/mariadb-10.0.21/
    groupadd -g 200 mariadb
    useradd -u 200 -g mariadb -s /sbin/nologin -d /var/lib/mariadb -M mariadb
    cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mariadb -DMYSQL_DATADIR=/var/lib/mariadb -DMYSQL_UNIX_ADDR=/var/lib/mariadb/mysql.sock -DMYSQL_USER=mariadb -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_READLINE=1 -DWITH_EMBEDDED_SERVER=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DWITH_SSL=/usr/local/openssl/ -DWITH_ZLIB=/usr/local/
    make -j `cat /proc/cpuinfo | grep processor | wc -l`;make install

    #将Mariadb设置为systemd系统服务
    cp packaging/rpm-oel/mysql-systemd-start /usr/local/mariadb/bin/
    sed -i 's/user=mysql/user=mariadb/g' /usr/local/mariadb/bin/mysql-systemd-start
    sed -i 's/\/usr\/bin/\/usr\/local\/mariadb\/bin/g' /usr/local/mariadb/bin/mysql-systemd-start
    sed -i 's/-omysql/-omariadb/g' /usr/local/mariadb/bin/mysql-systemd-start
    sed -i 's/-gmysql/-gmariadb/g' /usr/local/mariadb/bin/mysql-systemd-start
    sed -i 's/\/var\/lib\/mysql/\/var\/lib\/mariadb/g' /usr/local/mariadb/bin/mysql-systemd-start
    sed -i 's/mysql:mysql/mariadb:mariadb/g' /usr/local/mariadb/bin/mysql-systemd-start
    sed -i 's/\/var\/log\/mysqld.log/\/var\/log\/mariadb\/mariadb.log/g' /usr/local/mariadb/bin/mysql-systemd-start
    sed -i 's/mysqladmin/\/usr\/local\/mariadb\/bin\/mysqladmin/g' /usr/local/mariadb/bin/mysql-systemd-start
    chmod 755 /usr/local/mariadb/bin/mysql-systemd-start
    cp packaging/rpm-oel/mysqld.service /usr/lib/systemd/system/mysqld.service
    sed -i 's/Alias=mysql/Alias=mysqld/g' /usr/lib/systemd/system/mysqld.service
    sed -i 's/User=mysql/User=mariadb/g' /usr/lib/systemd/system/mysqld.service
    sed -i 's/Group=mysql/Group=mariadb/g' /usr/lib/systemd/system/mysqld.service
    sed -i 's/\/usr\/bin/\/usr\/local\/mariadb\/bin/g' /usr/lib/systemd/system/mysqld.service

    #若是7之前系统可这样添加为系统服务
    cp /usr/local/mariadb/support-files/mysql.server /etc/init.d/mysqld
    chmod +x /etc/init.d/mysqld
    chkconfig --add mysqld
    chkconfig --level 35 mysqld on

    #初始化并启动Mariadb:
    cp /usr/local/mariadb/support-files/my-medium.cnf /usr/local/mariadb/my.cnf
    mkdir -p /var/lib/mariadb
    mkdir -p /var/log/mariadb
    chown -R mariadb:mariadb /var/lib/mariadb/
    chown -R mariadb:mariadb /var/log/mariadb/
    cd /usr/local/mariadb/
    ./scripts/mysql_install_db --datadir=/var/lib/mariadb --user=mariadb
    chcon -R -u system_u -t mysqld_db_t /var/lib/mariadb/
    chcon -R -u system_u /usr/local/mariadb/lib/*
    systemctl enable mysqld
    systemctl start mysqld

    #可选,再执行安全初始
    cd bin/
    ./mysql_secure_installation
    echo '/usr/local/mariadb/lib/' >> /etc/ld.so.conf.d/comp.conf
  • 安装Python,后面软件编译会用到:
    #需要LibX11库支持,可源码编译安装,依赖较多,这里就不贴上来了,也可直接yum安装上
    yum install -y libX11-devel
    cd
    wget http://prdownloads.sourceforge.net/tcl/tcl8.6.4-src.tar.gz
    tar zxf tcl8.6.4-src.tar.gz -C /usr/local/src/
    cd /usr/local/src/tcl8.6.4/unix
    CFLAGS="-fPIC -O3" ./configure --enable-64bit
    make -j `cat /proc/cpuinfo | grep processor | wc -l`;make install
    cd
    wget http://prdownloads.sourceforge.net/tcl/tk8.6.4-src.tar.gz
    tar zxf tk8.6.4-src.tar.gz -C /usr/local/src/
    cd /usr/local/src/tk8.6.4/unix/
    CFLAGS="-fPIC -O3" ./configure --enable-64bit
    make -j `cat /proc/cpuinfo | grep processor | wc -l`;make install
    cd
    wget https://www.python.org/ftp/python/3.4.3/Python-3.4.3.tar.xz
    tar Jxf Python-3.4.3.tar.xz -C /usr/local/src/
    cd /usr/local/src/Python-3.4.3/
    CFLAGS="-fPIC -O3" ./configure --prefix=/usr/local/Python --with-tcltk-includes='-I /usr/local/include' --with-tcltk-libs='-I /usr/local/lib' --enable-shared --enable-ipv6
    make -j `cat /proc/cpuinfo | grep processor | wc -l`;make install
    ln -s /usr/local/Python/bin/python3 /usr/local/bin/python
    ln -s /usr/local/Python/lib/libpython3.4m.so.1.0 /usr/local/lib/
  • 安装GD库相关:
    #JPEG
    cd
    wget http://www.ijg.org/files/jpegsrc.v9a.tar.gz
    tar zxf jpegsrc.v9a.tar.gz -C /usr/local/src/
    cd /usr/local/src/jpeg-9a/
    mkdir -p /usr/local/jpeg9
    mkdir -p /usr/local/jpeg9/bin
    mkdir -p /usr/local/jpeg9/lib
    mkdir -p /usr/local/jpeg9/include
    mkdir -p /usr/local/jpeg9/man
    mkdir -p /usr/local/jpeg9/man1
    mkdir -p /usr/local/jpeg9/man/man1
    CFLAGS="-fPIC -O3" ./configure --prefix=/usr/local/jpeg9/ --enable-shared --enable-static
    make -j `cat /proc/cpuinfo | grep processor | wc -l`;make install

    #PNG
    cd
    wget http://ncu.dl.sourceforge.net/project/libpng/libpng16/1.6.17/libpng-1.6.17.tar.xz
    tar Jxf libpng-1.6.17.tar.xz -C /usr/local/src/
    cd /usr/local/src/libpng-1.6.17/
    CFLAGS="-fPIC -O3" ./configure --with-zlib-prefix=/usr/local/
    make -j `cat /proc/cpuinfo | grep processor | wc -l`;make install

    #ICU
    cd
    wget http://download.icu-project.org/files/icu4c/55.1/icu4c-55_1-src.tgz
    tar zxf icu4c-55_1-src.tgz -C /usr/local/src/
    cd /usr/local/src/icu/source/
    CXXFLAGS=--std=c++0x CFLAGS="-fPIC -O3" ./configure --enable-64bit-libs
    make -j `cat /proc/cpuinfo | grep processor | wc -l`;make install

    #FreeType
    cd
    wget http://download.savannah.gnu.org/releases/freetype/freetype-2.5.5.tar.gz
    tar zxf freetype-2.5.5.tar.gz -C /usr/local/src/
    cd /usr/local/src/freetype-2.5.5/
    PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/ CFLAGS="-fPIC -O3" ./configure --prefix=/usr/local/freetype --with-zlib=yes --with-bzip2=yes --with-png=yes --enable-shared --enable-static
    make -j `cat /proc/cpuinfo | grep processor | wc -l`;make install

    #libXpm
    cd
    wget ftp://ftp.x.org/pub/individual/util/util-macros-1.19.0.tar.bz2
    tar jxf util-macros-1.19.0.tar.bz2 -C /usr/local/src/
    cd /usr/local/src/util-macros-1.19.0/
    ./configure
    make -j `cat /proc/cpuinfo | grep processor | wc -l`;make install
    cd
    wget http://ftp.x.org/pub/individual/lib/libXpm-3.5.11.tar.gz
    tar zxf libXpm-3.5.11.tar.gz -C /usr/local/src/
    cd /usr/local/src/libXpm-3.5.11/
    CFLAGS="-fPIC -O3" PKG_CONFIG_PATH=/usr/local/share/pkgconfig/ ./configure
    #vim Makefile.am "ACLOCAL_AMFLAGS = -I m4 -I /usr/local/share/aclocal"
    make -j `cat /proc/cpuinfo | grep processor | wc -l`;make install

    #安装libXpm时,7之前系统编译时会提示需要automake1.14和gettest支持,可如下安装:
    cd
    wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz
    tar zxf autoconf-2.69.tar.gz -C /usr/local/src/
    cd /usr/local/src/autoconf-2.69/
    CFLAGS="-fPIC -O3" ./configure
    make -j `cat /proc/cpuinfo | grep processor | wc -l`;make install
    cd
    wget http://ftp.gnu.org/gnu/automake/automake-1.14.tar.gz
    tar zxf automake-1.14.tar.gz -C /usr/local/src/
    cd /usr/local/src/automake-1.14/
    CFLAGS="-fPIC -O3" ./configure
    make -j `cat /proc/cpuinfo | grep processor | wc -l`;make install
    cd
    wget http://ftp.gnu.org/pub/gnu/gettext/gettext-0.19.5.1.tar.gz
    tar zxf gettext-0.19.5.1.tar.gz -C /usr/local/src/
    cd /usr/local/src/gettext-0.19.5.1/
    CFLAGS="-fPIC -O3" ./configure
    make -j `cat /proc/cpuinfo | grep processor | wc -l`;make install

    #libIconv
    cd
    wget http://ncu.dl.sourceforge.net/project/expat/expat/2.1.0/expat-2.1.0.tar.gz
    tar zxf expat-2.1.0.tar.gz -C /usr/local/src/
    cd /usr/local/src/expat-2.1.0/
    CFLAGS="-fPIC -O3" ./configure
    make -j `cat /proc/cpuinfo | grep processor | wc -l`;make install
    cd
    wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
    tar zxf libiconv-1.14.tar.gz -C /usr/local/src/
    cd /usr/local/src/libiconv-1.14/
    CFLAGS="-fPIC -O3" ./configure

    #若提示Error: ./stdio.h:1010:1: error: ‘gets’ undeclared here,可
    sed -i '/gets is a security hole/d' srclib/stdio.h
    make -j `cat /proc/cpuinfo | grep processor | wc -l`;make install

    #FontConfig
    cd
    wget ftp://xmlsoft.org/libxml2/libxml2-2.9.2.tar.gz
    tar zxf libxml2-2.9.2.tar.gz -C /usr/local/src/
    cd /usr/local/src/libxml2-2.9.2/
    mkdir -p /usr/local/libxml2
    CFLAGS="-fPIC -O3" ./configure --prefix=/usr/local/libxml2/ --with-zlib=/usr/local --with-python=/usr/local/Python/ --with-ftp --with-html --with-http --with-icu --with-legacy --with-reader --with-regexps --with-sax1 --with-schemas --with-modules --with-iconv=/usr/local/ --with-readline=/usr/local/ --with-zlib=/usr/local/
    make -j `cat /proc/cpuinfo | grep processor | wc -l`;make install
    ldconfig
    cd
    wget http://www.freedesktop.org/software/fontconfig/release/fontconfig-2.11.1.tar.bz2
    tar jxf fontconfig-2.11.1.tar.bz2 -C /usr/local/src/
    cd /usr/local/src/fontconfig-2.11.1/
    PKG_CONFIG_PATH=/usr/local/libxml2/lib/pkgconfig/:/usr/local/lib/pkgconfig/:/usr/local/freetype/lib/pkgconfig/ CFLAGS="-fPIC -O3" ./configure --enable-iconv --with-libiconv=/usr/local/ --with-libiconv-includes=/usr/local/include/ --with-libiconv-lib=/usr/local/lib/ --with-expat=/usr/local/ --with-expat-includes=/usr/local/include/ --with-expat-lib=/usr/local/lib/ --enable-libxml2
    make -j `cat /proc/cpuinfo | grep processor | wc -l`;make install

    #TIFF
    cd
    wget http://download.osgeo.org/libtiff/tiff-4.0.3.tar.gz
    tar zxf tiff-4.0.3.tar.gz -C /usr/local/src/
    cd /usr/local/src/tiff-4.0.3/
    CFLAGS="-fPIC -O3" ./configure --with-zlib-lib-dir=/usr/local/lib --with-jpeg-lib-dir=/usr/local/jpeg9/lib --with-jpeg-include-dir=/usr/local/jpeg9/include/
    make -j `cat /proc/cpuinfo | grep processor | wc -l`;make install

    #libVPX,注:libvpx需使用1.3.0版本,使用新版1.4.0时,GD库编译时会报错,新的功能其不识别
    cd
    wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
    tar zxf yasm-1.3.0.tar.gz -C /usr/local/src/
    cd /usr/local/src/yasm-1.3.0/
    CFLAGS="-fPIC -O3" ./configure
    make -j `cat /proc/cpuinfo | grep processor | wc -l`;make install
    cd
    wget http://storage.googleapis.com/downloads.webmproject.org/releases/webm/libvpx-v1.3.0.tar.bz2
    tar jxf libvpx-v1.3.0.tar.bz2 -C /usr/local/src/
    cd /usr/local/src/libvpx-v1.3.0/
    ./configure --enable-vp8 --enable-vp9 --enable-shared --enable-static --enable-webm-io
    make -j `cat /proc/cpuinfo | grep processor | wc -l`;make install

    #GD库
    cd
    wget https://bitbucket.org/libgd/gd-libgd/downloads/libgd-2.1.1.tar.xz
    tar Jxf libgd-2.1.1.tar.xz -C /usr/local/src/
    cd /usr/local/src/libgd-2.1.1/
    ldconfig
    CFLAGS="-fPIC -O3" ./configure --prefix=/usr/local/gd --with-zlib=/usr/local/ --with-jpeg=/usr/local/jpeg9/ --with-freetype=/usr/local/freetype/ --with-png=/usr/local/ --with-xpm=/usr/local/ --with-fontconfig=/usr/local/ --with-libiconv-prefix=/usr/local/ --with-tiff=/usr/local/ --with-vpx=/usr/local/
    make -j `cat /proc/cpuinfo | grep processor | wc -l`;make install
    libGD

留下评论

error: Content is protected !!