Prologue (not necessary to accomplish solution but good info about general configuration if you are a newbie):
This blog post will explain how to get the GD extension working on your lamp stack on your Ubuntu box.
If you are like me, new to Ubuntu, and you wanted to just get a local server up you installed Apache, PHP and MySQL by using the amazingly easy "apt-get install" command. While this is great for getting a basic server up, you might find that certain more exotic features you are used to don't work. The first time this happened to me was when an image resize script which relied on the GD extension suddenly didn't work.
I spent 5 hours trolling the internet for a solution. Many folks said that you need to run "sudo apt-get install php5-gd". While this is true it is only half the battle. The other half, while super duper obvious to an experienced LAMP administrator is not obvious to a newbie. You need to go into the php.ini file and add (or possibly uncomment) a line which says "extension=gd.so". This is not to be confused with "extension=gd.dll". "gd.dll" will not work. At least it didn't with my configuration.
In order to alter the php.ini file you will of course first need to find it. It is located at "/etc/php5/apache2/php.ini" on my system and I assume that it will be a similar location on other distros of Ubuntu.
So now that I have explained the basic process, the following are the quick and dirty steps to get it done.
STEPS
1. Open a terminal window
2. Run the command "sudo apt-get install php5-gd" (if you use php4 you will want to type "php4-gd" in place of "php5-gd")
3. Wait for the package to install. Type "y" if necessary if you are prompted with how much disk space will be used.
4. Once the php5-gd package is installed, type sudo gedit /etc/php5/apache2/php.ini (NOTE: If the text editor opens blank it means that you have the wrong directory location for the php.ini file. This means that you are going to need to dig around a bit to find the file. Do try to use the above path as a guide of where to look)
5. Add the line "extension=gd.so" to the php.ini file. This line can go virtually anywhere in the file but you will probably want to place it somewhere logical. The section titled "Dynamic Extensions" is a good choice since this is where this line should technically be.
You might want to search for it with the text editor's search feature. If you find it but it has a semicolon in front of it that simply means that it is "commented out" (i.e. when it is read by PHP on startup that line is ignored). Thus that line, as far as PHP is concerned, doesn't exist. It is best to uncomment that line if you find it INSTEAD of adding another line.
While you are working in the php.ini file just remember that you only want to add a single line "extension=gd.so" without a semicolon before it or uncomment that line if you find it in the file. You DO NOT want to modify anything else or PHP may begin to behave strangely or simply not work.
When you are done, save and close the file.
5. Final step. Go back to the command line and type "sudo /etc/init.d/apache2 restart". Once again the exact thing to type will depend on your server type and distro number but that should be a good general model of the specific command you will use. You might get certain error messages when you restart Apache. They probably don't matter unless you are running a production server and, if you are running a production server and just had to read this explanation, god help us all!
Hopefully this tutorial has shown you how to get GD up and running. Or at least given you some new ideas about how to fix your GD extension blues. Good luck.
Tuesday, April 13, 2010
Monday, November 9, 2009
Welcome to nothing but errors!
As I develop web applications (with PHP, MySQL and Javascript) I commonly come across interesting and difficult to resolve errors. I almost invariably find the solution to my issue after hours of a combination of searching, trying, failing and trying again.
Therefore, I have created this blog with the web development community in mind to share some of the solutions to strange problems and interesting ways to achieve solutions which I have found so that others are spared from the same agonizing process.
This blog is more an adhoc set of tips and tricks than a set of tutorials although small tutorial style posts may be included from time to time.
Welcome and happy coding!
Therefore, I have created this blog with the web development community in mind to share some of the solutions to strange problems and interesting ways to achieve solutions which I have found so that others are spared from the same agonizing process.
This blog is more an adhoc set of tips and tricks than a set of tutorials although small tutorial style posts may be included from time to time.
Welcome and happy coding!
Subscribe to:
Posts (Atom)