John Davidson

postgresql - Using Postgres with PHP 7.4 macOs Big Sur

0 comments
Message:


After update to macOs Big Sur and update PHP 7.3 -> 7.4.19 my postgres not working.


Extensions activated in php.ini


extension=pdo_pgsql
extension=pgsql


  • PHP instaled using brew


Output command php -m not contains the module pdo_pgsql


Error output in command php artisan serve:


PHP Startup: Unable to load dynamic library 'pdo_pgsql' (tried: /opt/local/lib/php74/extensions/no-debug-non-zts-20190902/pdo_pgsql (dlopen(/opt/local/lib/php74/extensions/no-debug-non-zts-20190902/pdo_pgsql, 9): image not found), /opt/local/lib/php74/extensions/no-debug-non-zts-20190902/pdo_pgsql.so (dlopen(/opt/local/lib/php74/extensions/no-debug-non-zts-20190902/pdo_pgsql.so, 9): image not found)) in Unknown on line 0


My Answer:
To use Postgres with PHP 7.4 on macOS Big Sur, you will need to follow these steps:

1. Install Postgres:
- You can install Postgres using Homebrew by running the following command in your terminal:

brew install postgresql


2. Start Postgres:
- After installing Postgres, you can start the Postgres server by running the following command:

brew services start postgresql


3. Install the Postgres PHP extension:
- You can install the Postgres PHP extension using PECL by running the following command in your terminal:

pecl install pdo_pgsql


4. Enable the Postgres PHP extension:
- Once the extension is installed, you will need to enable it in your php.ini file. You can find the location of your php.ini file by running the following command in your terminal:

php --ini

- Open the php.ini file in a text editor and add the following line to enable the Postgres PHP extension:

extension=pdo_pgsql


5. Restart your web server:
- After enabling the Postgres PHP extension, you will need to restart your web server for the changes to take effect. You can do this by running the following command in your terminal:

sudo apachectl restart


6. Test the connection:
- You can test the connection to your Postgres database by creating a PHP script that connects to the database and performs a query. Here is an example script:
php
$db = new PDO('pgsql:host=localhost;dbname=mydatabase', 'myuser', 'mypassword');
$stmt = $db->query('SELECT * FROM mytable');
while ($row = $stmt->fetch()) {
print_r($row);
}
?>


By following these steps, you should be able to use Postgres with PHP 7.4 on macOS Big Sur.

Rate this post

5 of 5 based on 1784 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us