1

changed database.php settings enter image description here[![enter image description here][3]][3][![enter image description here][4]][4]I'm trying to deploy a PHP app with Azure. I get the the index page to show up: http://phpdiscussionboard.azurewebsites.net/

But when you click login or register, the error I see is: "The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."...which leads me to believe in my database.php file I am configuring it incorrectly..not sure. I have hooked up the connection with MYSQLWorkbench and when I test the connection it works. Similarly, when I change the index of my application to another view, that loads the specified template.

Here is my database.php file my applications/config

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

$active_group = 'default';
$active_record = TRUE;

if(ENVIRONMENT == 'production')
{
    $db['default']['hostname'] = 'ahmxn6q9c3.database.windows.net,1433';
    $db['default']['username'] = 'username';
    $db['default']['password'] = 'password';
    $db['default']['database'] = '';
}
else
{
    $db['default']['hostname'] = 'ahmxn6q9c3.database.windows.net,1433';
    $db['default']['username'] = 'username';
    $db['default']['password'] = 'password';
    $db['default']['database'] = '';
}
$db['default']['dbdriver'] = 'sqlsrv';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

//end of database.php

The db driver only works with 'sqlsrv'. In my connection string I get from azure, it says my database is called "discussionboard"...which I named it as on purpose. However when I enter discussionboard as the default db i continue to get the error. For my Azure db page, when I click on the sql database, it tells me: Connect to your database with : Server: ahmxn6q9c3.database.windows.net,1433 For which I have that string and port as my default host. However, in the connection string it says the data source is : us-cdbr-azure-west-c.cloudapp.net

Am i configuring the whole database.php incorrectly?

I would really appreciate anyone's help that has successfully deployed a php app with mysql through azure before.

Thank you for your time

this is what i have right now....looks the same as the image you posted...am i missing something? Sorry I've never deployed a php app before.

I've tried configuring it how you said...the image below is the only way I can get the page to load with a database error..but i still get the Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid object name 'users'. even when I add a users table.

posted error message

2 Answers2

2

The url http://tradiscussionboard.azurewebsites.net/users/login is returning 404 status code so it is not found. This is most likely the result of missing or miss-configured rewrite rules. On Azure you need to include a web.config file (the IIS equivalent of the .htaccess file on Apache) in the root directly that contains:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Rewrite to index.php">
                    <match url="index.php|robots.txt|images|test.php" />
                    <action type="None" />
                </rule>
                <rule name="Rewrite CI Index">
                    <match url=".*" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" pattern="css|js|jpg|jpeg|png|gif|ico|htm|html" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php/{R:0}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>
