Is Ubuntu 21.04 compatible with PHP sqlsrv driver? - php

I have a web system developed with PHP + MS Sql Server and I do maintenance on Windows environment. But I prefer working in Linux environment, Ubuntu to be more accurate.
But I cannot find a way to install this database driver. I googled but I cannot find any solution. Some tutorials shows how to install in 20.04, 18.04 versions, but even following the steps to the letter, I could no install.
Some tutorials that did not worked.
How to Install the PHP SQLSRV Extension
Linux and macOS Installation Tutorial for the Microsoft Drivers for PHP for SQL Server
Any suggestions?

It seems, at least today, that msodbcsql17 mssql-tools are not available in the Ubuntu 21.04 repos...
$ curl -s https://packages.microsoft.com/config/ubuntu/21.04/prod.list
deb [arch=amd64,armhf,arm64] https://packages.microsoft.com/ubuntu/21.04/prod hirsute main
$ curl -s https://packages.microsoft.com/ubuntu/21.04/prod/dists/hirsute/Contents-amd64.gz | gzip -d | grep -E "msodbcsql|mssql"
# No output.
As a result you'll get errors when you try to install them via apt-get:
$ curl -s https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
$ sudo bash -c "curl -s https://packages.microsoft.com/config/ubuntu/21.04/prod.list > /etc/apt/sources.list.d/mssql-release.list"
$ sudo apt-get update --yes
# ...
$ sudo ACCEPT_EULA=Y apt-get --verbose-versions --yes install msodbcsql17 mssql-tools
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package msodbcsql17
E: Unable to locate package mssql-tools

Update
I have written a bash script to automatically install the appropriate drivers for Ubuntu or Debian: https://github.com/sfinktah/bash/blob/master/add_sqlsrv_repo_combined.sh
I couldn't test support for other Linux vendors, but the capability is there if someone wants to send a PR.
Original Post
21.04 drivers are now available.
Follow the instructions on
https://learn.microsoft.com/en-us/sql/connect/php/installation-tutorial-linux-mac?view=sql-server-ver15 and https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver15#ubuntu17
Or as above:
sudo su
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
#Download appropriate package for the OS version
#Choose only ONE of the following, corresponding to your OS version
# Automatic version selection (does not work for 21.10, but 20.10 or 21.04 are fine)
curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -r -s)/prod.list > /etc/apt/sources.list.d/mssql-release.list
# Manual specification: Ubuntu 21.04
curl https://packages.microsoft.com/config/ubuntu/21.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql17
# optional: for bcp and sqlcmd
sudo ACCEPT_EULA=Y apt-get install -y mssql-tools
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
# optional: for unixODBC development headers
sudo apt-get install -y unixodbc-dev

Related

How do I upgrade from PHP 7.0 to 7.3 on google cloud platform?

I am running the Wordpress multisite click to deploy on the compute engine.
Operating system
Debian 9.8
Package contents
Apache 2.4.25
Google-Fluentd 1.6.9
MySQL-Client 5.7.26
MySQL-Server 5.7.26
PHP 7.0.33
Stackdriver-Agent 5.5.2
WP-CLI 2.2.0
WordPress 5.1.1
phpMyAdmin 4.6.6
I would like to upgrade PHP to 7.3
You can use a third-party repository to install php7.3
apt-get install ca-certificates apt-transport-https
wget -q https://packages.sury.org/php/apt.gpg -O- | sudo apt-key add -
echo "deb https://packages.sury.org/php/ stretch main" | sudo tee /etc/apt/sources.list.d/php.list
apt-get update
apt-get install php7.3
You may follow this instructions on how to update your php version from 7.0 to 7.3.
For Debian:
$ sudo apt install apt-transport-https lsb-release
$ sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg # Download the signing key
$ sudo sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list' # Add Ondrej's repo to sources list.
$ sudo apt update
$ sudo apt-get install php7.3
To check the current version after the installation:
$ php -v
For Ubuntu:
$ sudo add-apt-repository ppa:ondrej/php # Press enter to confirm.
$ sudo apt-get update
$ sudo apt-get install php7.3
If you encounter the error below during installation, you may execute the command "$ sudo rm /var/lib/dpkg/lock" then try installing the php7.3 again.
E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
Hope this information helps.
After updating your php version, the other thing you should do is:
update MYSQL and get WordPress to to recognize the new version
sudo apt-get update
sudo apt-get install php7.3-mysql
sudo a2enmod php7.3
sudo a2dismod php7.0
sudo systemctl restart apache2
This comprehensive instruction works just fine https://www.jiyuulife.net/update-php-version-for-wordpress-on-debian-9/
In the commands, replace the instruction's PHP version (7.4.5) with the latest release (7.4.11 as of October 2020).
In my case, after the update WordPress alerted me about missing (PHP) extensions that some plugins needed. I added them separately as per the instruction, restarted Apache and everything panned out perfectly fine.
Magic!
Thanks Tang for the great instruction.

