Nginx with PHP usage of SQLite throws error - php

I'm using nginx in docker from trafex/php-nginx
But I don't get SQLite working.
The following php code
<?php
$db = new SQLite3('/var/private/anmeldungen.db');
$db->close();
throws this error [error] 9#9: *33 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught Error: Class "SQLite3" not found in /var/www/html/phpinfo.php:3
I'm using a dockerfile to install the sqlite package:
FROM trafex/php-nginx:latest
USER root
RUN apk add php8-pdo_sqlite
USER nobody
And in the PHPInfo I can see that the package is loaded:
Does anyone have an idea?

Your package is wrong, PDO is PHP Data Object which is a higher layer designed to be able to work with any lower database protocol such as SQLite, MySQL, Postgres..., so implementing via PDO may help you a lot in long run if you would like to switch to another database without changing much (there may be some incompatible features but not much) of your source code.
To init a SQLite via PDO you have to do so:
$dbh = new PDO('sqlite:/tmp/foo.db');
You can read more about that here https://www.php.net/manual/en/ref.pdo-sqlite.php.
If you want to stick with native SQLite (to use your SQLite3 class), you will have to install package php8-sqlite3 but not the php8-pdo_sqlite3
apk add php8-sqlite3
This will work with your current code.

SQLite is included with PHP, you have to uncomment it in the php.ini file. But first you have to uninstall the one you installed because otherwise PHP will complain that there are two. I had the same problem, albeit not inside a Docker container. PHP agreed that SQLite was installed but the CLI wouldn't use it.

Related

Install MSSQL Using Composer

I am migrating a Drupal site to another server and keep getting HTTP 500 error in the browser. When I investigate the PHP error log, I see that there is
PHP Fatal error: Call to undefined function sqlsrv_connect()
in one of the files. I am on a Linux environment and have Composer installed. Is there a way to install the mssql extension using the Composer? Alternatively, what is an efficient way to install MSSQL extension?
the SQLSRV functions are only available on Windows machines.
you can try using the ODBC functions, after installing the drivers but you will have to rewrite your code to use them.
if you happen to be running Ubuntu, here's a script for installation.

CodeIgniter 1.72 and PHP 5.3.29 compatible?

We're upgrading our server infrastructure on Amazon and I'm attempting to migrate a PHP site based on CodeIgniter (version 1.7.2) to a new server which has AmazonLinux as the OS. The previous server was Ubuntu, running PHP 5.3.3-1ubuntu9.5 on apache2. The PHP version on the new AmazonLinux server is 5.3.29, running on httpd.
When I try to access the URL in the new server, the code is currently stopping in system/core/CodeIgniter.php at this line:
$CI = new $class();
I haven't been able to see any relevant error messages in the httpd error log specified in virtual hosts for the app, nor in the default httpd error log. Using the lynx command line client to access the URL simply shows a internal server 500 error, while accessing through a regular browser just shows a blank page.
Any ideas? I know the Code Igniter version is pretty old, circa 2009. But it's compatible with PHP 5.3, which we're running on the new server. This is legacy code and will disappear at some point, so we have no interest in upgrading the PHP or CI level - unless we're forced to due to the upgrade.
The problem turned out to be a database access issue. Specifically, the version of PHP on the new server turned out to not support deprecated calls to php-mysql APIs (e.g. #mysql_pconnect or #mysql_connect)
The solution was to
1) Download the mysql library which supports the legacy calls. In the case of AmazonLinux, this is accomplished as follows:
sudo yum install php-mysql
2) Find where the library was downloaded e.g.
find / -name mysql.so
This may have been shown in the install as well, but that is a way to find it anytime. YMMV, but in my case, the library name was:
/usr/lib64/php-zts/modules/mysql.so
3) Change php.ini (as shown in phpinfo when called from a php page on the httpd/apached server) as follows:
a) change "extension_dir" to show where the mysql.so is installed:
extension_dir = "/usr/lib64/php-zts/modules"
b) Then add the following lines:
extension=mysqli.so
extension=mysql.so
extension=pdo_mysql.so
Reboot apache and you should be good to go.
Note: the specific legacy call not supported, which is part of of the version of CodeIgnitor I'm working with, was this:
return #mysql_pconnect($this->hostname, $this->username, $this-
The php error log showed this error:
PHP Fatal error: Call to undefined function mysql_connect() in xxx.php on line xx

