Troubleshooting Codeigniter Deployment with Azure

2019-08-09 00:57发布

问题:

[![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.

回答1:

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>


回答2:

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:

--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';