Tristan
  • 3,301
  • 8
  • 22
  • 27
  • Hi Tristan, thanks for the answer. So to clarify, I add this through my azure web app and not directly into sublime? – Theodore Rollin Anderson Nov 11 '15 at 20:08
  • Yes, the `web.config` file needs to be in the root directory of your web app on your Azure server. – Tristan Nov 11 '15 at 20:09
  • Under app_settings/ WEBSITE_NODE_DEFAULT_VERSION ? – Theodore Rollin Anderson Nov 11 '15 at 20:13
  • The `web.config` must be located at the root of your project. This question may provide some context http://stackoverflow.com/questions/2362191/is-it-possible-to-edit-web-config-of-cloud-app-deployed-on-windows-azure-without – Tristan Nov 11 '15 at 20:22
  • I''m looking at it now. I created a web.config file at the root level of my application, added the routing rules you gave me, pushed and commited the changes as well as in the default documents I've added web.config – Theodore Rollin Anderson Nov 11 '15 at 20:26
  • now i'm getting farther..the flash errors will show up but now i get an error of A Database Error Occurred Error Number: 42S02 [Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid object name 'users'. Is this due to a failing connection with workbench? – Theodore Rollin Anderson Nov 11 '15 at 20:32
  • Sounds like your db connection does not specify a default database so it is using master. You need to specify your database name in the config `$db['default']['database'] = '';` – Tristan Nov 11 '15 at 20:42
  • Tristan, sorry to keep bugging you. Thanks for all the help. I have specified it to discussionboard, which is what the schema is called and what ive called it in azure. I test the connection through workbench and it connects to my azure sql database..is there anywhere else i should check? – Theodore Rollin Anderson Nov 11 '15 at 20:48
  • Now you're getting `Invalid object name 'discussionboard.users'.` Does that table exist in your database on the server? – Tristan Nov 11 '15 at 20:56
  • It exists in my schema in work bench, the table users..how do i verify that in azure? – Theodore Rollin Anderson Nov 11 '15 at 21:00
  • So you have connected to SQL Azure using workbench and confirmed that the table exists? – Tristan Nov 11 '15 at 21:09
  • i guess i'm not sure what you're asking. my connection from workbench says Connected to MySQL at us-cdbr-azure-west-c.cloudapp.net:3306 with user b98de423f68884 Connection parameters are correct SSL not enabled – Theodore Rollin Anderson Nov 11 '15 at 21:18
  • That can't be right. You're database.php config is using SQL server on port 1433, not MySQL on port 3306. – Tristan Nov 11 '15 at 21:22
  • so should i just change the port for the connection in workbench? – Theodore Rollin Anderson Nov 11 '15 at 21:24
  • I would recommend a SQL management tool, rather than workbench. Maybe an express version. SSMS 2012 Express supports special Azure SQL options like "Deploy Database to SQL Azure" etc – Tristan Nov 11 '15 at 21:27
  • you don't think there's a way to do it with workbench as i have it now? – Theodore Rollin Anderson Nov 11 '15 at 21:32
  • I'm not aware of a way to use mysql workbench to connect to sql server database on Azure. – Tristan Nov 11 '15 at 21:36
  • is there a place in the azure dashboard to check the contents of the database? – Theodore Rollin Anderson Nov 11 '15 at 22:32
1

The endpoint like: ahmxn6q9c3.database.windows.net,1433 is the connection endpoint of Azure SQL Server,

and the endpoint like: us-cdbr-azure-west-c.cloudapp.net is the connection endpoint of MySQL service on Azure which is provided by ClearDB.

According your current issue, it seems that you have misconfigurations of your Azure SQL in CodeIgniter project.

You should configure the database name in applications/config/database.php file, e.g.

$db['default']['hostname'] = 'ahmxn6q9c3.database.windows.net,1433'; $db['default']['username'] = 'username'; $db['default']['password'] = 'password'; $db['default']['database'] = 'discussionboard';

And your query string should be modified to like: "SELECT * FROM users WHERE users.email = 'aaa' AND users.password = 'aaa'".

--update0--

Use MySQL workbench to connect to Azure SQL: enter image description here

--update1--

if you use MySQL database, you need to modify database connection settings in applications/config/database.php,e.g.: $db['default']['hostname'] = '{your server name}.cloudapp.net'; $db['default']['username'] = 'username'; $db['default']['password'] = 'password'; $db['default']['database'] = 'discussionboard'; $db['default']['dbdriver'] = 'mysqli';

