Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR 404: Not Found with installodbc_redhat.sh #298

Closed
mikelecours opened this issue Feb 22, 2017 · 25 comments
Closed

ERROR 404: Not Found with installodbc_redhat.sh #298

mikelecours opened this issue Feb 22, 2017 · 25 comments

Comments

@mikelecours
Copy link

When attempting to install the msphsql drivers, the install script for red hat fails with a 404 error when trying to download msodbcsql-13.0.0.0.tar.gz. Below is the log of the install. Is there another location wher I can get the file?

--2017-02-22 09:17:08-- ftp://ftp.unixodbc.org/pub/unixODBC/unixODBC-2.3.1.tar.gz
=> \u2018/tmp/msodbcrhel/unixODBC-2.3.1.tar.gz\u2019
Resolving ftp.unixodbc.org (ftp.unixodbc.org)... 87.106.19.214
Connecting to ftp.unixodbc.org (ftp.unixodbc.org)|87.106.19.214|:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done. ==> PWD ... done.
==> TYPE I ... done. ==> CWD (1) /pub/unixODBC ... done.
==> SIZE unixODBC-2.3.1.tar.gz ... 1813380
==> PASV ... done. ==> RETR unixODBC-2.3.1.tar.gz ... done.
Length: 1813380 (1.7M) (unauthoritative)

100%[====================================================================================================>] 1,813,380 264KB/s in 8.9s

2017-02-22 09:17:24 (198 KB/s) - \u2018/tmp/msodbcrhel/unixODBC-2.3.1.tar.gz\u2019 saved [1813380]

Loaded plugins: fastestmirror, langpacks
Repository packages-microsoft-com-prod is listed more than once in the configuration
base | 3.6 kB 00:00:00
epel/x86_64/metalink | 14 kB 00:00:00
extras | 3.4 kB 00:00:00
google-chrome | 951 B 00:00:00
packages-microsoft-com-prod | 2.9 kB 00:00:00
remi-safe | 2.9 kB 00:00:00
updates | 3.4 kB 00:00:00
webtatic | 3.6 kB 00:00:00
(1/2): updates/7/x86_64/primary_db | 2.3 MB 00:00:00
(2/2): remi-safe/primary_db | 907 kB 00:00:01
Loading mirror speeds from cached hostfile

  • base: mirrors.cmich.edu
  • epel: mirrors.lug.mtu.edu
  • extras: mirrors.rit.edu
  • remi-safe: repo1.ash.innoscale.net
  • updates: mirror.team-cymru.org
  • webtatic: us-east.repo.webtatic.com
    Package gcc-4.8.5-11.el7.x86_64 already installed and latest version
    Nothing to do
    Succesfuly installed Yum Dependencies
    Installing unixODBC 2.3.1
    Successfuly installed unixODBC 2.3.1
    --2017-02-22 09:18:22-- https://download.microsoft.com/download/B/C/D/BCDD264C-7517-4B7D-8159-C99FC5535680/msodbcsql-13.0.0.0.tar.gz
    Resolving download.microsoft.com (download.microsoft.com)... 173.222.6.110, 2600:1417:4:187::e59, 2600:1417:4:196::e59
    Connecting to download.microsoft.com (download.microsoft.com)|173.222.6.110|:443... connected.
    HTTP request sent, awaiting response... 404 Not Found
    2017-02-22 09:18:24 ERROR 404: Not Found.

Unable to get Microsfot ODBC Driver from download center.
sudo: unable to resolve current working directory

@yitam
Copy link
Contributor

yitam commented Feb 22, 2017

Hi @mikelecours msodbcsql-13.0.0.0.tar.gz is old. Please follow the instructions on readme

To verify that ODBC driver is registered successfully, do the following:
odbcinst -q -d -n "ODBC Driver 13 for SQL Server"

You should see an output like this

[ODBC Driver 13 for SQL Server]
Description=Microsoft ODBC Driver 13 for SQL Server
Driver=/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.1.so.1.0
UsageCount=1

Hope this helps.

@mikelecours
Copy link
Author

That's the output I got. Thanks. I then followed the README instructions. Everything seemed to install OK. But when I tried the test php script in the readme I got the error:
Error information:
SQLSTATE: IMSSP
Code: -14
Message: An invalid parameter was passed to sqlsrv_query.

I've attached the testsql.php file for your review
testsql.php.txt

Just to be sure, I tried the connection string in sqlcmd and it worked just fine

[root@nagios ~]# sqlcmd -S 10.21.50.131 -d nagiosdb -U nagios -P
1> select * from dbo.testtable;
2> go
testdata

mydata

(1 rows affected)

@yitam
Copy link
Contributor

yitam commented Feb 22, 2017

This is odd, so to help us investigate, please add these lines after calling sqlsrv_connect():

if( $conn === false ) {
	die(FormatErrors(sqlsrv_errors()));
}

@mikelecours
Copy link
Author

