新葡亰496net 新葡亰编程 Linux服务器开发环境搭建-Nginx+PHP+MongoDB

Linux服务器开发环境搭建-Nginx+PHP+MongoDB

编译安装PHP7 Mongdb扩展

配置基本环境:

所有软件的版本一直会升级,注意自己当时的版本是不是已经更新了。

#先安装一个依赖库yum -y install openldap-develwget
/home/server/php7/bin/phpize
#根据自己编译的PHP环境而定./configure
–with-php-config=/home/server/php7/bin/php-config make && make
install#如果成功,生成一个mongodb.so扩展在lib/php/extensions/no-debug-non-zts-20151012/修改php.ini配置extension=mongodb.so

 

首先装centos7

以前版本用的是mongo.so扩展,老的php-mongodb
api在PHP7已经不支持了,至少目前不支持。最新支持PHP7的mongodb 编译后
仅支持新版API

vi /etc/profile, 添加alias ll=’ls -al’; source /etc/profile

如果你忘了设置swap分区,下面的文章可以教你怎么补一个上去:

GITHUB:

 

//www.jb51.net/os/201409/338170.html

mkdir -p /home/download

装好centos7后默认是不能上网的

PHP官方:
[已废弃,目前只支持到PHP5.9999]

mkdir -p /home/server

cd /etc/sysconfig/network-scripts/

API手册:

mkdir -p /home/workspace

找到形如ifcfg-enp0s3的文件,修改onboot=yes

Mongodb API 操作

 

然后

初始化Mongodb连接

 

service network restart
$manager = new MongoDB/Driver/Manager("mongodb://127.0.0.1:27017"); var_dump;object(MongoDB/Driver/Manager)#1  { ["request_id"]=> int ["uri"]=> string "mongodb://localhost:27017" ["cluster"]=> array { ["mode"]=> string "direct" ["state"]=> string "born" ["request_id"]=> int ["sockettimeoutms"]=> int ["last_reconnect"]=> int ["uri"]=> string "mongodb://localhost:27017" ["requires_auth"]=> int ["nodes"]=> array ["max_bson_size"]=> int ["max_msg_size"]=> int ["sec_latency_ms"]=> int ["peers"]=> array { } ["replSet"]=> NULL }}
  1. 安装Nginx

安装apache2 (centos里叫httpd)

CURL操作

 

yum install httpd
$bulk = new MongoDB/Driver/BulkWrite;$bulk->delete;$bulk->insert;$bulk->insert;$bulk->insert(['_id' => 3, 'hello' => 'world']);$bulk->update(['_id' => 3], ['$set' => ['hello' => 'earth']]);$bulk->insert(['_id' => 4, 'hello' => 'pluto']);$bulk->update(['_id' => 4], ['$set' => ['hello' => 'moon']]);$bulk->insert;$bulk->insert;$bulk->insert;$manager = new MongoDB/Driver/Manager('mongodb://localhost:27017');$writeConcern = new MongoDB/Driver/WriteConcern(MongoDB/Driver/WriteConcern::MAJORITY, 1000);try { $result = $manager->executeBulkWrite('db.collection', $bulk, $writeConcern);} catch (MongoDB/Driver/Exception/BulkWriteException $e) { $result = $e->getWriteResult(); // Check if the write concern could not be fulfilled if ($writeConcernError = $result->getWriteConcernError: %s/n", $writeConcernError->getMessage(), $writeConcernError->getCode(), var_export($writeConcernError->getInfo; } // Check if any write operations did not complete at all foreach ($result->getWriteErrors {printf("Operation#%d: %s /n", $writeError->getIndex(), $writeError->getMessage(), $writeError->getCode; }} catch (MongoDB/Driver/Exception/Exception $e){ printf("Other error: %s/n", $e->getMessage; exit;}printf("Inserted %d document/n", $result->getInsertedCount;printf("Updated %d document/n", $result->getModifiedCount;

cd /home/download;

启动apache2

查询

wget

service httpd start
$filter = array();$options = array( /* Only return the following fields in the matching documents */ "projection" => array("title" => 1,"article" => 1, ), "sort" => array, "modifiers" => array('$comment' => "This is a query comment",'$maxTimeMS' => 100, ),);$query = new MongoDB/Driver/Query;$manager = new MongoDB/Driver/Manager("mongodb://localhost:27017");$readPreference = new MongoDB/Driver/ReadPreference(MongoDB/Driver/ReadPreference::RP_PRIMARY);$cursor = $manager->executeQuery("databaseName.collectionName", $query, $readPreference);foreach { var_dump;}

 

看看生效了没

以上内容是小编给大家分享的PHP7之Mongodb API使用详解,希望大家喜欢。

tar zxvf nginx-1.0.5.tar.gz;

curl http://localhost

cd /home/download/nginx-1.0.5;

设置开机自动运行

./configure –prefix=/home/server/nginx-1.0.5;

chkconfig httpd on

 

安装php7

make;

首先要更新源

make install;

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

ln -s /home/server/nginx-1.0.5/  /home/nginx

cd /home/nginx;

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

vi /etc/profile, 添加alias ngx=’/home/nginx/sbin/nginx’, source
/etc/profile

然后yum安装

 

yum install php70w

此时即可使用ngx -t 和ngx -s reload启动和重新加载nginx, 利用pkill
nginx停止nginx

重启apache

 

service httpd restart

注:如果出现./configure: error: the HTTP rewrite module requires the
PCRE library.则执行下列脚本:

看下phpinfo

 

vi /var/www/html/info.php
<?php phpinfo(); ?>

wget
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.12.tar.gz 

访问

 

看到php7.0.x信息就OK啦

tar -zvxf pcre-8.12.tar.gz ; cd pcre-8.12

安装mysql5.7

 

更新源先

./configure

rpm -ivh http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm

 

安装

make; make install

yum install mysql-community-server

 

mysql5.7初始密码不再是空,会在shell输出里告诉你密码文件地址,一般在~/.mysql_secret下

 

如果这个文件不幸没有的话,也不是没有办法,按下文操作:

 

如果要安装purge模块

设置开机启动:

 

chkconfig mysqld on

cd /home/download

安装php7的mysql扩展

wget

yum install php70w-mysql

tar zxvf ngx_cache_purge-1.3.tar.gz

重启apache2生效

./configure –prefix=/home/server/nginx-1.0.5
–add-module=/home/download/ngx_cache_purge-1.3
 –with-http_stub_status_module

安装mongodb最新版

 

mongodb官网的说明非常详细,照做即可:

 

 

安装php7的mongo扩展

  1. 安装PHP

先要装一堆东西

 

yum install php-pear
yum install php-devel
yum -y install gcc
yum install openssl openssl-devel
pecl channel-update pecl.php.net

cd /home/download;

然后通过pecl装php7的mongodb扩展

 

pecl install mongo

wget

 

pecl install mongodb

 tar zxvf php-5.3.6.tar.gz;

mongo是老版本,现在不会再升级了,但很多历史代码都在用。mongodb是新版的扩展,官方推荐。

 

不要忘了php.ini加上

cd php-5.3.6; ./configure –prefix=/home/server/php-5.3.6 –enable-fpm
–enable-mbstring 

extension=mongo.so 或 extension=mongodb.so 并且重启apache2

 

安装redis一套

标签:

相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图