I am working on a website which needs to interact with an SQLite database. This is my first project using PHP and I'm running into some issues. So far I have:
config.php:
...
$connection = new SQLiteConnection();
$connection->connect();
And in SQLiteConnection, $connection->connect() does pretty much this:
try {
$rootDir = $_SERVER["DOCUMENT_ROOT"];
$this->pdo = new PDO("sqlite:".$rootDir.self::DATABASE_PATH);
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo "Exception: '".$e->getMessage()."' at line ".$e->getLine();
}
However each time I run config.php I get the following error:
Exception: 'could not find driver' at line 22
This is the line where I initialise a PDO.
I have tried lots of solutions:
Purging and reinstalling php-common, php-sqlite3, and others
Uncommenting these lines in my php.ini file (in /etc/php/7.2/cli):
extension=pdo_sqlite
extension=sqlite3
Uncommenting and setting an extension directory in the same php.ini file:
sqlite3.extension_dir = "ext"
Restarting the apache2 service (sudo service apache2 restart)
When I run php -m I do get the modules in the list, but with a warning:
$ php -m
PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_sqlite' (tried: /usr/lib/php/20170718/pdo_sqlite (/usr/lib/php/20170718/pdo_sqlite: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/pdo_sqlite.so (/usr/lib/php/20170718/pdo_sqlite.so: undefined symbol: php_pdo_unregister_driver)) in Unknown on line 0
PHP Warning: Module 'sqlite3' already loaded in Unknown on line 0
[PHP Modules]
...
PDO
pdo_sqlite
...
sqlite3
...
But when I look into the contents of the directory, those files seem to be present:
$ ls -al /usr/lib/php/20170718
total 6372
drwxr-xr-x 2 root root 4096 Mar 1 11:40 .
drwxr-xr-x 4 root root 4096 Mar 1 11:38 ..
...
-rw-r--r-- 1 root root 113048 Feb 11 15:55 pdo.so
-rw-r--r-- 1 root root 31096 Feb 11 15:55 pdo_sqlite.so
...
-rw-r--r-- 1 root root 52648 Feb 11 15:55 sqlite3.so
...
When I look into its parent directory, I see:
$ ls -al /usr/lib/php/
total 40
drwxr-xr-x 4 root root 4096 Mar 1 11:38 .
drwxr-xr-x 144 root root 4096 Mar 1 11:38 ..
drwxr-xr-x 2 root root 4096 Mar 1 11:40 20170718
drwxr-xr-x 3 root root 4096 Mar 1 11:38 7.2
-rw-r--r-- 1 root root 4845 Jan 17 2018 php-helper
-rw-r--r-- 1 root root 9534 Jan 17 2018 php-maintscript-helper
-rwxr-xr-x 1 root root 2922 Jan 17 2018 sessionclean
Could the issue be because of both 20170718 and 7.2 are present (I'm not really sure of the difference)? The 7.2 directory doesn't have any of the .so files though.
On restarting my computer (and thus the IDE I am using, IntelliJ), I received a different error when running the config.php file - that I needed to install php-cgi.
I did so and no longer received the exception when running config.php. I suppose I already solved that problem and it just required an IDE restart to apply it.
The second issue, that still remained, was the warning:
PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_sqlite' (tried: /usr/lib/php/20170718/pdo_sqlite (/usr/lib/php/20170718/pdo_sqlite: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/pdo_sqlite.so (/usr/lib/php/20170718/pdo_sqlite.so: undefined symbol: php_pdo_unregister_driver)) in Unknown on line 0
PHP Warning: Module 'sqlite3' already loaded in Unknown on line 0
And I resolved this using the answer here:
It means there is an extension=... or zend_extension=... line in one of your php configuration files (php.ini, or another close to it) that is trying to load that extension.
In trying to find a solution earlier, I had uncommented a few lines in the php.ini file. Simple commenting them back fixed the issue!
In case of php 7.4 on Windows, you must include the directory where libsqlite3.dll resides in the path.
See: https://www.php.net/manual/en/sqlite3.installation.php
Related
I have recently had to migrate to a brand new server after a sudden server crash. I am now getting an error where if I email a certain email address, (which I know i pipe to a PHP script), i get the following error message back via email:
This message was created automatically by mail delivery software.
A message that you sent could not be delivered to one or more of its
recipients. This is a permanent error. The following address(es) failed:
pipe to |/home/username/public_html/support/api/pipe.php
generated by email
The following text was generated during the delivery attempt:
------ pipe to |/home/username/public_html/support/api/pipe.php
generated by email------
PHP Warning: PHP Startup: Unable to load dynamic library '/opt/cpanel/ea-php54/root/usr/lib64/php/modules/msql.so' - /opt/cpanel/ea-php54/root/usr/lib64/php/modules/msql.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/opt/cpanel/ea-php54/root/usr/lib64/php/modules/mysql.so' - /opt/cpanel/ea-php54/root/usr/lib64/php/modules/mysql.so: cannot open shared object file: No such file or directory in Unknown on line 0
What is strange is I have the extensions installed via EasyApache. But if I do an ls on this, i only get the following:
[root#bob home]# ls /opt/cpanel/ea-php54/root/usr/lib64/php/modules/
ctype.so imap.so mysqlnd.so phar.so sqlite3.so xml.so
curl.so json.so pdo_mysqlnd.so posix.so tokenizer.so xmlwriter.so
dom.so mysqlnd_mysqli.so pdo.so simplexml.so wddx.so xsl.so
ftp.so mysqlnd_mysql.so pdo_sqlite.so sockets.so xmlreader.so
On a new server I installed PHP 7.0.10 and mysql.
When I try to connect to the database via a php file using mysqli_connect() it gives the error message
Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in /opt/http/blabla/src/class_db.php:19 Stack trace: #0 /opt/http/blabla/src/main.php(17): _Db->connect() #1 {main} thrown in /opt/http/blabla/src/class_db.php on line 19
This is caused because PHP cannot load the mysql shared object:
[root#nl2 httpd]# php -v
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64
/php/modules/mysqli.so' - /usr/lib64/php/modules/mysqli.so: symbol
mysql_change_user, version libmysqlclient_18 not defined in file
libmysqlclient.so.18 with link time reference in Unknown on line 0
PHP 7.0.11 (cli) (built: Sep 17 2016 09:23:18) ( NTS )
Both libraries exist:
[root#nl2 httpd]# ls -l /usr/lib64/php/modules/mysqli.so /usr/lib64/php/modules/mysqli.so
-rwxr-xr-x 1 root root 141856 Sep 17 11:39 /usr/lib64/php/modules/mysqli.so
-rwxr-xr-x 1 root root 141856 Sep 17 11:39 /usr/lib64/php/modules/mysqli.so
Some configuration information:
# yum list installed
php70w.x86_64 7.0.10-1.w7
php70w-cli.x86_64 7.0.10-1.w7
php70w-common.x86_64 7.0.10-1.w7
php70w-devel.x86_64 7.0.10-1.w7
php70w-gd.x86_64 7.0.10-1.w7
php70w-mysql.x86_64 7.0.10-1.w7
php70w-opcache.x86_64 7.0.10-1.w7
php70w-pdo.x86_64 7.0.10-1.w7
php70w-process.x86_64 7.0.10-1.w7
mysql55w.x86_64 5.5.50-1.w
mysql55w-devel.x86_64 5.5.50-1.w
mysql55w-libs.x86_64 5.5.50-1.w
mysql55w-server.x86_64 5.5.50-1.w
# cat /etc/php.d/mysqli.ini
;Enable mysqli extension module
extension=mysqli.so
extension=php_mysqli.so
Any suggestions?
Thanks.
I would comment, but I don't have enough points. Have you tried:
yum -y install php70w-mbstring php70w-mcrypt
And then connecting using:
$mysqli = new mysqli('ip', 'user', 'pass', 'db', port);
I think it's an issue of not enough PHP installed!
I am just beginning with laravel. I followed all the steps mentioned in here: http://github.com/aimeos/aimeos-laravel and tried running the final project using this command:
php artisan serve
It is giving me an error:
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/php_mbstring.dll' - /usr/lib/php/20151012/php_mbstring.dll: cannot open shared object file: No such file or directory in Unknown on line 0
Laravel development server started on http://localhost:8000/
[Wed Apr 13 17:03:32 2016] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/php_mbstring.dll' - /usr/lib/php/20151012/php_mbstring.dll: cannot open shared object file: No such file or directory in Unknown on line 0
[Wed Apr 13 17:03:43 2016] 127.0.0.1:39822 [200]: /favicon.ico
[Wed Apr 13 17:03:43 2016] 127.0.0.1:39823 [200]: /favicon.ico
What should I do to resolve this error? I have installed mbstring library so I think it should've been able to find it.
I am using laravel 5.2.29.
EDIT:
I had uncommented the line:
extension=php_mbstring.dll
in my php.ini file which shouldn't be done if platform is UNIX. Now, when I run php artisan serve on terminal, it doesn't give any error. But when I go to localhost:8000, it says : Whoops! looks like something went wrong.
EDIT2:
Did everything according to suggestion.
Now the error is: No supported encrypter found. The cipher and / or key length are invalid.
What I have already tried:
'cipher' => 'AES-256-CBC',
php artisan key:generate
What can be done to resolve it?
Got my last problem resolved too.
The problem was that as #Bordon suggested, I had created a .env file. But when I ran the command:
php artisan key:generate
It created another file called .env.example. Now since I am a user of composer, I needed to rename it to .env (and remove the prev one).
So finally I renamed it, ran the above mentioned command again and now it works like a charm. Thanks a lot #Bordon for helping me out.
Also I would like to note that as #ash suggested, using Vagrant is quite a lot easier to me than xampp.
I am getting this error when my php script tries to access text file.
PHP Warning: fopen(UPfileName.txt): failed to open stream: Permission denied in /path/to/script.php
Here are the permissions of my directory and file:
abc/www/file.txt
drwxr-xr-x 12 root root abc/
drwxr-xr-x 8 root root www/
-rwxrwxr-x 1 root root file.txt
Please tell what should I do to get ride of this error.
Thanks
Sam
I have a cron job that runs a php file. Within the php file it requires another file. For other php files run by cron and I do the same require file, it works just file. I've changed permissions on all files involved to 777 (for testing) and the problem still occurs. When I execute the file from the command line, it runs just fine.
Why is the file not allowed permission for this 1 php file?
Here is the error I receive from the cron:
[Fri Mar 29 00:05:01 2013] [warn-phpd] mmap cache can't open /home/rpn/public_html/admin/admin_functions.php - Permission denied (pid 29776)
PHP Warning: require(/home/rpn/public_html/admin/admin_functions.php): failed to open stream: Permission denied in /home/rp/public_html/cron/cron-boxscores.php on line 6
Warning: require(/home/rpn/public_html/admin/admin_functions.php): failed to open stream: Permission denied in /home/rp/public_html/cron/cron-boxscores.php on line 6
PHP Fatal error: require(): Failed opening required '/home/rpn/public_html/admin/admin_functions.php' (include_path='.:/usr/lib/php:/usr/local/lib/php:/home/rp/php') in /home/rp/public_html/cron/cron-scrape-boxscores.php on line 6
Fatal error: require(): Failed opening required '/home/rpn/public_html/admin/admin_functions.php' (include_path='.:/usr/lib/php:/usr/local/lib/php:/home/rp/php') in /home/rp/public_html/cron/cron-boxscores.php on line 6
Here is line 6:
require('/home/rpn/public_html/admin/admin_functions.php');
Here is the directory showing the file and permissions settings:
root#host [/home/rpn/public_html/admin]# ls -l admin*
-rw-r--r-- 1 nobody nobody 19022 Mar 8 14:18 admin_functions.php
nobody:nobody is what Apache is set to run under.