29
CodeIgniter Blank Page Fix: Blank webpage when setting up CodeIgniter, PHP, MySQL, and Apache
Today, I created my first website using the Code Igniter PHP framework and, oh boy, do I like it a lot more than Ruby on Rails. But I’ll dig into that further in a future post.
The purpose of this post is to shed some light on a problem that I wracked my brain over for a few hours last night.
Have you found this post helpful?
If so, I'd appreciate if you could indicate so by pressing the Google Plus button below.
The problem: After installing Apache, PHP, and MySQL and configuring the Code Igniter framework, you get a blank web page when testing your first controller, model, and view.
What I discovered were two issues that, when combined, create the perfect storm of an installation problem:
- First, MySQL is no longer enabled by default with PHP 5. Says the PHP website of MySQL in PHP 5:
MySQL is no longer enabled by default, so the php_mysql.dll DLL must be enabled inside of php.ini. Also, PHP needs access to the MySQL client library. A file named libmysql.dll is included in the Windows PHP distribution and in order for PHP to talk to MySQL this file needs to be available to the Windows systems PATH.
It’s been a LONG time since I’ve programmed in PHP let alone installed PHP, so this was news to me. Anyway, if check out the MySQL installation notes on the PHP website if you need help enabling MySQL.
- Unfortunately, that was the easy part. Once I had an error message to work with, Google lead me to the PHP website, and I was in the clear. But, for the longest time, I wasn’t even getting an error page. Remember, all I was getting was a blank HTML page. So what was the cause? Code Igniter…
- Using some creatively placed die() calls, I found out that the application was dying when trying to connect to the database. (Previous to this, I had already double- and triple-checked my MySQL username and password in the Code Igniter configuration file, and had even tried out alternate accounts, like my MySQL root account.)What I found out was that the MySQL drivers in Code Igniter were suppressing errors when attempting database connections.
This is what the code looks like in the Code Igniter mysql_driver.php file:
The “@” symbol before the mysql_connect() function call supresses any errors that may be returned. It is that symbol that wasted a good 2 hours of my life.Anyway, after I removed the “@” symbol from the code and re-tested my web application, PHP spit out the error message that I should have been presented with hours ago, and I was well on my way to fixing the problem.
function db_connect()
{
if ($this->port != '')
{
$this->hostname .= ':'.$this->port;
}
return @mysql_connect($this->hostname, $this->username, $this->password, TRUE);
}
If you’re experiencing the same problem that I was, I hope this helps you correct it faster than I did! Best of luck.
Oh, and did I mention how much I prefer Code Igniter over Ruby on Rails? It’s messier, but with my C and Java background, it makes more sense than Ruby and Ruby on Rails does!
Related posts:
2 Comments to “CodeIgniter Blank Page Fix: Blank webpage when setting up CodeIgniter, PHP, MySQL, and Apache”
Post comment
Recommended Services
Recent Posts
- Fantastic new corporate themes for WordPress
- Vistaprint offers FREE t-shirts, too!
- 80+ “Your Ad Here” 125 x 125 banners
- 5 Minute Long Tail SEO Drill: More Traffic, Better SERPs
- iPhone and iPod Touch app statistics: OS adoption, purchasing rates
Recent Comments
- Neerav on Using JavaScript to validate one or more grouped checkboxes
- Jacob on Using JavaScript to validate one or more grouped checkboxes
- kaify on Using JavaScript to validate one or more grouped checkboxes
- JC Goldenstein on How To: Cloak your Affiliate Links for Free in Under 3 Seconds
- Bail Bonds Los Angeles on Amazon Web Services on Rails
Categories
- .net
- acoustic guitar
- affiliate marketing
- ajax
- amazon associates
- blogging
- books
- business ideas
- c#
- code igniter
- dealdotcom
- google adsense
- google adwords
- internet marketing
- iPhone
- javascript
- leadership
- make money online
- mortgage goal
- msn adcenter
- networking
- personal development
- php
- ppc
- ruby
- ruby on rails
- seo
- text-link-ads
- web development
- yahoo search marketing





Steve van Bodegraven says:
Thanks Rory! Great post.
I wasted > 2 hours trying to figure out why I was receiving a blank page when connecting to a database and without this post I would have wasted countless hours more. Cheers.
Andy says:
Same issue, just for PostgreSQL. Thanks for this!
Finally found this post myself after about 2 hours, heh. The google search terms that were failing for me were things like “codeigniter dying without error message” and “codeigniter silent exit”. Hopefully this’ll help others find it! :)