1

I have an account with bluehost that gives me ssh access, but no sudo, so I cannot use yum (it’s a CentOS server).

I want to run a script that depends on phantomjs, but it fails, apparently because I do not have access to freetype and fontconfig. Contacting them, they’ve told me

Sounds like we have both of the font libraries needed, but because this is not a software we provide for you, support for it is limited.

When asking if there was no way to do it, they replied with

It might be possible, but we won't provide any support for it or set it up for you.

So my question is how can I install those libraries independently (preferably already compiled/ready), and make phantomjs use them?

user137369
  • 4,260
  • 5
  • 25
  • 49

2 Answers2

1

One possibility is to load the auxiliary libraries that you need into a “private” location, and then alter the headers of your program to search that location.

Mimic your target environment

  • Install a VM on your own machine running the same CentOS build as the hosting company. This means the same CentOS release and same CPU architecture. (cat /etc/*-release should give you the one piece of information; uname -a will give you the other. Specifically, you want to ensure that you have a similar/same C library version; /lib/libc.so.? should be executable and give you some details about the C library in use.)
  • Install the requisite packages using YUM on your virtual host.
  • Ensure that your binary executable works.

Figure out what the target environment is missing

  • Run ldd /usr/bin/your-app to obtain the list of libraries to which it refers. Specifically, to clean up that list: ldd /usr/bin/your-app | cut -d '(' -f 1 | cut -d '>' -f 2 | sed -e 's,[ \t],,g' | sort | uniq > my-required-libs

  • Log in to the remote server and copy the file over; then run something like:

    #!/bin/sh

    missing-libs for lib in $(< my-required-libs ) do if [ -f "$lib" ] then echo "OK $lib" else echo "NO $lib" echo "$lib" >> missing-libs fi done

  • Copy missing-libs back to your virtual host and mkdir a folder named e.g. ~/my-app/lib; then cp $(<missing-libs) /home/myself/my-app/lib

NOTE, that you will need to create this exact path on your shared host, including the user name and so forth — so if your writable directory on the shared host is /home/myself make sure that this directory is under /home/myself on the virtual host as well.

Alter the executable's RPATH to point to your alternate library location

  • Find your application executable file and alter its headers using chrpath (you will probably need to yum install chrpath in your virtual machine, as this is an unusual program to need):

    chrpath --list /usr/bin/your-app

    If that reports any existing RPATH, then you'll want to PREPEND the path ~/my-app/lib to that RPATH with a : — e.g. if chrpath --list showed /usr/lib/my-app/plugins you might use /home/myself/my-app/lib:/usr/lib/my-app/plugins. In the more usual case, just use --replace with the name of the directory into which you've copied the prerequisite libraries.

    chrpath --replace ~/my-app/lib /usr/bin/your-app

  • Now, copy the executable with the new RPATH and the directory full of supporting libraries to your shared host.

This is all “friendly” to a multi-user shared-hosting set-up, unlike other solutions using e.g. chroot jails.

Alternatively, create an LD_LIBRARY_PATH wrapper

If chrpath doesn't work for your set-up (e.g. extremely strict SELinux contexts), you may be able to skip the chrpath step and instead do something like:

  mv ~/my-app/bin/my-app ~/my-app/bin/my-app.real

and make a wrapper script like

  #!/bin/sh
  export LD_LIBRARY_PATH=/home/myself/my-app/lib
  exec /home/myself/my-app/bin/my-app.real

… and replace the original binary's name with this script.

Note, in theory, you can replace almost any library this way, but when libraries require data files in particular places (e.g. /etc) or dynamically invoke sub-libraries from system locations (e.g. /usr/lib64), you may be faced with having to recompile them with new paths in their ./configure scripts or editing their sources in ways that are probably not worth the effort in all but the most extreme cases.

EG: Things that are unfriendly to relocating in this way: libc and Pluggable Authentication Modules.

BRPocock
  • 13,043
  • 3
  • 26
  • 47
  • I’s been years since I’ve used a VM, and even then it was only VMWare (briefly) and Virtualbox. Wouldn’t a VM use a bunch of resources? There’s probably some VM solution that I’m not aware of, for this. I was thinking of something like [docker](https://www.docker.io/) but that seems like it needs sudo as well. Why do you say `chroot` would be unfriendly for this (other than it needing sudo as well, so it wouldn’t work, anyway)? – user137369 Jan 22 '14 at 00:37
  • I was successful with a variant of this solution, and this really helped me get there. Thank you – user137369 Jan 22 '14 at 02:51
  • Sorry, clarification, the VM is a temporary thing on your local machine, assuming you don't have a spare machine you can use for the mock-system. And, yes, `sudo` is why `chroot` would be difficult to use here, as well as requiring contortions to run the `chroot`ed app from outside of its jail sometimes – BRPocock Jan 22 '14 at 03:27
0

It sounds like you need the help of the hosting company if you cannot run YUM to install the packages yourself. In Linux you cannot install anything unless you can sudo or become root. If they won't help you (from what it sounds) then I would move to a VPS instead of a shared host. This will give you the flexibility to run YUM and make the changes you need to the server at the admin level.

*The reason they won't give you sudo or root level access on a shared machine is because you have admin power at that point and can access anyone's data on that server or even make configuration changes to lets say... network cards, storage, etc.

Source: Worked for a large hosting company for many years

  • I certainly understand why they won’t do it, but that does not mean it cannot be done. Software that is available through `yum` can be installed without root access manually, they just get locked down to a single user (no problem here). I do not *need* `yum`, I just need those libraries — what I’m asking is how to install them. – user137369 Jan 21 '14 at 17:39
  • Have you tried building it from source? It might let you do that depending on what security settings have in place. Next question would be if they say it's there is does it show up in phpinfo? Like this: FreeType Support => enabled FreeType Linkage => with freetype FreeType Version => 2.3.7 – Chris Conkright Jan 21 '14 at 17:50
  • Yes, freetype shows in phpinfo. I haven’t tried compiling from source, mainly because I wouldn’t know what to do with them after (how/where to set them up so that phantomjs sees and uses them). – user137369 Jan 21 '14 at 18:10