Gary Liu
  • 13,758
  • 1
  • 17
  • 32
  • Hi Gary..I've changed it to that an am still getting the same error – Theodore Rollin Anderson Nov 12 '15 at 02:48
  • can you confirm that your data is exactly in Azure SQL? you can manage Azure SQL in Visual Studio, refer to https://channel9.msdn.com/Events/Visual-Studio/Launch-2013/WC117 for details. – Gary Liu Nov 12 '15 at 02:58
  • I'm using a mac and using sql workbench. Can i still download it? – Theodore Rollin Anderson Nov 12 '15 at 03:06
  • can you connect to Azure SQL with your workbench? the general idea is that we need to make sure is there data in your Azure SQL server or MySQL service, as you also mentioned MySQL in your question. And in in Azure SQL manage page in Azure manage portal, there is a button named 'MANAGE' in bottom nav which provide a web management tool for Azure SQL online. – Gary Liu Nov 12 '15 at 03:15
  • Yes when i connect via mysqlworkbench and use the connection string it says it is connected but then the database error i get is Error Number: 42S02 [Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid object name 'discussionboard.users'. SELECT * FROM discussionboard.users WHERE users.email = 'email@email.com' AND users.password = 'password' Filename: D:\home\site\wwwroot\system\database\DB_driver.php Line Number: 330 – Theodore Rollin Anderson Nov 12 '15 at 03:46
  • try `SELECT * FROM users WHERE users.email = 'email@email.com' AND users.password = 'password'` – Gary Liu Nov 12 '15 at 04:29
  • usually, this error message means that you don't have such table named `users` in this database. you may double check your data on Azure SQL, as you work in a MAC, you can refer to http://stackoverflow.com/questions/3452/sql-client-for-mac-os-x-that-works-with-ms-sql-server – Gary Liu Nov 12 '15 at 04:58
  • there's really not any way to do it through mysql workbench? i feel like i'm super close to getting it. – Theodore Rollin Anderson Nov 12 '15 at 15:00
  • If your MySQL workbench supports to connect to MSSQL, you do can manage your Azure SQL via it. You can see the screenshot I updated. – Gary Liu Nov 13 '15 at 01:01
  • Gary..just added an image. Am i missing something? – Theodore Rollin Anderson Nov 13 '15 at 02:07
  • OK, the host in your MySQL workbench is MySQL server on Azure which is provided by ClearDB, but the database settings in your code project is Azure SQL info which is MSSQL on Azure. So currently, you just manage your data on MySQL, and connect to Azure SQL in your application. You have to decide one database service to use, MySQL or MSSQL. And keep the database settings the same in your application and workbench. – Gary Liu Nov 13 '15 at 02:28
  • So i need to change what I have in my database.php file? i want use mysql for the database. – Theodore Rollin Anderson Nov 13 '15 at 02:31
  • Gary -- I've tried configuring it how you said...the image below is the only way I can get the page to load without a database error..but i still get the Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid object name 'users'. even when I add a users table. – Theodore Rollin Anderson Nov 13 '15 at 03:10
  • you missed `$db['default']['dbdriver'] = 'mysqli';` to change your database driver – Gary Liu Nov 13 '15 at 03:20
  • yeah i tried that 'mysqli' as well as 'mysql'. only 'sqlsrv' seems to work for me – Theodore Rollin Anderson Nov 13 '15 at 03:23
  • what is the error message you get when you use `mysql` or `mysqli` driver? – Gary Liu Nov 13 '15 at 03:29
  • When i use mysql or mysqli as the driver I get: Unable to connect to your database server using the provided settings. Filename: D:\home\site\wwwroot\system\database\DB_driver.php Line Number: 124 – Theodore Rollin Anderson Nov 13 '15 at 03:30
  • could provide your database settings code snippet when you get this message? – Gary Liu Nov 13 '15 at 04:18
  • yeah i just posted it. – Theodore Rollin Anderson Nov 13 '15 at 04:22
  • your lasted edition still shows you are using `sqlsrv` driver with MSSQL database connection settings. Could you please modify your settings as my **update1** shows, and post your error message again? – Gary Liu Nov 13 '15 at 04:25
  • Gary, did it. posted the updated database.php file and the error message i get – Theodore Rollin Anderson Nov 13 '15 at 04:42
  • Gary...finally configured it and got it running properly..last question..i know how to take out the "index.php"..but how do i get rid of the "?" the pops up when i make a request to another page on my app. Regardless, thanks for all the help! – Theodore Rollin Anderson Nov 13 '15 at 05:15
  • Do you mean to hide the URL pattern after `?` mark? E.G. the part `?a=1&b=2` of `example.com/index.php?a=1&b=2`? And this question is little relative with this thread title. So I recommend you to specify your new question in a new thread which is benefit for those developers who have the same issue or have the experience browsing your thread. If it is convenient for you. – Gary Liu Nov 13 '15 at 05:28