Tag Archives: codeigniter

“MySQL server has gone away” with CodeIgniter and MySQL

I’v stopped using CodeIgniter for 7 months, but I maintaining a product that was developed under CI.

rock ssd

Today I’v got a error saying  “MySQL server has gone away” after a long time PHP execution.
I’v managed to solve it by, on the model that was getting me the error, *reconnect* to the database .

Before the *command* i’v added $this->db->reconnect();

 $this->db->insert('photoGallery', $data);
 return $this->db->insert_id();

Hope it helps anyone out there.

Codeigniter – remove index.php

Bootstrap & Apache! you can see the .htaccess

Add the following lines on your /etc/nginx/sites-enable/domain.com or default.

# removes trailing "index" from all controllers
 if ($request_uri ~* index/?$)
 rewrite ^/(.*)/index/?$ /$1 permanent;

More details how to set up a nginx environment for CI.


Create a .htaccess file on the root of your CI installation (in the same directory where you have system, application, etc).

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]


Awesome tutorial about mod-rewrite / pretty links


Thats kinda it!
Basically is a pretty url rewrite condition, for nginx must be also simple as that.
Simple as that!

CodeIgniter, PHP source code not compiled

I’v uploaded a CodeIgniter application from my localhost with Apache to a server running Nginx.
Its works perfectly on my localhost and on other server with Apache.
It’s under a subdomain, an domain and other subdomains are running PHP 100%.
This application in CI doesn’t start, and PHP is returned without being compiled.

This is what I get on /var/log/nginx/error.log:

2013/12/05 14:50:31 [error] 20139#0: *1 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Class 'M_website' not found in /home/webroot/domain.com/cms/system/core/Loader.php on line 303" while reading upstream, client:, server: cms.domain.com, request: "GET /websites HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "cms.domain.com"

Why the problem?

CI files were starting with


and not with



Had to edit /etc/php5/fpm/php.ini and set short_open_tag from Off to On and restart php-fpm.

service php5-fpm restart


This is how I solved it… simple issue to solve.

How to close session when browser is closed, in CodeIgniter?

We are building a small app for a non-lucrative, and we are using sessions on it – who doesn’t use it? -.
We need that when some user closes the browser the session must be destroyed.

This is how its done.

Open the geral config file application/config/config.php, search for $config[‘sess_expiration’]

$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_expire_on_close']	= FALSE;
$config['sess_encrypt_cookie']	= FALSE;
$config['sess_use_database']	= FALSE;

Change 7200 for -1. You should got something like

$config['sess_expiration'] = -1;

That should do the work! 🙂