IIS/PHP/SQL Server 2012 Troubleshooting

I miss LAMP stack…

I like php with mysql on linux…actually one of my favorite things. Trying to recreate an app from my debian box to one of my windows machines and found that the recommended configuration is php with sql server (color me shocked)….which is fine. SQL Server is pretty locked down when it comes to security settings – rightfully so, you don’t want your typical user to unknowingly make their machine into a server. Took a few minutes of playing around with it, but this is how you fix the various errors you’ll encounter when trying to write php on your windows box with sql server 2012 and iis:

1) PHP isn’t installed. Grab PHP (http://windows.php.net/download/) and use the handy new PHP installer for Windows with IIS (http://php.iis.net/). If you have one of the more modern Windows OS’s you have IIS already, but you may need to snag iis express. In IIS, you can register a new PHP version – you should see PHP manager on IIS once you run the 2 downloads above. If you can’t get IIS to play nice, leave me a comment and I’ll help you through it. Or we can move on with our lives and install apache…
2) SQL Server Authentication isn’t configured right. Open up SQL Server. Right click your server name and go to properties. Under Security on the left, you should see Mixed Mode authentication. Make sure that’s ticked. Under connections, tick Allow Remote Connections. I’m assuming you’re trying to remote in eventually, so you’ll need a new user on SQL server that can login with sql server authentication. Sometimes the wizards and menus are wonky, so try opening a new query and following these directions: http://stackoverflow.com/questions/1601186/sql-server-script-to-create-a-new-user. After that, you can use that user in the code in step 4.
3) SQL Server isn’t letting you connect. Open up SQL Server Configuration Manager. You should see SQL Server Network Configuration. When you click it you will see your named instances. Click into each one. There are two fields, protocol name and status. Try enabling Shared Memory, Named Pipes, and TCP/IP. These three should let you call in from a remote host using SQL server authentication.
4) Your code is wrong. Just follow this…should work nicely and help you further troubleshoot: http://www.php.net/manual/en/function.sqlsrv-connect.php

Hope that helps…this should solve “Login failed for user” in your php app.

Mysql error 13…!@#$!@#$!@#$ (Ubuntu 13.x)

New ubuntu 13 install, yay. Mysql errors, boo. Tried reinstalling, thought it could be a lamp bulk install issue on the latest release (used the tasksel method). Figured out a few tricks to fix this error I was getting when I created a database:

mysql> create database db;
ERROR 13 (HY000): Can’t get stat of ‘./db’ (Errcode: 13)

!@#$!@$!@$

Error 13 means a permission issue usually…not a problem…let’s login as root…my fault, that was a n00b move (though ashley is the mask for my root right now):

ashley@c0dem0nkey:~$ mysql -u root -p

still ERROR 13!!! !@#$!@#$!@

Last thing…check if there’s permission to write to the mysql directory in var (where you store the database text files). AH HA!!!
do this:

~ ls -la /var/lib/mysql
ls: cannot open directory /var/lib/mysql: Permission denied

k so need everyone able to write to that directory. Use chmod for that…I took the lazy way out and gave everyone basically admin where the X’s are (not recommended):

~ sudo chmod XXX /var/lib/mysql

XXX is where you put the numeric code. 777 gives admin…DO NOT DO 777 unless you understand the ramifications..as in…7 lets you execute! 444 lets everyone read…which is probably enough. Check out this man page for more: http://ss64.com/bash/chmod.html.

Now it all works. Haven’t hit the server from another machine yet just to check port crap, but at least I can locally create and use db’s. Win.