Install php mongodb extension centos 7
Pre-Flight Check Show
Step 1: Setup Environment, Install PHP Extension & Application Repository (PEAR) As a matter of best practice we’ll update our packages:
Then let’s install a compiler, the PHP Extension and Application Repository (PEAR), and PHP development tools:
Step 2: Installation with the PHP Extension Community Library (PECL) Now let’s install the MongoDB PHP driver (extension) with PECL:
Next you’ll be prompted regarding ‘MongoDB Enterprise Authentication’. If you’re not specifically using SASL (and already have it installed), then hit enter to continue (thus answering ‘no’): Build with Cyrus SASL (MongoDB Enterprise Authentication) support? [no] : Step 3:Configure PHP For a refresher on editing files with vim see: New User Tutorial: Overview of the Vim Text Editor
It is possible to place the following bit of code anywhere in the php.ini file. However, the most common location for extensions is in the Dynamic Extensions section. Find Dynamic Extensions and insert the following in that section:
Then exit and save the file with the command :wq . And now we’ll restart Apache:
Step 4: Verify the Extension is Available Now verify that the extension is available by using the following command:
Your result should be: mongo In order to use MongoDB in our PHP programs, we need to install php mongodb driver. It is a PHP extension that manages the connection to the MongoDB server and enables you to perform all kinds of operations on a NoSQL database through PHP. In this tutorial we will see how to install and configure the mongodb php driver on Ubuntu, CentOS 7 and Microsoft Windows. As distributions and environments vary, installation instructions will also vary.
Install MongoDB PHP Driver on UbuntuMongoDB PHP Driver for Ubuntu provides by the php-mongodb package which we can install with apt-get command.
Then, restart the Apache Web Server:
To verify the installation, we can run phpinfo() function. The phpinfo page should display mongodb details as shown below. From the command line you can run php -i command to get information on mongodb driver.
Install PHP MongoDB Driver on CentOS 7The php mongodb driver on CentOS 7 for PHP 5 available from the epel-repository. First, enable the epel repository:
Install the php-mongodb package:
Restart the HTTPD server:
If you installed PHP 7 using webtatic repository, then the package name should be something like "php71w-pecl-mongodb". You can search available packages with yum search command.
Selinux will block mongodb driver on CentOS 7. As a solution you can either disable Selinux or enable the 'httpd_can_network_connect_db' boolean.
Following is the sample PHP error caused by Selinux on CentOS 7:
Install PHP MongoDB Driver on Windows 10/Windows Server 2016Important: For Windows, You need to download correct mongodb driver for PHP, based on your PHP version, Architecture and whether Thread Safety is enabled. You can get those information from the phpinfo page. Do the following steps to install and configure MongoDB driver on Windows XAMPP Server.
Test MongoDB Connection From PHP ScriptLet's write a very simple PHP program that creates a connection to the MongoDB server and dump the connection status. Add following PHP code to your php script and access from the Web browser.
The above PHP example will output something similar to:
And that is mean, you have a connection to the MongoDB Server in your PHP script. |