zoukankan      html  css  js  c++  java
  • apache+php连接数据库

    ######## 安装APACHE #############
    #安装apr
    /usr/src/apache+php/
    tar xf apr-1.5.2.tar.gz
    cd apr-1.5.2
    ./configure --prefix=/usr/local/apr
    make && make install

    #安装apr-util
    cd ..
    tar xf apr-util-1.5.4.tar.gz
    cd apr-util-1.5.4
    ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
    make && make install

    #安装httpd
    cd ..
    yum install pcre-devel zlib-devel openssl-devel -y
    tar xf httpd-2.4.25.tar.gz
    cd httpd-2.4.25
    ./configure --prefix=/usr/local/httpd --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --enable-so --enable-deflate --enable-expires --enable-headers --enable-ssl --enable-rewrite --enable-mpms-shared=all --with-mpm=prefork --enable-mods-shared=most
    make && make install
    #可通过./configure --help或结合http://httpd.apache.org/docs/2.4/progms/configure.html来了解各参数含义


    # vim /etc/profile 或者 vim ~/.bash_profile
    echo 'export PATH=/usr/local/httpd/bin:$PATH' >> /etc/profile
    . /etc/profile

    yum remove httpd* -y

    # vi /usr/local/httpd/conf/httpd.conf
    sed -i 's/#ServerName www.example.com:80/ServerName localhost:80/g' /usr/local/httpd/conf/httpd.conf
    apachectl start
    netstat -antp | grep httpd

    #启动文件
    ln -s /usr/local/httpd/bin/apachectl /etc/init.d/httpd
    echo -e "
    # chkconfig: - 85 15 # description: The Apache HTTP Server" >> /etc/init.d/httpd
    chkconfig --add httpd
    systemctl enable httpd
    /etc/init.d/httpd restart


    #查看所有模块
    ls /usr/local/httpd/modules/

    #查看加载模块
    apachectl -t -D DUMP_MODULES

    ######### 安装PHP ############
    #安装php:
    yum install libxml2 libxml2-devel -y
    tar xf php-5.6.30.tar.gz
    cd php-5.6.30
    ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/httpd/bin/apxs
    make && make install

    vi /usr/local/httpd/conf/httpd.conf
    DirectoryIndex index.php index.html
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps

    /etc/init.d/httpd restart

    #测试:
    vim /usr/local/httpd/htdocs/index.php
    <?php
    phpinfo();
    ?>

    #php安装mysql模块:
    yum -y install mysql-devel autoconf
    ln -s /usr/lib64/mysql /usr/lib/mysql ----64位系统
    cd /usr/src/apache+php/php-5.6.30/ext/mysql
    /usr/local/php/bin/phpize
    ./configure --with-php-config=/usr/local/php/bin/php-config --with-mysql=/usr
    make && make install

    让php加载安装好的外部模块:
    cp php解压缩路径/php.ini-production /usr/local/php/lib/php.ini
    vim /usr/local/php/lib/php.ini
    extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226"
    extension = "mysql.so"
    /etc/init.d/httpd restart


    #安装配置mysql(此处安装的是rpm):
    yum install mysql-server -y
    mysql
    mysql> grant all on *.* to root@192.168.18.240 identified by '123'; ##240为php的IP


    #连接mysql的测试页
    cd /usr/local/httpd/htdocs
    vim mysql.php
    <?php

    $conn = mysql_connect('192.168.18.241','root','123');

    if (!$conn)
    {

    die('Could not connect: ' . mysql_error());
    }

    else
    {
    echo "Connect Successfully!";
    }

    ?>


    #安装PHP的redis.so:
    yum install -y autoconf
    cd /tmp/phpredis-3.1.1RC1
    /usr/local/php/bin/phpize
    ./configure --with-php-config=/usr/local/php/bin/php-config
    make && make install

    #安装验证
    ls /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/redis.so

    #配置PHP 加载redis客户端
    cp php-5.6.30/php.ini-production /usr/local/php/lib/php.ini
    vim /usr/local/php/lib/php.ini
    extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226"
    extension = redis.so


    # 在redis中设置bind参数-->重启redis
    bind 127.0.0.1 192.168.18.134(本机ip)


    #通过网页phpinfo.php或者 /usr/local/php/bin/php -m 验证是否正确加载了redis模块
    测试页面
    <?php
    //连接本地的 Redis 服务
    $redis = new Redis();
    $redis->connect('127.0.0.1', 6379);

    $redis->auth('123456');

    echo "Connection to server sucessfully.</br>";

    //查看服务是否运行
    echo "Server is running: " . $redis->ping();
    ?>

  • 相关阅读:
    (转)样本方差的期望
    (转)Python 字典排序
    曝光补偿
    python判断字符串是否包含子字符串
    python requests接口测试 -----博客园串接口
    jmeter+ant+jenkins 搭建接口自动化测试
    TOMCAT闪退。cmd执行startup.bat保错:the CATALINA_HOME environment variable is not defined correctly
    selenium python自动化测试 ddt数据驱动
    jenkins到底如何拉取代码 如何部署的
    git 常用命令
  • 原文地址:https://www.cnblogs.com/Stephen-blog/p/10463486.html
Copyright © 2011-2022 走看看