0392.html 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <!DOCTYPE html>
  2. <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>Install and Configure MongoDB with PHP on Windows</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <meta charset="UTF-8">
  7. <meta name="keywords" content="MongoDB,PHP,Database,NoSQL,Apache2,HTTPD,Microsoft,Windows,MongoDB Compass,XAMPP,PowerShell,How To,Tutorial,i12bretro">
  8. <meta name="author" content="i12bretro">
  9. <meta name="description" content="Install and Configure MongoDB with PHP on Windows">
  10. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  11. <meta name="revised" content="04/02/2023 11:57:40 AM" />
  12. <link rel="icon" type="image/x-icon" href="includes/favicon.ico">
  13. <script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
  14. <script type="text/javascript" src="includes/js/steps.js"></script>
  15. <link href="css/steps.css" rel="stylesheet" type="text/css" />
  16. </head>
  17. <body>
  18. <div id="gridContainer">
  19. <div class="topMargin"></div>
  20. <div id="listName" class="topMargin">
  21. <h1>Install and Configure MongoDB with PHP on Windows</h1>
  22. </div>
  23. <div></div>
  24. <div id="content">
  25. <h2>Adding PHP Support for MongoDB</h2>
  26. <ol>
  27. <li>Open Windows Explorer and navigate to the PHP installation directory</li>
  28. <li>Hold the SHIFT key and right click in the white space &gt; Open PowerShell window here...</li>
  29. <li>Run the following command to output the PHP version information
  30. <div class="codeBlock PS">.\php.exe -v</div>
  31. </li>
  32. <li>Note the architecture (x86 or x64) and the PHP version</li>
  33. <li>Open a web browser and navigate to the MongoDB PHP driver page <a href="https://pecl.php.net/package/mongodb" target="_blank">Download</a></li>
  34. <li>Click the Windows DLL link</li>
  35. <li>Select either the x86 or x64 to match the PHP installation. If using PHP with Apache or nginx download the Thread Safe version. If using PHP for IIS, download the Non-Thread Safe version</li>
  36. <li>Extract the downloaded .zip file</li>
  37. <li>Copy the .dll file from the extracted folder to the PHP installation /ext directory</li>
  38. <li>Find php.ini inside the PHP installation directory and edit it in a text editor</li>
  39. <li>Search for ;extension=</li>
  40. <li>At the bottom of the list of extensions, add the following line
  41. <p>extension=mongodb</p>
  42. </li>
  43. <li>Restart the web server to apply the change</li>
  44. </ol>
  45. <h2>Installing MongoDB on Windows</h2>
  46. <ol>
  47. <li>Download MongoDB Community Server <a href="https://www.mongodb.com/try/download/community" target="_blank">Download</a></li>
  48. <li>Navigate to the Downloads directory &gt; Launch the MongoDB .msi installer</li>
  49. <li>Step through the installer accepting all the defaults</li>
  50. </ol>
  51. <h2>Testing PHP and MongoDB</h2>
  52. <ol>
  53. <li>Download the mongodb_test.php <a href="https://raw.githubusercontent.com/i12bretro/tutorials/main/_Downloads/mongodb_test.php" target="_blank">Download</a></li>
  54. <li>Save mongodb_test.php on the root of the web server</li>
  55. <li>Open a web browser and navigate to http://DNSorIP/mongodb_test.php</li>
  56. <li>The page will create a new database called phpDemo, a collection named states, write some rows and then read them back and display them in a table</li>
  57. </ol>
  58. <h2>Install MongoDB Compass (Optional)</h2>
  59. <ol>
  60. <li>Open a web browser and navigate to the MongoDB Compass GitHub latest release <a href="https://github.com/mongodb-js/compass/releases/latest/" target="_blank">Link</a></li>
  61. <li>Download the win32-x64.zip file</li>
  62. <li>Extract the downloaded .zip file</li>
  63. <li>Move the extracted files to a folder where it will run from permanently (ie C:\Program Files\MongoDBCompass\)</li>
  64. <li>Run MongoDBCompass.exe</li>
  65. <li>Once the application loads, click the green Connect button to connect to the locally running MongoDB instance</li>
  66. </ol>
  67. <p>For more information on MongoDB CRUD operations with PHP check out <a href="https://roytuts.com/mongodb-php-7-crud-example/" target="_blank">https://roytuts.com/mongodb-php-7-crud-example/</a></p> </div>
  68. </div>
  69. </body>
  70. </html>