Category Archives: PHP


I just thought that I would post this because I ran into this issue earlier today. If you’re wanting to enable SQLite in PHP you’ll have to edit your php.ini file and uncomment the line (removing the initial semicolon) that looks like this:


And the line that looks like this:


Basically, SQLite requires the PDO module to be loaded in order for it to work. This may seem an obvious solution to some (albeit somewhat awkward), but it caused me some annoyance. Anyway, hope that helps someone out.

Setting Up the Symfony Framework on MediaTemple’s Grid Server

Introduction and Disclaimer

Before I begin I should probably mention that this will take quite a bit of time, potentially up to an hour or more; so make sure you set aside enough time to do this. Also, I’d like to point out that Media Temple has an excellent tutorial and the official documentation may be found on the Symfony website.

A lot of this information can be found elsewhere on the internet, but I haven’t really seen a complete/concise walkthrough on setting up and configuring Symfony to work with MediaTemple‘s Grid Server, so I’m writing my own. The following instructions are written from the perspective of a Windows PC user, but – for the most part – everything should be pretty much the same on OSX or Linux. Keep in mind that you should only do this if you know what you’re doing. You could potentially mess up your web server if you’re not careful; also keep in mind that these instructions may not apply to all server configurations. Don’t blame me if you end up screwing up your server.

First and Foremost


Before you can even get started you have to make sure that your server is configured properly. Make sure that the Primary PHP Version is set to PHP 5. You can do this by selecting your target domain from the domains tab, then click on PHP Settings and select PHP 5 and press save at the bottom.

SSH Access

The next thing you need to make sure to do is enabled SSH access to your MediaTemple account. Still on the control panel page press the Server Administrator button/cell and make sure that under the SSH Option section that you select enabled. Save your settings.

Server Number: You’ll need to know your MediaTemple server number. In order to find out what your server number is, go the the Account Center control panel and click on the Server Guide button/cell. On the next page click the “System Paths” link in the third column. You should see a page that lists all of your server paths, environment variables, etc. You should see a line titled System path with a value of something like: “home/####/domains/” write down the number that comes after “home/” and before “/domains”; that’s your server number, it could be four or five digits (maybe more).

SSH Client

Now that you SSH access you’ll need a client to utilize its power. Mac users should have already have a client pre-installed on their OS (Applications>Utilities>Terminal). Unix/linux users should already know how to do this. For Windows users, I recommend using Putty; but if you have a preferred client feel free to use it. You can download the Putty client at Select the version that applies to your version of Windows (select the putty.exe file, not one of the other options). Whenever the Putty client finishes downloading, put the .exe file into your Windows folder (most likely C:\Windows); create a shortcut (right-click > “create shortcut”) and drag the shortcut to your desktop, start menu, wherever you want it.

Connecting to the Server