Mongodb running with node and PHP

I am new to Node.js and MongoDB. I have successfully got the mongoDB running with node.js and am able to start it up and store data inside of collections. So the server is already running on localhost:27017 and works when accessing localhost:28017 .
Now that I have it running and working within Node, I wanted to test MongoDB out with PHP on my Xampp server running on Ubuntu, but am not able to get the phpinfo() to say it is using mongo yet.
I have followed the steps here to configure and install the driver. I have moved the mongo.so file to my xampps extensions and added the appropriate line in php.ini + restarted. But phpinfo() still doesn't show it.
I guess i am confused on the aspect of where do i put the mongo-php-driver folder? is this installed into the Xampp server as well, if so where do i put it?
It is already running and working using node.js , so was just getting confused why it wasn't working properly or getting connected.
Also while I'm at it, Is it possible to have php and node.js use the same mongoDB server running on port 27017?
EDIT:
I was able to get the server to at least give me an error message about the file after i edited the extension_dir to the correct path
extension_lib = "/opt/lampp/lib/php/extensions/no-debug-zts-20090626"
i am now getting this error
Warning: PHP Startup: Unable to load dynamic library '/opt/lampp/lib/php/extensions/no-debug-non-zts-20090626/mongo.so' - /opt/lampp/lib/php/extensions/no-debug-non-zts-20090626/mongo.so: wrong ELF class: ELFCLASS64 in Unknown on line 0
i guess I needed to change that php.ini option to get it to load properly. but it seems I have compiled the wrong mongo.so build. I try again.
Thanks
According to this:
http://montenasoft.com/en/blog/how-install-pecl-php-extension-64bit-linux-while-you-are-using-32bit-xampp
Because xampp is compiled with 32 bit, but the mongo driver you compile is 64 bit.
You may have to compile your mongo driver with these:
phpize
CFLAGS=-m32 CPPFLAGS=-m32 CCASFLAGS=-m32 ./configure
make
sudo make install
Or just install apache2, mysql, php separately. I think this is a better option.

How can I tell if PDO module installed/disabled?

I'm developing a PHP application. I just moved a bunch of files over to the production server, to discover that PDO is apparently not installed (Fatal error: Class 'PDO' not found in [file] on line [line]). The prod server is using PHP 5.3.6; according to the documentation I've found, "PDO and the PDO_SQLITE driver is enabled by default as of PHP 5.1.0".
I have very little experience administering PHP. How do I tell if this module is installed but disabled, or absent altogether? And what do I need to do to get it running?
Generally you can just do phpinfo(); to find out what modules are installed.
Or from the commandline:
php -m
Additionally you could use: class_exists('PDO') to find out whether the PDO class indeed is accessible.
In the terminal type:
php -i |grep PDO
The -i is used to display the output of phpinfo().
The |grep will filter the list to the ones containing PDO.

CakePHP Bake Error: Database connection "Mysql" is missing, or could not be created

I'm looking for some help to get rid of this error. As i'm running mac os x 10.5 I had to install A newer version of php to support pdo. I did this using Marc Liyanage's installer package.
The problem I'm having now is that using php from the command line is invoking the default apple php, not the pdo enabled version causing bake to fail.
How can I get the bake command to use the correct version of php on my system?
Many Thanks
Ralph
you could specify the path to the new php.. ?
/path/to/new/php/php script_to_run.php
There may be an alternatives package under osx as well where you can specify which versions of which apps you can use.
I was getting the following error while trying to bake v2.3.1
Warning Error: PDO::__construct(): [2002] No such file or directory
(trying to connect via unix:///var/mysql/mysql.sock) in
[/Library/WebServer/third-party/frameworks/cake_2.3.1/lib/Cake/Model/Datasource/Database/Mysql.php,
line 158]
Error: Database connection "Mysql" is missing, or could not be created.
Fixed the issue by modifying pdo_mysql.default_socket in php.ini to point to right socket file path.

Categories