Here's the new error messages
Error information:
SQLSTATE: HYT00
Code: 0
Message: [unixODBC][Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired
SQLSTATE: 08001
Code: 10013
Message: [unixODBC][Microsoft][ODBC Driver 13 for SQL Server]TCP Provider: Error code 0x271D
SQLSTATE: 08001
Code: 10013
Message: [unixODBC][Microsoft][ODBC Driver 13 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.

@yitam
Copy link
Contributor

yitam commented Feb 22, 2017

@mikelecours Code 10013 means "Permission Denied". It might be firewall or related issues. In addition, you ran sqlcmd as root user (I assume the password was chopped off when you pasted).

Please try the followings:

  1. run sqlcmd NOT as root
  2. try connecting to another SQL Server using sqlsrv

Also, what version of SQL Server are you using? On which Windows version?

#190 might be a related issue.

@mikelecours
Copy link
Author

I've confirmed I can connect as a regular user:
[nagios@nagios ~]$ sqlcmd -S 10.21.50.131 -d nagiosdb -U nagios -P nagios
1> select * from dbo.testtable;
2> go
testdata

mydata

(1 rows affected)

The instance I'm connecting to is Microsoft SQL Server Express (64-bit) 13.0.4001.0 running on Window 10. I don't have another SQL Server instance to try connecting to. I'm connecting from Centos 7.

I looked at incident 190 but I don't think it related. It's not the firewall as I connect through SQLCMD. It's not the ports since I'm using the default and connect with or without the port specified. Just can't connect using the ms php drivers.

With the port specified.
[nagios@nagios ~]$ sqlcmd -S 10.21.50.131,1433 -d nagiosdb -U nagios -P nagios
1> select * from dbo.testtable;
2> go
testdata

mydata

(1 rows affected)

@yitam
Copy link
Contributor

yitam commented Feb 23, 2017

Thanks @mikelecours for the details. What output do you get when running odbcinst -q -d -n "ODBC Driver 13 for SQL Server"?

Also, to help us troubleshoot the connection issues, please go through the section Troubleshooting Connection Problems on this page.

For example, when you run yum list unixODBC, what do you see?
If possible, please enable connection log in odbcinst.ini file, one for sqlcmd and one when running php.
Thank you for your patience.

@mikelecours
Copy link
Author

Here's the result of the driver query

[nagios@nagios ~]$ odbcinst -q -d -n "ODBC Driver 13 for SQL Server"
[ODBC Driver 13 for SQL Server]
Description=Microsoft ODBC Driver 13 for SQL Server
Driver=/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.1.so.4.0
UsageCount=1

Here's the result of the yum list command

Installed Packages
unixODBC.x86_64 2.3.1-11.el7 @base
Available Packages
unixODBC.i686 2.3.1-11.el7 base

I'll try working through the trouble shooting document and report back the results

@mikelecours
Copy link
Author

I ran through the troubleshooting steps. The results are attached below. If I'm interpreting them correctly, the most common issue of more than one driver manager installed is false. It seems that the odbc drives themselves are working correctly. It seems that php is just not talking to them.

I don't know if this helps, but what I'm try to do is monitor a SQL Server instance with Nagios. It uses php to connect. Here's the error message I get from Nagios. It has different error messages that might help.
[nagios@nagios ~]$ check_mssql -H 10.21.50.131 -U nagio -P nagios -w 2 -c 5
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/pdo_sqlsrv.so' - /usr/lib64/php/modules/pdo_sqlsrv.so: undefined symbol: php_pdo_register_driver in Unknown on line 0
PHP Warning: Module 'sqlsrv' already loaded in Unknown on line 0
UNKNOWN: MSSQL/DBLIB support is not installed on this server. pdo_dblib must be usable.

mssqlphp.txt

@yitam
Copy link
Contributor

yitam commented Feb 23, 2017

@mikelecours your new error messages definitely gave us a clue. Please do the followings:

  1. run php -m (this will display a list of php modules, and see if you can find sqlsrv or pdo_sqlsrv amongst them)
  2. run php --ini (you might get similar warnings above) and locate where your php.ini file is

Then edit this php.ini file and look for extension=sqlsrv.so and extension=pdo_sqlsrv.so
If you find more than two instances of each, please delete the extra lines and only keep one line each. In short, you should only find one set of

extension=sqlsrv.so
extension=pdo_sqlsrv.so

Meanwhile I'll take a look at your attached logs.

@mikelecours
Copy link
Author

Interesting. The php --ini showed me the ini file that was loaded /etc/php.ini . The two extension statement were in there. I put them in per the install instructions. There were no duplicates. I looked up the PHP Warning: Module 'sqlsrv' already loaded in Unknown on line 0 part of the error and found a site that said to take out the extension statements if sqlsrv and pdo_sqlsrv were listed in the php -m statement because they are already compiled. http://www.somacon.com/p520.php

So, I rem'd them out to see what would happen. Now my app just returns UNKNOWN: MSSQL/DBLIB support is not installed on this server. pdo_dblib must be usable. The other part of the error is gone. No change with the testsql.php. Still the same errors. Attached are the lists from php -m and php --ini before the rem out. They both showed the Unknown line 0 error. That went away after I rem'd out the extension statement. So php 7 doesn't like those statements.

php listing.txt

We changed the error message. That's progress, right?

@yitam
Copy link
Contributor

yitam commented Feb 23, 2017

First of all, @mikelecours you're right, that for CentOS we shouldn't have the extensions in php.ini file. Instead, please read Step 5 of readme and you will find that RedHat / CentOS is handled differently from others. The main reason is that we have to ensure the extension PDO is loaded first.

Now that the lines have been commented out, you don't get those warning messages again, correct?

When you run php -m you should find pdo_sqlsrv and sqlsrv because they are supposed to be in separate ini files.

/etc/php.d/pdo_sqlsrv.ini,
/etc/php.d/sqlsrv.ini

What do you get when you run php --ri sqlsrv or the equivalent for pdo_sqlsrv?

Lastly, mssql pdo_dblib is a different extension.

@mikelecours
Copy link
Author

Yeah, I'm not sure why Nagios is complaining about that. But I mention it just to show the other error message is gone.

I verified that php -m shows both sqlsrv and pdo_sqlsrv. I review step 5 of the readme and verified the entries in their ini files:

[nagios@nagios ~]$ grep sqlsrv.so /etc/php.d/sqlsrv.ini
extension= /usr/lib64/php/modules/sqlsrv.so
[nagios@nagios ~]$ grep sqlsrv.so /etc/php.d/pdo_sqlsrv.ini
extension= /usr/lib64/php/modules/pdo_sqlsrv.so

Here is the results of the php --ri sqlsrv
[nagios@nagios ~]$ php --ri sqlsrv

sqlsrv

sqlsrv support => enabled
ExtensionVer => 4.0.8.0

Directive => Local Value => Master Value
sqlsrv.WarningsReturnAsErrors => On => On
sqlsrv.LogSeverity => 0 => 0
sqlsrv.LogSubsystems => 0 => 0
sqlsrv.ClientBufferMaxKBSize => 10240 => 10240

Everything seems to say the drivers are OK, sqlcmd can use them, why can't php?

@yitam
Copy link
Contributor

yitam commented Feb 24, 2017

Good question @mikelecours :) I believe it's something to do with your environment, so let's take a couple of steps back and run odbc trace again. Previously, you said your testsql.php did not write anything to the log. Is it still the case?

Do you have a clean CentOS vm for testing purposes?

Also, I wonder why it complains about pdo_dblib. Please check if the extension is listed in your php.ini

@mikelecours
Copy link
Author

You're not going to believe this but I found the problem. It's SELinux. I set it to permissive to test another problem and suddenly the testphp page works - connect to my database just fine. Set it SELinux back to enforcing - doesn't work. Back to permissive, works great. Since I can't leave it in permissive, any guidance on what needs to be set to allow php to keep using the drivers?

@yitam
Copy link
Contributor

yitam commented Feb 24, 2017

Glad to hear that you found a solution to this, @mikelecours. However, SELinux seems to have troubles with Apache + PHP (see this page for example).

Just for a quick test, can you run a simple script like this:

<?php
	phpinfo();
?>

@mikelecours
Copy link
Author

Yes, it returns the versioning information. I'll look at the page you sent me to see if I can solve the SELinux problem

@yitam
Copy link
Contributor

yitam commented Feb 25, 2017

Just so you know, we've confirmed that once SELinux is set to Enforcing, the php script won't run on Apache (even though running the same script from a terminal php /var/www/html/testsql.php works). This link might be able to help you, and it seems workarounds are possible. Good luck, @mikelecours.

@mikelecours
Copy link
Author

Thanks for all your help and prompt attention . It was very much appreciated.

@ulvii
Copy link
Contributor

ulvii commented Feb 25, 2017

Hi @mikelecours ,

Can you post output of the following command?

getsebool -a | grep httpd

@ulvii
Copy link
Contributor

ulvii commented Feb 25, 2017

If httpd_can_network_connect_db --> off, you need to allow Apache to connect to database through SELinux. Please try:

setsebool httpd_can_network_connect_db 1

@mikelecours
Copy link
Author

That did the trick! Thanks!

@yitam
Copy link
Contributor

yitam commented Feb 27, 2017

We are glad to hear that the suggestion from @ulvii works, @mikelecours !
I also found out setsebool -P httpd_can_network_connect 1 could fix the issue as well.
However, we would like to know, from an end user's point of view, which setting is preferred. Looking forward to hearing from you.

@mikelecours
Copy link
Author

For this application, httpd_can_network_connect_db is preferred. According to the man page for httpd_selinux, httpd_can_network_connect_db only allow connection to known database ports where as httpd_can_network_connect allow connect to any port. Below is the allowed ports from the man page for connect_db

allow httpd_t postgresql_port_t : tcp_socket { recv_msg send_msg name_connect } ;
allow httpd_t mssql_port_t : tcp_socket name_connect ;
allow httpd_t oracle_port_t : tcp_socket name_connect ;
allow httpd_t mysqld_port_t : tcp_socket { recv_msg send_msg name_connect } ;
allow httpd_t gds_db_port_t : tcp_socket name_connect ;

@yitam
Copy link
Contributor

yitam commented Feb 27, 2017

Thank you for your contributions, @mikelecours . We will update our documentation accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants