Raspberry PI installation and configuration process
【slightly】
Installation process of Nginx, PHP and MongoDB
【slightly】
Install PHP’s MongoDB driver
Instructions are from here (driver installation) and here (phpize not found).
Run the following commands to install the PHP development environment and PEAR:
sudo apt-get install php5-dev
sudo apt-get install php-pear
Then, run the following command to detect PEAR installation (can be skipped):
pear version
pecl version
Check, install and compile MongoDB driver:
pecl search mongo
sudo pecl install mongo
After success, it will prompt the path of mongo.so and the method of modifying php.ini:
Build process completed successfully
Installing ‘/usr/lib/php5/20100525+lfs/mongo.so’
install ok: channel://pecl.php.net/mongo-1.4.5
configuration option “php_ini” is not set to php.ini location
You should add “extension=mongo.so” to php.ini
Under raspberry Pi, we still use nano to edit the file. There is no trace of mongodb in the php.ini file, so we have to add it ourselves:
Run the following command to open php.ini:
sudo nano /etc/php5/fpm/php.ini
Add the following at the end, then press CTRL+X, then press Y to save and exit:
…
[MongoDB]
; igame:Dec-24-2013: Add MongoDB extension.
extension=mongo.so
Run the following command to restart php-fpm:
sudo killall php5-fpm
sudo /etc/init.d/php5-fpm restart
Then, open the info.php page with your browser to check the results. Note that the root directory of Nginx is /usr/share/nginx/www. If you see the mongo part, you succeeded.
Test
Now write a simple page to test it out. Enter the command:
sudo nano /usr/share/nginx/www/testmongo.php
Then enter the following:
<?php
echo ‘PHP+MongoDB Test
‘;
try
{
$mongo = new Mongo(/*”localahost:27101″*/);
$blog = $mongo->blog;
$posts = $blog->posts;
$it = $posts->find();
if ($it->count() < 1)
{
$posts->insert(array(‘title’ => ‘Hello, MongoDB!’));
$posts->insert(array(‘title’ => ‘Hello, igame!’));
$posts->insert(array(‘title’ => ‘Hello, php!’));
$posts->insert(array(‘title’ => ‘Hello, Nginx!’));
}
else
{
Echo $it->count() . ‘ document(s) found.
‘;
foreach($it as $obj)
{
Echo “title: [” . $obj[“title”] . “]
“;
}
}
$mongo->close();
}
catch(MongoConnectionException $e)
{
die(‘Error in connection to MongoDB’);
}
catch(MongoException $e)
{
die(‘Error:’ . $e->getMessage());
}
?>
Save and exit. Open it with a browser to see the result.
Questions
Please let the dog search by yourself.