1.准备以下源码包
    apr-1.4.5.tar.gz
    apr-util-1.3.12.tar.gz
    pcre-8.10.zip
    libxml2-sources-2.9.2.tar.gz
    httpd-2.4.18.tar.gz
    mysql-5.0.22.tar.gz
    php-7.0.4.tar.gz

2.安装
    apr安装
        ./configure --prefix=/opt/LAMP/apr
        make&&make install

    apr-util安装
        ./configure --prefix=/opt/LAMP/apr-util --with-apr=/opt/LAMP/apr
        make&&make install

    pcre安装
        ./configure --prefix=/opt/LAMP/pcre
        make&&make install

    libxml2安装
        ./configure --prefix=/opt/LAMP/libxml2
        make&&make install

    apache安装
        ./configure --prefix=/opt/LAMP/apache2 --with-apr=/opt/LAMP/apr --with-apr-util=/opt/LAMP/apr-util --with-pcre=/opt/LAMP/pcre --with-libxml2=/opt/LAMP/libxml2 --enable-so --enable-cgi --enable-rewrite
        make&&make install

    ncurses安装
        apt-cache search ncurses
        apt-get install libncurses5-dev

    mysql安装
        ./configure --prefix=/opt/LAMP/mysql
        make&&make install

    php安装
        ./configure --prefix=/opt/LAMP/php --with-libxml-dir=/opt/LAMP/libxml2 --enable-mysqlnd --with-pdo-mysql=mysqlnd --with-apxs2=/opt/LAMP/apache2/bin/apxs --with-config-file-path=/opt/LAMP
        make&&make install

3.配置
    php配置
        cp php.ini-development /opt/LAMP/php.ini

    apache配置
        在httpd.conf中添加
        LoadModule php7_module modules/libphp7.so
        AddType application/x-httpd-php .php
        DirectoryIndex index.html index.php

4.测试

点击(此处)折叠或打开

  1. <?php
  2. try{
  3.         $dbh = new PDO('mysql:host=localhost;port=3306;dbname=xxx', 'xxx', 'xxx',array( PDO::ATTR_PERSISTENT => false));
  4.         $stmt = $dbh->prepare("SELECT xxx FROM xxx WHERE xxx=:xxx");
  5.         $stmt->execute(array(':xxx'=>'xxx'));
  6.         while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
  7.                 echo $row['xxx'];
  8.         }
  9. } catch (PDOException $e) {
  10.     print "Error!: " . $e->getMessage() . "
    "
    ;
  11.     die();
  12. }
  13. ?>



    
09-27 10:36