lamp及php扩展

  • 准备

主机环境:centos6.5

lamp版本:httpd-2.4.25

           mysql-5.6.26

           php-7.2.13

  • 安装apache

安装包:httpd-2.4.25.tar.bz2

apr-1.4.5.tar.gz

apr-util-1.4.1.tar.gz

pcre-8.10.zip

    安装编译环境:

        # yum -y groupinstall "Server Platform Development" "Development tools"

    安装apr:

        # tar zxf apr-1.4.5.tar.gz

        # cd apr-1.4.5

        # ./configure --prefix=/usr/local/apr

        # make && make install

    安装apr-util:

        # tar zxf apr-util-1.4.1.tar.gz

        # cd apr-util-1.4.1

        # ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/

        #make && make install

    安装pcre:

        # unzip  pcre-8.10.zip

        # cd pcre-8.10

        # ./configure --prefix=/usr/local/pcre

        # make && make install

    安装apache:

        # tar jxf httpd-2.4.25.tar.bz2

        # cd httpd-2.4.25

   # ./configure --prefix=/usr/local/httpd --sysconfdir=/usr/local/httpd/etc/ --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre=/usr/local/pcre/ --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=all --enable-mpms-shared=all --with-mpm=prefork

(--enable-so --enable-ssl  #允许运行时加载DSO模块 # 启动ssl加密功能

--enable-cgi --enable-rewrite  # 启用cgi协议  #启用URL重写功能 

--with-zlib    :使用指定的zlib压缩库
--with-pcre    :使用指定的pcre库

--enable-modules=all   # 支持动态启用模块;all:所有,most:常用

--enable-mpms-shared=all  #编译并共享模块

--with-mpm=prefork  #指定使用的MPM的类型 {prefork|worker|event})

        # make && make install

        # vim /etc/profile.d/httpd.sh                    //添加环境变量

            export PATH=/usr/local/httpd/bin:$PATH

        # ln -sv /usr/local/httpd/include /usr/include/httpd  //导出头文件

        # vim /etc/man.config

MANPATH /usr/local/httpd/man              //导出man手册

        # cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd

        # chmod +x /etc/init.d/httpd

        # service httpd start

        # netstat -antp | grep httpd

tcp    0    0 :::80     :::*        LISTEN      19761/httpd

  • 安装PHP      php7.2没有mcrypt

安装依赖包:

# yum -y install openssl openssl-devel curl curl-devel libjpeg libjpeg-devel libpng  libpng-devel freetype freetype-devel pcre pcre-devel libxslt libxslt-devel bzip2 bzip2-devel

# tar zxf php-7.2.13.tar.gz

# cd php-7.2.13

#./configure \

--prefix=/usr/local/php7 \

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

--with-config-file-path=/usr/local/php7/etc \

--with-mysqli \

--with-pdo-mysql \

--with-freetype-dir \

--with-jpeg-dir \

--with-png-dir \

--with-zlib \

--with-libxml-dir \

--with-curl \

--with-gd \

--with-openssl \

--with-mhash \

--with-gettext \

--with-xsl --with-bz2 \

--enable-inline-optimization \         //优化线程

--enable-mysqlnd \

--enable-mbstring \

--enable-xml \

--enable-bcmath \

--enable-fpm \

--enable-sockets \

--enable-zip \

--enable-soap --enable-ftp \

        # make && make install

# cp /usr/src/php-7.2.13/php.ini-production /usr/local/php7/etc/php.ini

# vim /usr/local/httpd/etc/httpd.conf

  LoadModule php7_module        modules/libphp7.so  //已有

    AddType application/x-httpd-php .php     //添加

    DirectoryIndex  index.php index.html    //添加

# service httpd restart

测试apache连接php:

  # vim /usr/local/httpd/htdocs/index.php

      <?php

  echo phpinfo()

?>

  • 安装mysql

    # yum install -y ncurses-devel libaio-devel cmake

    # groupadd mysql

    # useradd -M -s /sbin/nologin mysql -g mysql

    # tar zxf mysql-5.6.26.tar.gz

    # cd mysql-5.6.26

    # cmake \

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

-DSYSCONFDIR=/etc \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DWITH_EXTRA_CHARSETS=all \

        # make && make install

        # chown -R mysql:mysql /usr/local/mysql/

        # cp /usr/src/mysql-5.6.26/support-files/my-default.cnf /etc/my.cnf

                   # vim /etc/my.cnf

                            basedir = /usr/local/mysql

datadir = /usr/local/mysql/data

socket = /var/lib/mysql/mysql.sock

        # /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

        # echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile

        # . /etc/profile

  # cp /usr/src/mysql-5.6.26/support-files/mysql.server /etc/init.d/mysqld

# chmod +x /etc/init.d/mysqld

# chkconfig --add mysqld

# service mysqld start

  测试php通过mysqili连接数据库:   添加mysql用户和密码

      <?php

        $link=new mysqli('localhost','root','hzk97106');

        if(!$link){

          echo"database error";

        }else{

          echo "connection successfully!";

        }

        $mysqli->close();

?>

  测试php通过pdo连接数据库

    <?php

       $link=new pdo('mysql:hosts=localhost','root','hzk97106');

       if(!$link){

           echo"database error";

       }else{

           echo "connection successfully!";

       }

       $mysqli->close();

?>

  • 安装mongodb并添加到php扩展

mongodb说明:https://docs.mongodb.com/ecosystem/drivers/php/

对于5.X来说需要的扩展文件是mongo.so文件,对应的下载链接:https://pecl.php.net/package/mongo

对于7.X版本需要生成的扩展文件是mongodb.so文件,对应的下载链接在这里:https://pecl.php.net/package/mongodb

安装包:mongodb-linux-x86_64-rhel62-4.0.2.tgz

        mongodb-1.4.2.tgz

# tar zxf mongodb-linux-x86_64-rhel62-4.0.2.tgz

# mv mongodb-linux-x86_64-rhel62-4.0.2 /usr/local/mongodb

# export PATH=/usr/local/mongodb/bin:$PATH

# cd /usr/local/mongodb/bin/

# mkdir /usr/local/mongodb/db

# touch /usr/local/mongodb/mongodb.log

# vim mongodb.conf

    dbpath=/usr/local/mongodb/db

logpath=/usr/local/mongodb/mongodb.log

port=27017

fork=true

        # /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/bin/mongodb.conf

        # echo "PATH=$PATH:/usr/local/mongodb/bin" >> /etc/profile

        # . /etc/profile

        # mongo

        # cd /usr/src

        # tar zxf mongodb-1.4.2.tgz

        # cd mongodb-1.4.2

        # /usr/local/php7/bin/phpize

                   # ./configure --with-php-config=/usr/local/php7/bin/php-config

                   # make && make install

        # vim /usr/local/php7/etc/php.ini

           extension=mongodb.so    //添加

        # service httpd restart

  • 安装redis并添加到php扩展

安装包:redis-3.2.1.tar.gz      redis-3.1.6.tgz

    下载地址:http://pecl.php.net/package/redis

    # tar zxf redis-3.2.1.tar.gz

    # mv redis-3.2.1 /usr/local/redis

# cd /usr/local/redis/

# make

# make install

# vim /usr/local/redis/redis.conf

      daemonize yes (no -> yes)

# /usr/local/bin/redis-server /usr/local/redis/redis.conf

# redis-cli         //使用客户端

#redis-cli shutdown     //关闭客户端

php扩展:

# tar zxf redis-3.1.6.tgz

# cd redis-3.1.6

# /usr/local/php7/bin/phpize

# ./configure --with-php-config=/usr/local/php7/bin/php-config

# make && make install

# vim /usr/local/php7/etc/php.ini

      extension=redis.so  //添加

# service httpd restart

    测试php通过Redis扩展连接数据库:

      <?php

        $redis = new Redis();

        $redis->connect('127.0.0.1',6379);

        $redis->set('name','hzk');

        echo $redis->get('name'); ?>    

posted @ 2019-03-15 09:31  诸城布拉德皮特  阅读(237)  评论(0编辑  收藏  举报