Home >Backend Development >PHP Tutorial >Detailed installation process of using mongodb with PHP under centOS

Detailed installation process of using mongodb with PHP under centOS

WBOY
WBOYOriginal
2016-07-29 09:12:051250browse

This article talks about the complete installation and configuration process of using mongodb under centOS.


Replace the yum source

We hope to install through yum, which is faster and faster, but the default yum environment of centOS does not have the content we need, so we need to actively change the yum source to the 163 source.

First get the 163 source:

<code><span># wget http</span>:<span>//mirrors.163.com/.help/<strong>CentOS6</strong>-Base-163.repo</span></code>

Then we back up our local yum:

<code><span>#mv</span> CentOS<span>-Base</span><span>.</span>repo CentOS<span>-Base</span><span>.</span>repo<span>.</span>bak</code>

Then change the downloaded 163 source to the local source:

<code><span>#mv</span> <strong>CentOS6</strong><span>-Base</span><span>-</span><span>163.</span>repo CentOS<span>-Base</span><span>.</span>repo</code>

Next, update the yum source:

<code><span>#yum clean all</span><span>#yum makecache</span><span>#yum update -y</span></code>

Like this The new yum source is configured.


Install mongodb database

Next we need to install the mongodb database under centOS.

<code><span>#yum instll mongodb</span></code>

Then install the server:

<code><span>#yum install mongodb-server</span></code>

Next start mongodb:

<code><span>#service mongod start</span></code>

Then enter mongo:

<code><span>#mongo</span></code>

Detailed installation process of using mongodb with PHP under centOS

If the above results appear, it means that mongodb is installed successfully.


Configure the php-mongo extension

or install it through yum:

<code><span>#yum</span> install php<span>-pecl</span><span>-mongo</span></code>

After successful installation, php_info() will display mongo:

Detailed installation process of using mongodb with PHP under centOS


Test mongodb

Test mongodb through php code to see if it can run normally:

<code><span><span><?php </span><span>$mongo</span> = <span>new</span> Mongo();
<span>$alldb</span> = <span>$mongo</span>->listDBs();<span>//获取所有数据库名称</span><span>echo</span><span>$alldb</span>;</span></span></code>

If it returns normally, it means that the php operation on mongodb is successful.

For the next specific addition, deletion, modification and query operations, you can refer to the API: official documentation

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces the detailed installation process of PHP using mongodb under centOS, including CentOS6 content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:php sorting functionNext article:php sorting function