天天看點

redhat下安裝LAMP架構

LAMP指的Linux、ApacheHTTP 伺服器,MySQL資料可 和PHP 的第一個字母,是用來建立web應用的一個平台。

一、 手工編譯安裝apache

1.将安裝apache需要用到的包,解壓到/opt目錄下

指令如下:

tar xzvf http-2.4.2.tar.gz -C /opt

tar xzvf apr-1.4.6.tar.gz -C /opt (支援Apache上層應用跨平台,提供底層接口庫)

tar xzvf apr-util-1.4.1.tar.gz -C /opt

安裝好之後可以在/opt目錄下看到解壓好的三個包

redhat下安裝LAMP架構

2.将解壓好的兩個apr檔案複制到/opt/hppd-2.4.2/srclib/目錄,分别取名apr、apr-util

cp -R apr-1.4.6/ /opt/httpd-2.4.2/srclib/apr

cp -R apr-util-1.4.1/ /opt/httpd-2.4.2/srclib/apr-util

redhat下安裝LAMP架構
  1. 安裝 gcc 、 gcc-c++ 、 make 、 pcre、pcre-devel 四個包

    (pcre : 一個Perl庫,支援正規表達式)

    redhat下安裝LAMP架構
    在安裝過程中會安裝8個包,當出現“complete”時,說明安裝成功!
    redhat下安裝LAMP架構

    4.切換到cd /opt/httpd-2.4.2 目錄下,

    輸入以下配置檔案進行配置

    ./configure \

    --prefix=/usr/local/apache \

    --enable-so \

    --enable-rewrite \

    --enable-mods-shared=most \

    --with-mpm=worker \

    --disable-cgid \

    --disable-cgi

    5.編譯成位元組碼檔案

    redhat下安裝LAMP架構

    6.過濾掉/usr/local/apache/bin/apachectl中的注釋檔案,并重定向到/etc/init.d/httpd下

    指令:grep -v "#" /usr/local/apache/bin/apachectl > /etc/init.d/httpd

    redhat下安裝LAMP架構
  2. 編輯/etc/init.d/httpd檔案,在檔案最前面插入下面的頭檔案資訊
    redhat下安裝LAMP架構
    8.給/etc/init.d/httpd添加可執行權限,指令chmod +x /etc/init.d/httpd
    redhat下安裝LAMP架構
  3. 将httpd服務設定為開機自啟動

    chkconfig --add httpd

    chkconfig --list httpd

    chkconfig --level 35 httpd on

    redhat下安裝LAMP架構
  4. 建立軟連接配接便于管理
    redhat下安裝LAMP架構

    編輯/etc/httpd.conf檔案,将Listen前面的注釋删除,并将ip改為本機ip位址,并注釋掉IPV6的ip,同時設定Servername,格式為:主機名.域名

    Listen:IPV4

    ServerName:主機名.域名

    redhat下安裝LAMP架構
    redhat下安裝LAMP架構
    11.重新開機httpd服務,并檢視服務資訊
    redhat下安裝LAMP架構
    12.關閉防火牆跟selinux,在與此台主機相連的另一台機器上測試服務是否成功
    redhat下安裝LAMP架構
    當輸入此主機的ip位址後,可以看到出現此時的頁面,說明Apache安裝成功!
    redhat下安裝LAMP架構
    二、 Mysql安裝
  5. 解壓mysql的安裝包到/opt目錄下
    redhat下安裝LAMP架構
  6. 确認安裝 cmake 、ncurses-devel(字元終端螢幕控制基本庫)、bison(文法分析器)、

    libaio-devel(支援同步I/O)的軟體包

    redhat下安裝LAMP架構

    3.切換到/opt/mysql-5.5.24下,輸入以下配置資訊:

    cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql

    -DMYSQL_UNIX_ADDR=/home/mysql/mysql.sock

    -DDEFAULT_CHARSET=utf8

    -DDEFAULT_COLLATION=utf8_general_ci

    -DWITH_EXTRA_CHARSETS=all

    -DWITH_MYISAM_STORAGE_ENGINE=1

    -DWITH_INNOBASE_STORAGE_ENGINE=1

    -DWITH_MEMORY_STORAGE_ENGINE=1

    -DWITH_READLINE=1

    -DENABLED_LOCAL_INFILE=1

    -DMYSQL_DATADIR=/home/mysql

    -DMYSQL_USER=mysql

    -DMYSQL_TCP_PORT=3306

  7. make && make install
    redhat下安裝LAMP架構
  8. 添加mysql使用者并加入到mysql組

    useradd -s /sbin/nologin mysql

    mkdir -p /usr/local/mysql

    redhat下安裝LAMP架構
    6.chown -R mysql.mysql /usr/local/mysql
    redhat下安裝LAMP架構
    7.設定開機時重新整理 export PATH=$PATH:/usr/local/mysql/bin/
    redhat下安裝LAMP架構

    8.複制以下資訊到/etc/下分别取名my.cnf和mysqld

    cp support-files/my-medium.cnf /etc/my.cnf

    redhat下安裝LAMP架構
    9.更改檔案權限并設定開機自啟動
    redhat下安裝LAMP架構

    10.初始化資料庫

    在目前目錄下,直接輸入以下資訊:

    /usr/local/mysql/scripts/mysql_install_db \

    --user=mysql \

    --ldata=/var/lib/mysql \

    --basedir=/usr/local/mysql \

    --datadir=/home/mysql

    redhat下安裝LAMP架構
  9. 直接建立軟連接配接

    ln -s /var/lib/mysql/mysql.sock /home/mysql/mysql.sock

    redhat下安裝LAMP架構

    12.編輯/etc/init.d/mysqld檔案

    将資料庫目錄設定為/usr/local/mysql 資料目錄設定為/home/mysql

    redhat下安裝LAMP架構

    13.開啟mysqld并檢視狀态

    使用service mysqld start指令開啟mysql服務

    redhat下安裝LAMP架構
    netstat -tnl 3306指令檢視端口資訊,此時可以看到mysql的3306端口已經開啟,此時我們得而mysql就已經安裝成功了!
    redhat下安裝LAMP架構
  10. 進入mysql
    redhat下安裝LAMP架構
    三、 PHP安裝
  11. 首先安裝GD庫和GD庫關聯程式,用來處理和生成圖檔

    直接輸入下面的指令進行安裝

    yum install \

    libjpeg-devel \

    libpng-devel \

    freetype-devel \

    zlib-devel \

    gettext-devel \

    libXpm-devel \

    libxml2-devel \

    fontconfig-devel \

    openssl-devel \

    bzip2-devel

    2.解壓安裝包到/opt下,

    tar xzvf gd-2.0.35.tar.gz -C /opt

    redhat下安裝LAMP架構
  12. 進入剛剛壓縮的檔案目錄下,進行配置

    ./configure --prefix=/usr/local/gd

    redhat下安裝LAMP架構
  13. 編譯make make install
  14. 解壓縮php安裝包到?opt目錄下

    tar xjvf /opt/lamp/php-5.4.5.tar.bz2 -C /opt

    5.輸入配置檔案

    ./configure \

    --prefix=/usr/local/php \

    --with-apxs2=/usr/local/apache/bin/apxs \

    --with-gd \

    --with-mysql=/usr/local/mysql \

    --with-config-file-path=/etc \

    --enable-sqlite-utf8 \

    --with-zlib-dir \

    --with-libxml-dir \

    --with-freetype-dir \

    --with-jpeg-dir \

    --with-png-dir \

    --with-ttf \

    --with-iconv \

    --with-openssl \

    --with-gettext \

    --enable-mbstring \

    --enable-gd-native-ttf \

    --enable-gd-jis-conv \

    --enable-static \

    --enable-zend-multibyte \

    --enable-inline-optimization \

    --enable-sockets \

    --enable-soap \

    --enable-ftp \

    --disable-ipv6

  15. 編譯make make install
  16. 讓apache 支援php ,

    更改配置檔案vim /usr/local/apache/conf/httpd.conf

    找到 AddType application/x-gzip .gz .tgz 在下面添加如下内容

    AddType application/x-httpd-php .php

    AddType application/x-httpd-php-source .phps

    檢查php5_module這個子產品是否存在

    LoadModule php5_module modules/libphp5.so

    redhat下安裝LAMP架構
  17. 調整首頁檔案設定

    DirectoryIndex index.php index.html

    redhat下安裝LAMP架構
    10.重新開機httpd服務
    redhat下安裝LAMP架構
    以上就是lamp架構的安裝過程。

轉載于:https://blog.51cto.com/13620954/2110265