Launch Putty (or your SSH client) from your shortcut, put your website hostname ( or IP address into the hostname field – make sure the SSH option is selected and that the port number is correct – then click “open” on the bottom. If you haven’t connected to your server with the SSH client before you’ll get a “The server’s host key is not cached in the registry” alert. Click “Yes” to continue.

Logging In

Put in your username (it should be, press enter, then type in your password and press enter. If after logging in the client immediately closes or you get a “Connection closed by remote host” alert, it’s because you didn’t set your “SSH option” to enabled in the MediaTemple Account Center or you forgot to save your settings after you did so. If this happens to you, change your settings and try logging in again. After logging in successfully you should see a prompt with something like (except the *asterisks* will be an alphanumeric combination):****:~$

Installing Custom Pear Packages

Fortunately Pear comes as a global pre-install with MediaTemple’s Grid Servers, so that saves us a step (kind of); but because we’re adding a custom package/module we need to manually create an install copy in the server’s home directory.

Pear Install

Before we install/copy Pear we need to create a configuration file. Make sure that you’re still logged in with your SSH client (log in again if you’re not) and generate a configuration file for your home directory by typing in the following:

/usr/local/pear/bin/pear config-create $PWD .pearrc

Double check your spelling. If you did everything correctly you should see a list of files scroll past and the last line of text should read “Successfully created default configuration file”, etc. Now you’ll need to run the install:

/usr/local/pear/bin/pear install -o PEAR

Be sure to double check everything and make sure you don’t misspell anything. If you typed in everything correctly you’ll see a series of lines scroll past with things like “Downloading Console_Getopt”, “Downloading Structures_Graph”, etc. and then a few lines that say “install ok: channel://” and so on.

Bash Profile

So that you don’t have to type the full path to Pear in every time we’ll create a .bash_profile in order to make things more efficient. Check to see if a .bash_profile file already exists (chances are it doesn’t) by typing in the following:

ls -a

If you have a .bash_profile file in there already, fine, if you don’t also fine. You can do this next part one of two ways; you can use the Vi editor, or you can “concatenate” or “echo” the text directly into the file. If .bash_profile already exists you should use the Vi editor to make sure you’re not adding something that’s already there.

Vi Editor Method

Launch the Vi editor within your SSH client by typing in:

vi .bash_profile

This should “clear” the screen except for a line at the bottom that says something like:

".bash_profile" [New File]

The Vi editor defaults to “Command Mode”, be sure to press “i” on your keyboard to switch to “INSERT” mode. You’ll be able to tell because the bottom line changes to “– INSERT –”. Now type:

export PATH=$PATH:/home/####/users/.home/pear/

Be sure to replace the #### symbols with the server number you wrote down earlier. Double check your spelling and press the Escape (ESC) key on your keyboard, this will put you back in “Command Mode”. Hold down the Shift key (SHIFT) on your keyboard and press “ZZ” (make sure you press “Z” twice); again: “SHIFT+ZZ”. If you did everything correctly it should take you back to the shell prompt.

Go ahead and make sure that the file is there by displaying a directory listing:

ls -a

It should look just like it did earlier except now there’s a “.bash_profile” file in there.

Concatenation Method

If the .bash_profile file doesn’t exist in the current directory, at the SSH prompt type in:

touch .bash_profile

Press Enter. This will create a .bash_profile file for you. Next type in the following:

echo export 'PATH=$PATH:/home/####/users/.home/pear/' >> ~/.bash_profile

You can make sure that everything worked by typing in:

cat ~/.bash_profile

If you did everything properly it should basically just echo back the contents of the file.

Verifying the Profile

Now you can install Pear packages without having to type in the full path. Let’s run a test by installing/updating the mail package:

pear install -o Mail

It should scroll a few lines saying “Downloading”, etc. and end with “install ok: channel://” and so on, just like when we copied/installed Pear to the home directory.

Editing the PHP.INI File

If you’re not logged into the MediaTemple Account Center anymore, be sure to log back in for this next segment. From the Account Center control panel click on the “File Manager” button/cell. On that page, click into the “etc” folder. Once inside the “etc” folder you should see a file titled “php.ini.sample”, click it to open it and edit it. By the way, I would recommend that you copy everything that’s in that text box and make a backup somewhere on your computer, just in case you accidentally mess something up and have to go back to the default settings.

Scroll down to the very bottom and add the following line:

include_path = ".:/home/####/users/.home/pear/php"

Be sure to change the #### to your server number. If you want, feel free to add a comment (start the line with a semi-colon “;”) that says something like “pear include path”. Finally, change “php.ini.sample” to php.ini”. If you don’t do this, your settings won’t take effect. Click “save changes” to save the file.
Some users may prefer to change the include path on a directory-by-directory basis via an .htaccess file or on a script-by-script (.php file) basis but I wouldn’t recommend it unless you know what you’re doing. If you made the changes to your php.ini file as instructed above go ahead and skip to the next section, otherwise – if you’re wanting to go about it a different way – read the next few of paragraphs.
If you want to do it via .htaccess files (keep in mind this only affects .php files within that directory) add the following line to the .htaccess file in your target directory (remember to change the #### values to your server number):

php_value include_path /home/####/users/.home/pear/php'

If you’re wanting to change your include directive on a script-by-script basis, add the following somewhere near the top (probably before any ‘include’ commands):


Be sure – this is getting redundant, I know – to change the #### values to your server number.

Preparing to Install Symfony

Okay, we’re about half way done (I told you this would take a while). By the time you’ve gone through all of this your SSH client has probably timed out and aborted the connection, if this is case go ahead and log back in. If your client has not timed out type in “clear” and press enter to clear the screen (if you had to log back in, go ahead and do this as well).

You’ll have to make sure that the command-prompt is running as PHP5, to do this you’ll have to update your .bash_profile file again. There are two methods to doing this, as mentioned before. In this instance, I’m going to use the concatenation method:

echo export 'PATH=/usr/local/php5/bin:$PATH:/home/####/users/.home/pear'  >> ~/.bash_profile

WARNING: Make sure not to insert a carriage return or line break when entering the above two lines. The code above is merely wrapping.

Type that into your SSH client and make sure to replace the #### with your server number. Double check that everything is typed correctly, it’s a pretty lengthy line.

If you’re wanting to use Vi to input that, it’s the same except you don’t need to type “echo” or the “>> ~/.bash_profile”, nor do you need to put single quotes around the path.
To make sure that everything worked correctly type:

cat ~/.bash_profile

If you typed everything in correctly, it should echo the contents of .bash_profile out to you. The last line is the part that you just added.

Before we move on, you’ll need to refresh the shell environment variables, type:

source ~/.bash_profile

Installing Symfony


Before installing Symfony you have to “discover” it through pear, type in:

pear channel-discover

After a slight pause, you should see a couple of lines that say: “Adding Channel succeeded” and “Discovery of channel succeeded”. Now with the next part you can either choose to install the latest stable release of Symfony or the “nightly builds” (beta releases); I recommend using the stable release.

For the stable release (recommended), type:

pear install symfony/symfony

For the “nightly build”:

pear install symfony/symfony-beta

You should see some text that says “starting to download symfony” then a progressing load, and finally, “install ok: channel://”.

This next part can be a little tricky so follow along closely.

Initializing a Symfony Project

After completing the previous section, Symfony is officially installed on your server; but, before you can use it you have to initialize a project and an application. The following steps will walk you through setting up a “symfony” subdomain which you can use to play with your Symfony installation. If you don’t want to create a subdomain you don’t have to.

To create a subdomain type:

mkdir ~/domains/

Obviously change “” to whatever your site may be (“”, “”, etc.). Next create a “symfony” directory:

mkdir ~/domains/

If you didn’t create a subdomain replace “” with simply “”. Now within the “symfony” directory create a directory called “web”:

mkdir ~/domains/

The reason we created these two directories is so that we can establish a symbolic link “SymLink” from the newly created “web” folder to the root “html” folder. Type in the following (be absolutely sure to type this in correctly):

cd ~/domains/
ln -s symfony/web html

Again, if you didn’t create a subdomain instead of “” it will be just “”. The reason this is necessary is because Symfony’s default folder structure is different from MediaTemple’s structure, so we have to create a “SymLink” that will basically redirect the framework to the required files.

You may have noticed that after typing “cd ~/domains/” that the prompt changed; that’s because you’ve moved into another directory, which is what is supposed to happen. Now that that’s done we need to actually “initialize” our Symfony project. Make sure that the prompt displays (note the word “symfony” at the end):****:~/domains/$

If it doesn’t type (if you didn’t create a subdomain – “” instead of “”):

cd ~/domains/

Now, at the SSH shell type:

symfony init-project myproject

Feel free to change “myproject” to whatever you want (e.g., “test”, “demo”, “default”, etc.). You should see a series of lines scroll by, if you typed everything correctly. Now type in the following:

symfony init-app myapp

Again, feel free to change “myapp” to whatever you wish, just make sure to be consistent.

If you’ve created a subdomain you have to make sure to add an .htaccess file in your “symfony/web” directory that adds a php5 script handler. To do this just type:

echo 'Options +FollowSymLinks +ExecCGI' >> ~/domains/
echo 'AddHandler php5-script .php' >> ~/domains/

WARNING: Make sure not to insert a carriage return or line break when entering the above two lines. The code above is merely wrapping.

Be sure to type this accurately (note the spaces and periods carefully) otherwise you’ll get a “500 Internal Server Error”. Again, if you prefer to use Vi to add those two lines to the end, it’s up to you.
Now go and test your work: (or just if you didn’t create the subdomain).

Where Are the Media Files?

If for some reason you’re not seeing the stylesheet, images, etc. It’s because the “sf” files didn’t get copied over, I’m not sure why this happens, but there’s an easy fix. In your SSH shell type:

cp -r ~/pear/data/symfony/web/sf ~/domains/

WARNING: Make sure not to insert a carriage return or line break when entering the above two lines. The code above is merely wrapping.

Be sure to type all of that in carefully. Also if you didn’t create a subdomain change “” to simply “”.

Now go and test your work: (or just if you didn’t create the subdomain). Everything should be up and running smoothly. Congratulations, you’re finished.

Apache, Automatic Directory Listings

I recently formatted my PC – because it had begun to take forever to boot up. There have been instances where I would, literally, wait two minutes just to get to the desktop. I figured that the cause of my problem was possibly due to my system registry being packed with ancient entries, etc. – due to previously installed software and/or the fact that I was running out of hard disk space. The solution? Backup and format.

To get to the point… Because I re-started with a fresh OS install, I had to re-install Apache, MySQL, and PHP. I’ve done this several times in the past so everything was relatively easy to do. <non-sequitur> I typically use binaries (setup.exe) for my Apache and MySQL installations, and manual installation for PHP.</non-sequitur> I have never spent much time playing around with Apache because I either did not feel the need to and/or did not really have the time to do so. Anyway, after installing WordPress 2.0 (on the local host) I noticed that all index (i.e., “index.php”) references had been replaced with backslashes (“/”), which is fine, except that my Apache installation had not been configured to handle backslashes in a desirable way, instead, every backslash would show a directory listing. Not only is this insecure, it’s not a very efficient way to browse through a web site.

Wanting to alter this default behavior, I delved into the Apache manual that came with my installation (a somewhat daunting and intimidating task). After a while I happened upon a section dealing with automatic directory listings, apparently to disable this feature all that is needed is to add the following to my configuration (httpd.conf) file:

<Directory /path/to/directory>
Options -Indexes

Because something similar already existed, I merely added “Options -Indexes” and restarted my Apache server to see if that solved the problem. Well, it did, but instead of displaying the directory contents my server gave me a 403 – Forbidden error; which solves the problem, but creates another. I obviously needed to take this one step further.

Delving a bit further a noticed a reference to backslashes, directories and mod_dir.c; I read the entry and after doing the wrong thing for a while tried added the following after the “Options -Indexes” line in httpd.conf and restarted Apache again:

DirectoryIndex index.html index.htm index.php

And that fixed it. Cool. The complete segment:

<Directory /path/to/directory>
Options -Indexes
DirectoryIndex index.html index.htm index.php

I was glad that I checked the manual because I did not want to waste hours searching the internet for a solution. Anyway, I just thought that I would share my experience; enjoy.

PHP and Sessions

I don’t know how many people have had this particular problem, but I know I’m not the only one. Two weeks ago I encountered a strange issue when using session_start() with PHP; the method call was not setting/creating a cookie, so I couldn’t access my session variables. I went to and found several answers. I’m pretty sure this only applies to people who have are running this on their own server; ergo, hosting companies won’t have (or have already remedied) this issue.

I use PHP ver. 4.4.1 so I don’t know if this applies to versions 5+, but if you encounter the same problem, try one (or all) of the following:

  • Check to see if your php.ini file has a slash at the end of the session.cookie_path setting (e.g., “session.cookie_path = /”). Remove it so that it becomes “session.cookie_path =”. Apparently, the slash is read as an escape character, which would, obviously, cause issues.
  • Make sure that session_start() is the very first command in your document; above <html> and the <doctype>. This may seem obvious, but not an unlikely mistake.
  • You may need to implement a compact privacy policy, more info here: P3P, Cookies and IE6.0: A Case Study.

If you’ve been having the same problem and none of the above suggestions have helped, try looking for a solution at, if that doesn’t work for you, well, you can always Google it.