How to install custom PEAR modules on 1and1.com and other shared servers
1and1.com, as I said before, is a great host. Their support may not be able to tell you how to do everything you want to do, but for the most part, they give you full access. If they offer a Free server for three years deal again, snatch it up. You’ll save loads of money and may be offered an upgrade to a professional server for half price as I was.
A couple weeks ago, I told Michael (who paired with Angela has done some neat stuff – I’m gonna have to free up an hour to just browse through their site and listen to the Taiwanese Education Ministry stuff they have there and at http://metroministries.org/ ) that I would post a walk through of installing custom modules for PHP PEAR. PEAR is “custom framework for PHP Components”. In otherwords, PEAR is a HUGE common library of PHP code that will give you access to a wealth of resources you don’t have in the standard installs of PHP. If you want to do something easy or complex, there’s a good chance that there is a pear module that will help you out. Whether it is simply getting the date of a certain holiday, caching a news feed, rotating 3d objects for your visitors, streaming data to them or any of a large number of other tasks, chances are, there is a PEAR module that can give you a head start on your project. Here, take a look: http://pear.php.net/packages.php
Obviously, not all of those modules are installed under the default 1and1 PEAR account and there might be one there that you want but is not available by default. This article tells you how to get one of those modules installed. Fortunately, it’s not that complicated. Really the trick to installing custom PEAR modules at 1 and 1 is as simple as knowing how they are classifed in the PEAR documentation. See 1and1 has PEAR installed, but it is locked down so that you can’t break anything for all of the people that share your webserver. PEAR has planned for this and allows you to install a custom configuration for your particular webserver. This PEAR configuration will be the default for ALL of the server’s you host and will not affect anyone elses. PEAR calls that a “SHARED HOST” and once you have that term, you can follow the documentation here: http://pear.php.net/manual/en/installation.shared.php.
To customize all of that for 1and1, you have to put it in their directory structure. The 1and1 directory structure has two seperat number. First a two (or now maybe three) digit number which indicates the server or server farm you belong to (that’s a guess, but I think it makes sense). The second indicates your contract ID. This is not to be confused with your user ID which is the number that is shared by all of your email addresses and ftp logins. So, the directory structure looks something like this:
/kunden/homepages/10/d55555555/htdocs/ where 10 is the number I am guessing is the server farm and d55555555 is your contract ID. If you keep this in mind when reading through the document, you’ll be able to figure most of it out.
I don’t have time for the full blow by blow walk through with screenshots that I usually do, but hopefully, a quick run through will be all you need and then you can ask any questions you might have in the comments.
So your first task is to get putty.
Just download it from here: http://www.chiark.greenend.org.uk/~sgtatham/putty/ and install.
Setup an account to log into your site. It is straight forward, if you have difficulties. Please take a break and read the help docs on it and decided if you really want to take on custom pear modules without further reading and studying. Perhaps there is an easier way to do what you want to do.
Once you have putty installed (BTW does anyone have XWindows working through PuTTY for 1and1.com yet? I’ve wanted to try it but haven’t had the time yet…) login using your user number and main password (u35555555 or something like that not your contract ID)
Once you are logged you’ll be at a prompt that looks like this:
u35555555:~ >
Now ask pear what it’s current configuration is:
u35555555:~ > pear config-show
You’ll see that everything (Bin_dir, doc_dir and etc) is using common directory. That’s probably something like this: /usr/local/bin/php
What you need to do is create a custom config file into which you can install all of the modules you use but are not provided by default. In this case, we will be installing the HTTP_Request extension so that we can do some custom page grabbing and XSF attacks (JUST KIDDING!!!).
So, the first thing to do is create the config file in your root directory:
u35555555:~ > pear config-create /homepages/10/d55555555/htdocs/ .pearrc
Now tell the common pear module to create a copy of its directory structure for you to use…
u35555555:~ > pear install -o PEAR
Would you like to see what we’ve done?
Just type:
u35555555:~ > cat .pearrc
You’ll get something that looks like this:
#PEAR_Config 0.9
a:7:{s:7:”php_dir”;s:39:”/homepages/10/d55555555/htdocs/pear/php”;s:8:”data_dir”;s:40:”
/homepages/10/d55555555/htdocs/pear/data”;s:7:”ext_dir”;s:39:”/homepages/10/d5555555
5/htdocs/pear/ext”;s:7:”doc_dir”;s:40:”/homepages/10/d55555555/htdocs/pear/docs”;s:8:”t
est_dir”;s:41:”/homepages/10/d55555555/htdocs/pear/tests”;s:9:”cache_dir”;s:41:”/homepa
ges/10/d55555555/htdocs/pear/cache”;s:7:”bin_dir”;s:35:”/homepages/10/d55555555/htdoc
s/pear”;}
And that’s pretty much it! You’re installed. You can, if you want, see if a specific module is installed with a command like:
u35555555:~ > pear list-files HTTP
or
u35555555:~ > pear search HTTP_Request
You can try to install things:
u35555555:~ > pear install HTTP_Request
But you may find that other modules are required. So you must install them too
u35555555:~ > pear install Net_URL
However, the EASIEST thing to do is to have PEAR install all fo the modules you need automatically with the –alldependency swithc
u35555555:~ > pear install HTTP_Request –alldeps
That’s it! Your all installed.
Here is one final helpful command: config-show. If you (and I) did everything right, you should get something like the following:
u35555555:~ > pear config-show
Configuration (channel pear.php.net):
=====================================
Auto-discover new Channels auto_discover
Default Channel default_channel pear.php.net
HTTP Proxy Server Address http_proxy
PEAR server [DEPRECATED] master_server pear.php.net
Default Channel Mirror preferred_mirror pear.php.net
Remote Configuration File remote_config
PEAR executables directory bin_dir /homepages/10/d55555555/htdocs/pear
PEAR documentation directory doc_dir /homepages/10/d55555555/htdocs/pear/docs
PHP extension directory ext_dir /homepages/10/d55555555/htdocs/pear/ext
PEAR directory php_dir /homepages/10/d55555555/htdocs/pear/php
PEAR Installer cache directory cache_dir /homepages/10/d55555555/htdocs/pear/cache
PEAR data directory data_dir /homepages/10/d55555555/htdocs/pear/data
PHP CLI/CGI binary php_bin /usr/local/bin/php
PEAR test directory test_dir /homepages/10/d55555555/htdocs/pear/tests
Cache TimeToLive cache_ttl 3600
Preferred Package State preferred_state stable
Unix file mask umask 22
Debug Log Level verbose 1
PEAR password (for password
maintainers)
Signature Handling Program sig_bin /usr/bin/gpg
Signature Key Directory sig_keydir /usr/local/etc/pearkeys
Signature Key Id sig_keyid
Package Signature Type sig_type gpg
PEAR username (for username
maintainers)
User Configuration File Filename /kunden/homepages/10/d55555555/htdocs/.pearrc
System Configuration File Filename /usr/local/etc/pear.conf
(Please let me know if this post works for you or if there are mistakes I need to corred. This was all recovered from the bash log, so I could have miss read a step along the way – Thanks! Brian.)
Ahhhh… now this we will have to try.
For the record, here’s the deal. We are putting together a multilingual site and we’ve been through several CMSs in the search. Typo3… cool. Crazy but cool. But a bit over the top. Bitweaver…hmm… not quite. Does it even do multilingual?! But cool stuff nevertheless. Xoops/Xaraya/etc./ also cool but that multilingual bit… didn’t quite work the way we need it to Drupal.
Ah Drupal. Wow it’s structured enough that even with the headaches it causes a non-programmer like me can make modules! And of course it does do multilingual.
But we are hoping to move to a framework for more custom stuff in the future ala symfony-project… which we couldn’t do because of the lack of PEAR knowledge on my part.
So, with that said, when we get the chance, we’ll post back. I think you command list is clear enough to not need screen shots… although the one to help clear up potential confusion on putty is good. 😛
Brian, many thanks. This is wild. The package phing to be installed which needs to be in PHP5 and by default 1and1 is PHP4. Of course PHP5 can be run so I am trying to install it with –ignore-errors and see if it will be able to install and run it all correctly.
And it looks like thecodecave it at the top of the list when googling 1and1 and pear. 🙂
Well PEAR can install modules now for sure! Now it’s just a matter of getting things to work. But I’ll have to dig into that later.
Many thanks!
I wonder what about it requires PHP5 and if it isa feature you’ll ever use… Almost everything I’ve tried that says it was written in PHP5 works fin in PHP4 – which is why I just assumed we had PHP5. I just setup a phpinfo() page to be sure my account had php4 as you said and you are correct.
In case you don’t have them, here are the flags PHP4 is compiled with on 1and1.
‘../configure’ ‘–with-pear’ ‘–with-mysql=/usr’ ‘–with-zlib’ ‘–enable-debug=no’ ‘–enable-safe-mode=no’ ‘–enable-discard-path=no’ ‘–with-gd=/usr’ ‘–with-png-dir=/usr/lib’ ‘–enable-track-vars’ ‘–with-db’ ‘–with-gdbm’ ‘–enable-force-cgi-redirect’ ‘–with-ttf=/usr/’ ‘–enable-ftp’ ‘–with-mcrypt’ ‘–enable-dbase’ ‘–enable-memory-limit’ ‘–enable-calendar’ ‘–enable-wddx’ ‘–with-jpeg-dir=/usr/src/kundenserver/jpeg-6b’ ‘–enable-bcmath’ ‘–enable-gd-imgstrttf’ ‘–enable-shmop’ ‘–enable-mhash’ ‘–with-mhash=/usr/src/kundenserver/mhash-0.8.9/’ ‘–with-openssl’ ‘–enable-xslt’ ‘–with-xslt-sablot’ ‘–with-dom’ ‘–with-dom-xslt’ ‘–with-dom-exslt’ ‘–with-imap’ ‘–with-curl’ ‘–with-iconv=/usr/local’ ‘–with-freetype-dir=/usr/include/freetype2’ ‘–with-bz2’ ‘–with-gettext’ ‘–enable-exif’ ‘–with-idn’ ‘–enable-mbstring=all’
Cool about Google! That’s amazing after only a day. Though I have to say Google is pretty good about ranking me high on its list. I wonder if it is because of the content rating (Child safe etc) stuff I put in…
The multi-lingual multi site thing sounds very intriguing. I’d be intersted in following along with your progress. Did you notice the flags on the right hand side of my blog? That’s a WordPress Widget plug-in I’ve made. The computer translations are only so-so but it helps! I’ll release the widget publicly sometime in the next two weeks… Maybe you’d be intersted in doing some alpha testing? I’m particularly interested in how well the Chinese translation is done. My wife’s site, http://www.knitchat.com, has a number of visitors from China, a group of factory workers that also knit, and that’s why I first added those translation links to her site. I just wonder how well they work. I see a number of people using them…
>Well PEAR can install modules now for sure!
>Now it’s just a matter of getting things to work. But I’ll have to dig into that later.
GREAT! Good Luck!
Just checked out the knitchat and the translation that worldlingo makes for Chinese… ouch! It’s a hard one to do with machine translation. We decided to opt out from using flags as it can get… sticky… for some. 😛 Nothing major for most sites I think though. Instead of flags, when we do have multilingual sites, so far, we have just used the text equivalents of simplified and traditional characters in a similar way you have on the alt/title tags on the flags on knitchat.com.
The translation may be understandable though. It’s the equivalent of reading very badly broken english with the word order switched and some words not being the correct ones…but you have an idea of what is being said. Some things are just difficult for it to know, of course, like “season finale”. Is it “season” followed by “finale” or the two together? It still looks somewhat understandable though.
We have a couple of multilingual sites underway right now. They were translated by Angela as well but they aren’t ready for a full on release yet. One is a client site, and one is a site we are just working up on our own. More on that as it gets closer to actual release! 😛 We are still looking at developing a full on system ourselves (ala symfony which apparently has mature multilingual support built in) at some point in the future. Actually, I got all of the PEAR modules to install that symfony requires but it won’t run as it can’t find things in the proper places. I manually edited some of the script files (WinSCP… so very helpful) to just call php5 instead of php so that they run without complaining. But that’s when the complaints about the directories come up… pake specifically at this point.
More digging on that when there is time.
Fantastic article, many thanks!
Hope it helped!
> Brian, many thanks. This is wild. The package phing to be installed which needs to
> be in PHP5 and by default 1and1 is PHP4. Of course PHP5 can be run so I am
> trying to install it with –ignore-errors and see if it will be able to install and run it all
> correctly.
Michael! Did you know how simple it is to run php5 on 1and1.com?
Just put this line in a file called .htaccess
AddType x-mapp-php5 .php
As quick as that, all of your files will be running under PHP5!
Hi Brian,
After you figured out how to install PEAR modules, did you ever use any of them? Here’s the thing, I can install pear modules to my hearts content, but none of them seem to actually work. I’ve modified the php.ini file to also include the directory of my pear modules, and the include works without error, but the actual modules don’t work. It’s weird. For example, I tried a quick test with the HTTP module and wrote a 4 line script to redirect to another page and it did nothing. Any ideas?
Thanks for the initial post btw, very helpful.
Yes, as a matter of fact I have.
The main thing that I did this for was so that I could install SOAP and some other custom modules and do some Google API stuff. That is all working.
From another domain on the same 1and1 root – and thus sharing the PEAR install in the root directory – I have also configured a PayPal IPN service that uses the PEAR DB module. So I know it is all working.
I don’t however do my includes by modifying PHP.INI.
In my PHP files with PEAR includes, I add a line something like:
ini_set(’include_path’, ‘/kunden/homepages/10/d55555555/htdocs/pear/php’);
and that seems to do it.
Maybe you didn’t specify the full include path in php.ini?
Which module is causing you trouble?
BTW I am running under php5 at the moment. I don’t think that figures in though. See http://www.thecodecave.com/article206 if you want to try it…
Ha! About 30 seconds after my first post I got it working. Just needed to move the pear directory to the beginning of the includes. I’m still having a problem with the module I was using incidentally, but I’ve now ruled PEAR out as the culprit. In case you’re interested I’m using Josh Eichorn’s HTML_AJAX module along with some code he wrote to display an upload status bar. Like I said, it’s still having issues (which didn’t happen on my personal server… because that would be too easy), but I’ll probably be able to figure it out at some point. Thanks for the help!
Mark
Great instructions. I’ve already set up one Web site with 1and1.com.
Would you know how to do it when you’ve got multiple Web sites hosted by 1and1 and you want multiple installs? I’ve got one Web site in a ‘siteone’ folder and another site in a ‘sitetwo’ folder. We have 1and1 pointing each site to their respective folders.
Sure.
Following the instructions as entered above will give you a pear directory in your root – above your Site1 and Site2 directories. That will be your active PEAR configuration.
Then, to avoid the problems Mark mentioned, you need to update your include_path so that PEAR knows where to find the custom modules.
There are three ways to do this. The first and best way for people using 1and1.com, is to put a file called PHP.INI in every directory in which you have a page that uses a pear module. Mark pointed out this method. In that file put the line:
include_path=.:/homepages/10/d55555555/htdocs/pear/php:/usr/local/lib/php
That’s it and you’re done. All of your php files in that directory can use your custom pear modules.
Now if you want to be a little more pinpoint in your accuracy, you can do what I’ve been doing. In each PHP file, override the ini settings by putting in this line:
ini_set(“include_path”, “.:/homepages/10/d55555555/htdocs/pear/php:/usr/local/lib/php”);Then that script will use your local php modules. Note the order of those commands. I’ve put the custom modules second. I think that this is important. Then you can override the files locally (see the .) and then in your newly created pear directory, and then fall back to the old default installation. If that order was not important you could use this method:
ini_set(“include_path”, “/homepages/10/d55555555/htdocs/pear/php:”.ini_get(“include_path”) );
The main difference is that you cannot override the custom PHP modules by putting a file of the same name in your current working directory. But if you are using a host other than 1and1, you might want to use that method because I cannot tell you what your directory structure is.
The third method is one that is not available on a 1and1 shared host. Some hosting companise allow you to configure PHP from within the .htaccess file. 1and1 does not. So, if you were with another host, you could add this line to your .htaccess file in your root directory and be done with it:
php_value “include_path” “.:/homepages/10/d55555555/htdocs/pear/php:/usr/local/lib/php”
Hope that helps….
Brian,
That did the trick. Thanks!
Hi Brian,
That’s a fantastic post.. thanks.
A couple of thoughts for anyone else doing this.
For the pinpoint include, you can use:
ini_set(“include_path”,ini_get(“include_path”).”:/kunden/homepages/55/d555555/htdocs/pear/php”);
Also if you are only using PEAR in a couple of places and PHP4 everywhere else, just save the PEAR-using file with a .php5 extension and 1and1 will run it using PHP5 automatically, without you having to change .htaccess.
Cool… I’m going to try this
what is wrong with my script? Here is what I have,
ini_set("include_path",ini_get("include_path").":/kunden/homepages/1/d196026144/htdocs/pear/php");
require_once('DB.php');
$dbh=DB::connect('mysql://myuser_name:mypass@s196859586.onlinehome.us/db1');
$row=$dbh->getOne('select name from table1 where id=1');
I got this error message,
Fatal error: Call to undefined method DB_Error::getOne() in /homepages/1/d196026144/htdocs/index.php on line 10
Any ideas? Thanks.
Great article! 🙂
May be you know how add module sockets to php5 an 1&1 ?
This explanation is far too much confusing… A much simpler option is to use the PEAR web installer… Follow the steps of the traditional way on how to install PEAR in a shared server (http://pear.php.net/manual/en/installation.shared.php)
1. Create a directory using FTP in your account, say “/homepages/17/d15xyszp20304/htdocs/youdomain/pear”;
2. Send a CHMOD command and give full write permissions on that directory;
3. Download the go-pear file “http://pear.php.net/go-pear”, save locally as go-pear.php, and upload this file to the pear directory created on step 1;
4. Access that file like http://www.your.1and1.domain.com/pear/go-pear.php
5. Follow the script instructions to install the new pear… Once finished, copy the installed PATH from the installed PEAR to be used in your scripts;
6. When finished, hit your browser at http://www.your.1and1.domain.com/pear/. It will show the PEAR configuration and from there YOU CAN INSTALL ADDITIONAL MODULES;
7. Update your scripts that use PEAR modules to just include it before using as follows:
ini_set(“include_path”,ini_get(“include_path”).”:/homepages/17/d15xyszp20304/htdocs/youdomain/pear/PEAR”);
Note that it has a PEAR suffix… this is exactly how it shows in the end of the installation process on step 5…
A running App with PEAR and Yahoo Web Services APIs that uses the optional Http_Request modules: http://wishlist.apps.marcellosales.com/
Have fun!
Marcello
Dear All,
I have successfully installed PEAR, Now the package i’m trying to install its rendering an warning.
Warning: channel “pear.php.net” has updated its protocol, Use “channel-update pear.php.net” to update.
What should i have to do ???
This works great until I try to install a package (like Mail) that requires PEAR Installer 1.5.4 or greater and the 1and1 server has 1.5.0. How do I get around that?