Linux php установить pdo

PHP 7 RC3: How to install missing MySQL PDO

I am trying to setup webserver with PHP 7 RC3 + Nginx on Ubuntu 14.04 (for test purposes). I installed Ubuntu in Vagrant using ubuntu/trusty64 and PHP 7 RC 3 from Ondřej Surý (https://launchpad.net/~ondrej/+archive/ubuntu/php-7.0). I can not find the way to install MySQL PDO (PHP sees PDO class but not anything related to MySQL, like PDO::MYSQL_ATTR_DIRECT_QUERY etc.) Looks like there is no lib php7.0-mysql (by analogy with standard php5-mysqlnd and php7.0-fpm etc. from Ondřej) Section PDO in phpinfo() :

PDO support enabled PDO drivers no value 

You say Ubuntu 12.04, but then that you’re using ubuntu/trusty64 which is 14.04. Assuming that you are in fact using Trusty (after all, Ondřej hasn’t produced packages for Precise) then his php-modules package will provide php-mysql .

Yes, you are absolutely right! (version is fixed). And your suggestion with module name works. Thanks! If you add it as answer I will mark it as correct.

My mistake — i was searching like this apt-cache search php pdo and module php-mysql in this case is not shown.

If it’s anything like standard Ubuntu/Debian you can also install php5-mysqlnd to use the mysql native driver, which according to that link is «strongly encouraged», even if the Ubuntu devs don’t use it by default.

13 Answers 13

For thoses running Linux with apache2 you need to install php-mysql

or if you are running ubuntu 16.04 or higher just running the following command will be enought, no need to edit your php.ini file

apt-get install php7.2-mysql 

If you are running ubuntu 15.10 or below:

Edit your php.ini file, it’s located at /etc/php/[version]/apache2/php.ini and search for pdo_mysql you might found something like this

Save the file and restart apache

Check that it’s available in your phpinfo()

Just a general FYI, I would highly recommend using MySQLND( php-mysqlnd ) instead of the older php-mysql package

Not everyone has the luxury of choosing what library the customer app is already using, and not everyone can just «apt-get»

Note: «service restart apache2» should read «service apache2 restart». For Ubuntu 16.04 I used only «sudo apt-get install php7.0-mysql» and «sudo service apache2 restart».

sudo apt-get install php7.0-mysql //change the version number based on the php version 
sudo service apache2 restart 

On ubuntu 18.04 following works for me

type this in your terminal

sudo apt-get install php7.3-gd php7.3-mysql 
sudo apt-get install php7.0-gd php7.0-mysql 
sudo apt-get install php5-gd php5-mysql 

Since eggyal didn’t provided his comment as answer after he gave right advice in a comment — i am posting it here: In my case I had to install module php-mysql . See comments under the question for details.

Читайте также:  Linux hex to ascii

First, check if your php.ini has the extension enabled «php_pdo_mysql» and «php_mysqli» and the path of «extension_dir» is correct. If you need one of above configuration, then, you must restart the php-fpm to apply the changes.

In my case (where i am using the Windows OS in the company, i really prefer OSX or Linux), i solved the problem putting this values in the php.ini:

; . extension_dir = "ext" ; . extension=php_mysqli.dll extension=php_pdo_mysql.dll ; . 

If you are on windows, and your php folder is not in your PATH, you have set the absolute directory in your php.ini

extension=php_mysqli.dll extension=php_pdo_mysql.dll 

Restart apache2.4 and it should work.

  1. download the source code of php 7 and extract it.
  2. open your terminal
  3. swim to the ext/mysqli directory
  4. use commands:

Thanks, the same worked for pdo_mysql. Not sure why it isn’t compiled as part of default make;make install o_O

I had, pretty much, the same problem. I was able to see that PDO was enabled but I had no available drivers (using PHP 7-RC4). I managed to resolve the issue by adding the php_pdo_mysql extension to those which were enabled.

I resolved my problem on ubunto 20.4 by reinstalling php-mysql.

sudo apt purge php7.2-mysql 
sudo apt install php7.2-mysql 

It will add new configurations in php.ini

Had the same issue, resolved by actually enabling the extension in the php.ini with the right file name. It was listed as php_pdo_mysql.so but the module name in /lib/php/modules was called just pdo_mysql.so

So just remove the «php_» prefix from the php.ini file and then restart the httpd service and it worked like a charm.

Please note that I’m using Arch and thus path names and services may be different depending on your distrubution.

I’ll start with the answer then context NOTE this fix was logged above, I’m just re-stating it for anyone googling.

  1. Download the source code of php 7 and extract it.
  2. open your terminal
  3. swim to the ext/pdo_mysql directory
  4. use commands: phpize ./configure make make install (as root)
  5. enable extension=mysqli.so in your php.ini file

This is logged as an answer from here (please upvote it if it helped you too): https://stackoverflow.com/a/39277373/3912517

Context: I’m trying to add LimeSurvey to the standard WordPress Docker. The single point holding me back is «PHP PDO driver library» which is «None found»

php -i | grep PDO PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_odbc' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20170718/pdo_odbc (/usr/local/lib/php/extensions/no-debug-non-zts-20170718/pdo_odbc: cannot open shared object file: No such file or directory), /usr/local/lib/php/extensions/no-debug-non-zts-20170718/pdo_odbc.so (/usr/local/lib/php/extensions/no-debug-non-zts-20170718/pdo_odbc.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: Module 'mysqli' already loaded in Unknown on line 0 PDO PDO support => enabled PDO drivers => sqlite PDO Driver for SQLite 3.x => enabled 
apt-get install php7.0-mysql 
Package 'php7.0-mysql' has no installation candidate 

Get instructions saying all I have to do is run this:

add-apt-repository -y ppa:ondrej/apache2 
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 223: ordinal not in range(128) 

So I try and force some type of UTF: LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/apache2 and I get this: no valid OpenPGP data found.

Читайте также:  What is export command in linux

Follow some other instructions to run this: apt-get update and I get this: Err:14 http://ppa.launchpad.net/ondrej/apache2/ubuntu cosmic/main amd64 Packages 404 Not Found Err:15 http://ppa.launchpad.net/ondrej/php/ubuntu cosmic/main amd64 Packages 404 Not Found and — I think because of that — I then get:

The repository 'http://ppa.launchpad.net/ondrej/apache2/ubuntu cosmic Release' does not have a Release file. 

By this stage, I’m still getting this on apt-get update:

Package 'php7.0-mysql' has no installation candidate. 

I start trying to add in php libraries, got Unicode issues, tried to get around that and. you get the idea. whack-a-mole. I gave up and looked to see if I could compile it and I found the answer I started with.

You might be wondering why I wrote so much? So that anyone googling can find this solution (including me!).

Источник

How to install Microsoft’s SQL PHP PDO and so on drivers for Linux NGINX – Tested

Microsoft has made massive strides in supporting PHP on Linux in the last few years. A common need in a PHP application might be to connect to a Microsoft SQL Server. This guide is designed to explain how to install Microsoft SQL PHP drivers and some of the pitfalls that might occur. It’s heavily based on the Microsoft documentation but all the noise stripped out. There really exists just one pitfall (spoiler install ODBC Dev), but the entire procedure is a bit cumbersome so we’ve documented it from head to toe.

Prerequisites

  • Ubuntu 18.04 or any of it’s derivatives
    • Refer to the Microsoft documentation if you’re using another Linux distribution
    • The only tricky park with regards to other distributions is the PECL compilation

    Step 1

    Install PHP & PHP-DEV and XML Libraries

    Note: All three these items might already be installed on up to date PHP servers. If you’re using a different PHP version, substitute 7.4 with whichever version.

    sudo su add-apt-repository ppa:ondrej/php -y apt-get update apt-get install php7.4 php7.4-dev php7.4-xml -y --allow-unauthenticated

    Step 2

    Install ODBC Driver prerequisites

    At this point the Microsoft documentation takes you to another site to install the ODBC drivers. This can be quite overwhelming for an already complex and convoluted installation process but hang in there.

    Once you get to this destination website, your first challenge is to understand which actual version you are supposed to install, and which one is not working or was a temporary one that is now deprecated. It’s thoroughly confusing and as you’re only starting the installation, it can be really annoying. But hang in there, we’ve done the work so you can just sit back and relax and read on.

    So next one has to install the ODBC driver for Ubuntu by following the instructions on the Linux installation article. We’ve put the link for you don’t have to follow it, we won’t take you to another page.

    If you are going to follow links, skip to Ubuntu because the default link at the top of the page has lots of confusing information:

    Now you probably need a big screen because the instructions scroll off the screen. Bigger screens are highly recommended for PHP Development.

    sudo su curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -

    Next be careful! You might choose the wrong Ubuntu version and then who knows what will happen.

    curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > /etc/apt/sources.list.d/mssql-release.list

    Next be careful again! There are three sets of instructions, and two are optional, but in my experience the ODBC drivers are key to getting things working. First you have to deal with Microsoft’s weird sudo su / exit experience:

    exit sudo apt-get update sudo ACCEPT_EULA=Y apt-get install msodbcsql17

    Next your optional packages, before, long further down this convoluted installation you might need ODBC dev libraries! Skip at your own peril!

    # optional: for bcp and sqlcmd

    sudo ACCEPT_EULA=Y apt-get install mssql-tools echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc source ~/.bashrc

    Here is the non-optional steps marked at optional!

    # optional: for unixODBC development headers

    sudo apt-get install unixodbc-dev

    You can now continue to the first page. That’s if you remember where you came from. It’s called Step 3

    Step 3

    Install the PHP drivers for Microsoft SQL Server

    Warning! The procedure below only works for PHP 7.4! If you use another version kittens will die! The reasons for this kitten nightmare is because PECL will try to compile for the currently installed PHP version. If you have another version you’re trying to do this for, this tutorial is not the right one but I’d love your comments below if you gave help. I did it once and was so tired afterwards I decided to go and sleep.

    The fun below starts at the very first command pecl install sqlsrv. This goes into some complex compilation process and god forbid it works the first time. The lovely favourite here is:

    fatal error: sql.h: No such file or directory #include

    One thing you have to understand about this pecl command is it will interrogate your local PHP install and compile the library for that version. If you’re using multiple PHP versions you might have to play with update alternatives.

    The next command takes ages and it’s output is completely overwhelming. It tells you if it’s successful but you have to carefully scrutinize the final output.

    Build process completed successfully . noise. You should add "extension=sqlsrv.so" to php.ini

    Then if you need PDO (do it anyway, you’ve come this far):

    sudo pecl install pdo_sqlsrv

    Final steps, please note that this is for PHP 7.4 and probably won’t work as the compiled libraries are for 7.4.

    sudo su printf "; priority=20\nextension=sqlsrv.so\n" > /etc/php/7.4/mods-available/sqlsrv.ini printf "; priority=30\nextension=pdo_sqlsrv.so\n" > /etc/php/7.4/mods-available/pdo_sqlsrv.ini exit sudo phpenmod -v 7.4 sqlsrv pdo_sqlsrv

    The last command is supposed to work for Apache by in my experience it also works for NGINX.

    Источник

Оцените статью
Adblock
detector