/usr/bin/env: �php\r’: No such file or directory

I have a problem during Propel ORM configuration.
I prepared environment on my Vagrant with PHP 7.1 following this provision file:
# Install software
add-apt-repository ppa:ondrej/php
apt update
apt install python-software-properties
apt update
apt install -y apache2
apt install -y php
apt install -y php-mcrypt
apt install -y php-mysql
apt install -y php-curl
apt install -y php-cli
apt install -y php-xml
apt install -y libapache2-mod-php
apt install -y mc
# install composer, configure Apache and create database
service apache2 restart
/etc/init.d/mysql restart
Currently I want to install Propel ORM. I added Propel to composer, installed, and now I type (by SSH in Vagrant)
/var/www/application/Vendors/bin/propel init but unfortunately I get error:
/usr/bin/env: �php\r’: No such file or directory
What can I do to resolve it?
EDIT:
File that I run (not edited, installed via Composer):
#!/usr/bin/env sh
dir=$(d=${0%[/\\]*}; cd "$d"; cd "../propel/propel/bin" && pwd)
# See if we are running in Cygwin by checking for cygpath program
if command -v 'cygpath' >/dev/null 2>&1; then
# Cygwin paths start with /cygdrive/ which will break windows PHP,
# so we need to translate the dir path to windows format. However
# we could be using cygwin PHP which does not require this, so we
# test if the path to PHP starts with /cygdrive/ rather than /usr/bin
if [[ $(which php) == /cygdrive/* ]]; then
dir=$(cygpath -m "$dir");
fi
fi
dir=$(echo $dir | sed 's/ /\ /g')
"${dir}/propel" "$#"
I don't use propel but had the same problem with phpunit.
The problem is often that the vendor/propel/propel/bin/propel, or in my case the vendor/phpunit/phpunit/phpunit file you try to execute is Windows encoded and not Unix encoded. It happens when you do composer install/update on Windows but run your code in a vagrant box.
You have multiple ways of getting rid of the CRLF:
dos2unix command (sudo apt-get install dos2unix)
use your prefered text editor (Sublime, PHPStorm, they can both do that)
get rid of vendor and run composer install/update from your vagrant box
Remember that the problem is not the vendor/bin/propel file but the vendor/propel/propel/bin/propel file.
Hope this help!

Installing PHP driver for Cassandra

I create server on linode and installed Ubuntu 15.10 and in my console, enter command for install php
apt-get update
apt-get install -y php5
sudo apt-get install php5-dev
Then, I Installed software: boost, openssl, libtool и cmake
sudo apt-get install libboost-all-dev
sudo apt-get install openssl
apt-get install cmake
sudo apt-get install automake libtool curl
curl -sSL https://github.com/libuv/libuv/archive/v1.4.2.tar.gz | sudo tar zxfv - -C /usr/local/src
cd /usr/local/src/libuv-1.4.2
sudo sh autogen.sh
sudo ./configure
sudo make
sudo make install
sudo rm -rf /usr/local/src/libuv-1.4.2 && cd ~/
sudo ldconfig
sudo apt-get install libssl-dev
And then, I installed cassnadra use datastax documentation
echo "deb http://debian.datastax.com/community stable main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
curl -L http://debian.datastax.com/debian/repo_key | sudo apt-key add -
sudo apt-get update
sudo apt-get install dsc20=2.0.11-1 cassandra=2.0.11
I checked cassnadra
sudo service cassandra status
and i get it:
● cassandra.service - LSB: distributed storage system for structured data
Loaded: loaded (/etc/init.d/cassandra)
Active: active (running) since Mon 2016-02-08 09:12:59 EST; 21s ago
Docs: man:systemd-sysv-generator(8)
CGroup: /system.slice/cassandra.service
└─27880 java -ea -javaagent:/usr/share/cassandra/lib/jamm-0.2.5.jar -XX:+CMSClassUnloadingEnabled -XX:+UseThreadPriorities -XX:Threa...
Feb 08 09:12:59 ubuntu systemd[1]: Starting LSB: distributed storage system for structured data...
Feb 08 09:12:59 ubuntu systemd[1]: Started LSB: distributed storage system for structured data.
I check the status of the cluster and cqlsh:
sudo nodetool status
and get:
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 127.0.0.1 41.32 KB 256 100.0% 2eaa4bd9-136d-4c2a-a65e-7444eb9d8824 rack1
and:
Connected to Test Cluster at localhost:9160.
[cqlsh 4.1.1 | Cassandra 2.0.11 | CQL spec 3.1.1 | Thrift protocol 19.39.0]
Use HELP for help.
Everything is working! finally I try install PHP Driver for Cassandra use this:
git clone https://github.com/datastax/cpp-driver.git
cd cpp-driver
cmake . && make && make install
ln -s libcql.so.0.7.0 /usr/lib/libcql.so.0
ln -s /usr/lib/libcql.so.0 /usr/lib/libcql.so
git clone https://github.com/aparkhomenko/php-cassandra.git
cd php-cassandra
phpize && ./configure && make
But I get Error
checking for specified location of CQL library... yes, shared
checking for CQL in default path... not found
configure: error: Please reinstall the cassandra distribution
Where is my mistake?
I think that the problem is that you are installing the Cassandra's driver for C/C++:
git clone https://github.com/datastax/cpp-driver.git
Instead, you have to use the PHP one:
git clone https://github.com/datastax/php-driver.git
cd php-driver
git submodule update --init
cd ext
./install.sh
Then, add the extension in the php.ini.
For apache2:
echo -e "; DataStax PHP Driver\nextension=cassandra.so" >> /etc/php5/cli/php.ini
echo -e "; DataStax PHP Driver\nextension=cassandra.so" >> /etc/php5/apache2/php.ini
/etc/init.d/apache2 reload
Everything you did prior to that was ok.
Source: https://github.com/datastax/php-driver/blob/master/ext/README.md

couchbase client for PHP in ubuntu 14.04

I am using Ubuntu14.04 and run PHP on it. Now I want the PHP to connect to Couchbase. However, I searched google and cannot find any suitable client for Ubuntu 14.04 of Couchbase Client. Does anyone have the idea to use the couchbase for php in Ubuntu 14.04/
Thanks
Using Ubuntu 14.04, Paddy's solution did not work,
these rewritten commands did work:
wget -O- http://packages.couchbase.com/ubuntu/couchbase.key | sudo apt-key add -
echo "deb http://packages.couchbase.com/ubuntu trusty trusty/main" >> /etc/apt/sources.list.d/couchbase.list
apt-get update
sudo apt-get install libcouchbase2-core libcouchbase2-libevent libcouchbase-dev
- missing after apt-key add, source file is missing a file ending, Ubuntu Aptitude only parses sources.list.d/*.list, libcouchbase-devel got renamed to libcouchbase-dev.
First of all you will need to install Libcouchbase (LCB):
wget -O- http://packages.couchbase.com/ubuntu/couchbase.key | sudo apt-key add
echo "deb http://packages.couchbase.com/ubuntu trusty trusty/main" >> /etc/apt/sources.list.d/couchbase
apt-get update
sudo apt-get install libcouchbase2-core libcouchbase2-libevent libcouchbase-devel
The Couchbase documentation covers this in more detail.
Once LCB has been installed then you will need to install the Couchbase PHP SDK:
pecl install couchbase
Again the Couchbase documentation covers this in more detail.

How do you install Libevent for PHP?

I installed the libevent-dev library on my Debian 7 64bit desktop:
$ sudo aptitude install -y libevent-dev
Then I installed the PECL library
$ pecl list
Installed packages, channel pecl.php.net:
=========================================
Package Version State
libevent 0.1.0 beta
I've restarted PHP and the OS but PHP doesn't list libevent as an installed ext in with phpinfo() and I get "PHP Fatal error: Call to undefined function event_base_new()" when I try to use it.
How do you install Libevent?
Install Libevent for PHP 5.X
sudo apt-get install libevent-dev
sudo pecl install libevent-beta
sudo su
sudo echo 'extension=libevent.so' > /etc/php5/mods-available/libevent.ini
exit
sudo ln -s /etc/php5/mods-available/libevent.ini /etc/php5/fpm/conf.d/
sudo ln -s /etc/php5/mods-available/libevent.ini /etc/php5/cli/conf.d/
sudo service php5-fpm restart
Install Libevent for PHP 7.X
At this time pecl package libevent is not available for php 7
https://pecl.php.net/package/libevent
So let's compile it.
Download master:
https://github.com/expressif/pecl-event-libevent
Unpack to: /tmp/install_libevent
cd /tmp/install_libevent/pecl-event-libevent-master
sudo phpize
sudo ./configure
After this step scroll our console window and try find any Warnings or Errors. I got one warning - required to install re2c package.
sudo make
sudo make install
sudo su
sudo echo 'extension=libevent.so' > /etc/php/7.0/mods-available/libevent.ini
exit
sudo ln -s /etc/php/7.0/mods-available/libevent.ini /etc/php/7.0/fpm/conf.d/20-libevent.ini
sudo ln -s /etc/php/7.0/mods-available/libevent.ini /etc/php/7.0/cli/conf.d/20-libevent.ini
sudo service php7.0-fpm restart
I've successfully installed it.
These are the steps:
apt-get install libevent-dev
sudo pecl install libevent
Edit: Press enter when you are asked for the libevent installation directory (autodetect)
; Add extension=libevent.so in the *.ini file where you desire to load it. For example if you want this extension to be loaded always, create a libevent.ini file where your php5 mods are (in my computer they are in /etc/php5/mods-available/) and write extension=libevent.so. Enable this module then with php5enmod libevent. This page may help you.
Add extension=libevent.so to php.ini.

Categories