I have successfully pushed a codeigniter project to a cpanel console.
Everything seems to be working fine except the database connection.
I believe i have the settings correct but i could be wrong.
Below is my database.php script:
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'instadri_insta',
'password' => 'BL9w;K;ds9MR',
'database' => 'instadri_ver',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
I have the errors below:
A PHP Error was encountered
Severity: Warning
Message: mysqli::real_connect(): (HY000/1044): Access denied for user
'instadri_insta'#'localhost' to database 'instadri_ver'
Filename: mysqli/mysqli_driver.php
Line Number: 202
Backtrace:
File: /home/instadri/application/controllers/Welcome.php Line: 10
Function: __construct
File: /home/instadri/public_html/index.php Line: 319 Function:
require_once
I also get :
A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by
(output started at /home/instadri/system/core/Exceptions.php:272)
Filename: core/Common.php
Line Number: 568
Backtrace:
File: /home/instadri/application/controllers/Welcome.php Line: 10
Function: __construct
File: /home/instadri/public_html/index.php Line: 319 Function:
require_once
And Finally :
Unable to connect to your database server using the provided settings.
Filename: controllers/Welcome.php
Line Number: 10
I have taken care of the above.
The new issue now is the smarty template file loading.
I have a controller that does this :
$this->smarty->view('front-theme/index.tpl', $data );
But i get this error:
Unable to load the requested file:
front-theme/index.tpl
My cpanel directory structure is:
public_html
- index.php
application
system public
-_template
-_cache
-front-theme
I had the same problem but I have solved it.
Simply upload your CI files to the public html folder, every thing in the CI folder should be uploaded together. so when you open the public folder it should filled with the CI files.
Leave your db settings the same way, but cross-check the values you entered for validity. and finally go to the config.php file and check the base url variable and change to your url link name.
That's it!
Related
Not able to connect MySQL... detail given bellow.
A PHP Error was encountered
Severity: Warning
Message: mysqli::real_connect(): (HY000/2002): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)
Filename: mysqli/mysqli_driver.php
Line Number: 202
Backtrace:
File: /var/www/html/application/controllers/Account.php
Line: 7
Function: __construct
File: /var/www/html/index.php
Line: 315
Function: require_once
First you need to download xampp and ensure that my sql services on or off .if it is on then you are write function mysqli_connect(‘localhost’,’username’,’password’,’database’);
I guess you have a xampp installed in your system and SQL service was enabled.
If yes, then create one database file in your application/config folder. Filename is database.php
Here you need to give a default db driver variable, likewise
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'your-db-username',
'password' => 'your-db-password',
'database' => 'your-db-name',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8mb4',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
Next, you need to load this database.php config file in autoload.php (in the same directory).
$autoload['libraries'] = array('database');
Now, you have connected a database with your Codeigniter project.
Reference : https://www.codeigniter.com/userguide3/database/configuration.html
I am learning how to use schema builder to create tables. I have got phpmyadmin running on 127.0.0.1:81/phpmyadmin. I created a db in phpmyadmin named testdb.
On my laravel app in app/config/database.php i have made changes to 'mysql' section as:
'mysql' => array(
'driver' => 'mysql',
'host' => '127.0.0.1:81',
'database' => 'testdb',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
On app/routes.php i wrote :
Route::get('/', 'HomeController#showWelcome');
On app/controller/HomeController.php i wrote:
public function showWelcome()
{
Schema::create('employee', function($emp_table){
$emp_table->increments('id');
$emp_table->string('name');
$emp_table->integer('salary');
});
return View::make('hello');
}
Now i am getting a 'Something went wrong' message when reloading localhost:8000. It should be creating the table 'employee' with fields 'id', 'name' and 'salary'. The 'app/storage/logs/laravel.log' says:
[2015-01-14 06:09:49] production.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Maximum execution time of 60 seconds exceeded' in C:\wamp\www\stylop-dev\bootstrap\compiled.php:9301
Stack trace:
#0 [internal function]: Illuminate\Exception\Handler->handleShutdown()
#1 {main} [] []
Please help, i am stuck fixing this error and have hit a dead end :(
Well i guess i figured out why i was getting the error. I was using 127.0.0.1:81 so i changed it back to the default port 80.
Now it works
When I try to login to the app I have setup on Forge, my Laravel app spits out this error:
SQLSTATE[HY000] [1045] Access denied for user 'appname'#'localhost' (using password: YES)
I have the environment variables configured correctly and they work fine on my copy of the site on my local Homestead vagrant box.
Here is the .env.php file that Forge wrote:
return [
'APP_ENV' => 'production',
'DB_DRIVER' => 'mysql',
'DB_HOST' => 'localhost',
'DB_NAME' => 'appname',
'DB_USER' => 'appname',
'DB_PASS' => 'LoNgPaSsWoRd',
];
Here is the relevant contents of app/config/database.php which works locally:
'default' => getenv('DB_DRIVER'),
'connections' => array(
'mysql' => array(
'driver' => getenv('DB_DRIVER'),
'host' => getenv('DB_HOST'),
'database' => getenv('DB_NAME'),
'username' => getenv('DB_USER'),
'password' => getenv('DB_PASS'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
),
I tried dumping the environment values before the first database connection is accessed using dd(getenv('DB_PASS'), getenv('DB_USER')) and they show up correct.
I also tried connecting through MySQL Workbench and resetting the password to exactly what is shown in the environment variable Forge wrote.
None of my other subdomains are having this issue.
What could be going on here and how could I debug this?
I just upgraded my Laravel install from 4.1.(something) to 4.2.7 using the steps recommended here: http://laravel.com/docs/upgrade
Now I'm getting this error on every page:
PDOException (2002)
SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '' (111)
MySQL is not running locally, but it's not supposed to be. I don't have any configuration for connecting to local MySQL, my development SQL server is remote. Why is it trying to connect to local?
Is there some config change that isn't mentioned in the upgrade guide? Everything was peachy in 4.1.
From my app/config/database.php file:
'default' => 'mysql',
...
'connections' => array(
'mysql' => array(
'driver' => 'mysql',
'host' => 'myrealdb.us-east-1.rds.amazonaws.com',
'database' => 'myrealdbname',
'username' => 'myrealuser',
'password' => 'myrealpass',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'database_port' => '3306',
'unix_socket' => '',
),
...
);
I tried php artisan clear-compiled and php artisan dump-autoload just in case. No effect.
Edit: I submitted a fix for this that has been merged into the 4.2 branch. You shouldn't have to worry about this error anymore.
I got it! This appears to be a change in the way Laravel uses the database configuration, I hope this answer helps others.
The short version is: if your connection is configured like mine (in the question), delete the unix_socket entry from the array.
Previously, I always copied and edited the default entries in the connections array, leaving in the unix_socket parameter as empty. Apparently now there's a check that assumes if unix_socket is present, it should use a socket DSN string. The empty string in my config passed the check. You can see how this happens in /vendor/laravel/framework/src/Illuminate/Database/Connectors/MySqlConnector.php. The functions getDsn, getSocketDsn, and getHostDsn tell the story.
Pasted because this will eventually change:
protected function getDsn(array $config)
{
return isset($config['unix_socket']) ? $this->getSocketDsn($config) : $this->getHostDsn($config);
}
...
protected function getSocketDsn(array $config)
{
extract($config);
return "mysql:unix_socket={$config['unix_socket']};dbname={$database}";
}
...
protected function getHostDsn(array $config)
{
extract($config);
return isset($config['port'])
? "mysql:host={$host};port={$port};dbname={$database}"
: "mysql:host={$host};dbname={$database}";
}
I deployed my app on a remote host and everything works as expected. But when I try to test my code on localhost, it gives me the following error, without any change to the code working on the host:
Fatal error: Class 'AppHelper' not found in [path]
I am using CakePHP 2.1 and MySQL as my default datasource.
I connect to my local database just like to the remote one (with authentication changes):
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'root',
'password' => '',
'database' => 'database',
'prefix' => '',
'encoding' => 'utf8',
);
Why isn't this working on my localhost? Thank you
Two possible things:
either you didnt know about the AppHelper requirement for 2.1:
http://book.cakephp.org/2.0/en/appendices/2-1-migration-guide.html
or you forget to declare the helper at the very top of your class:
App::uses('AppHelper', 'View/Helper');
Although the second one is highly unlikely if you are not running any unit tests.
So my bet is on the first one.