Guide on how to install PHP XSLT extension on CentOS

    So you’ve got your CentOS server ready to roll. Go to install your PHP application, in my case, Symphony CMS, only to get a nice little message telling you that you need to install the PHP XSLT extension.

    Don’t despair, this should only take five minutes or so (from when you started reading this post, not the two hours prior!)

    Please note this solution requires that you have shell (sudo, preferably) access to your server.

    First thing to do is run:

    sudo yum update

    This will update all existing installed packages on your sever.

    The next thing to do is run the following:

    yum --disableexcludes=main list installed

    This will show you all installed packages including ones that might be excluded from general yum commands in your yum configuration file.

    You can check to see what is excluded in this file by running the following:

    vi /etc/yum.conf

    Depending on your hosting provider it will look something similar to this:

    [main]
    exclude=apache* bind-chroot courier* dovecot* exim* filesystem httpd* mod_ssl* mydns* mysql* nsd* perl* php* proftpd* pure-ftpd* ruby* spamassassin* squirrelmail*
    tolerant=1
    errorlevel=1
    cachedir=/var/cache/yum/$basearch/$releasever
    keepcache=0
    debuglevel=2
    logfile=/var/log/yum.log
    exactarch=1
    obsoletes=1
    gpgcheck=1
    plugins=1
    installonly_limit=5
    bugtracker_url=http://bugs.centos.org/set_project.php?project_id=16&ref=http://bugs.centos.org/bug_report_page.php?category=yum
    distroverpkg=centos-release
    
    #  This is the default, if you make this bigger yum won't see if the metadata
    # is newer on the remote and so you'll "gain" the bandwidth of not having to
    # download the new metadata and "pay" for it by yum not having correct
    # information.
    #  It is esp. important, to have correct metadata, for distributions like
    # Fedora which don't keep old packages around. If you don't like this checking
    # interupting your command line usage, it's much better to have something
    # manually check the metadata once an hour (yum-updatesd will do this).
    # metadata_expire=90m
    
    # PUT YOUR REPOS HERE OR IN separate files named file.repo
    # in /etc/yum.repos.d

    Note in the example file above the php packages are hidden on the second line.

    The package(s) you’ll need are php-xml and libxslt (depending on your architecture libxslt.i686 or libxslt.x86_64).

    To install these packages perform the following command (replacing libxslt.i686 with the required packages):

    yum --disableexcludes=main install libxslt.i686

    Once you’ve installed these you’ll need to find the following:

    find / -name "xsl.so"

    This searches your entire server for the xsl extension you’ve installed. Note the directory to this file. We are going to copy the file to your extension directory. The quickest way to find this is to phpinfo() the information.

    Create a php file and add the following line of code and save it to a web accessible directory.

    <?php phpinfo(); ?>

    When you view the file in the browser, look for the following line:

    Note this line down and then combine into the folowing command:

    cp -i /usr/lib64/php/modules/xsl.so /usr/local/lib/php/extensions/no-debug-non-zts-20090626/

    This will copy the extension from the original path to the extension directory.

    Now you need to add it to the php.ini file. You can find the location of this file in the phpinfo file you previously created.

    Now you’ll need to edit it:

    vi /usr/local/lib/php.ini

    Navigate the file until you find the section:

    ;;;;;;;;;;;;;;;;;;;;;;;;;
    ; Paths and Directories ;
    ;;;;;;;;;;;;;;;;;;;;;;;;;

    After this you shoud see a few lines down:

    ; Directory in which the loadable extensions (modules) reside.

    Behold, the the calling of extensions. You should see some existing calls such as extension = "pdo.so"

    You’ll just need to add a line in here:

    extension = "xsl.so"

    Once you’ve done that. Save the file.

    We’ll now need to reboot apache.

    service httpd restart

    That’s it. You should now have your XSLT extension installed and ready to use in PHP.

    Please note that this is just my experience on getting the extension installed and that server configs vary widely between hosting providers. Happy to help if you have any questions though.

    This post was last modified on %s = human-readable time difference 10:20 pm

    Dom Sammut: Dom Sammut is a PHP / Node.js Web Developer from Australia with extensive experience in developing in and customising Laravel, Express, VueJS, WordPress, Symphony CMS, Craft CMS and Squiz Matrix.

    View Comments (18)

    • This was helpful to read, but for me with Centos 6, php 5.3.3 this did not work.
      After several other tries (and failures but with each learned something new) what worked for me was ...
      yum install php-xml

      This
      1. installed the xsl.so in the correct /usr/lib64/php/modules directory
      2. Also installed other .so files similarly including dom.so
      3. identified libxslt as a dependency and installed it
      4. Added the necessary .ini files (to /etc/php.d) to match each php extension .so file

      • Hey Gautam,

        This tutorial was written for CentOS 6, but it shouldn't be drastically different for CentOS 7. I'd be happy to try and help if you could provide some more detail around the issue(s) you're encountering.

        Cheers
        Dom

    • Hi Dom,

      This is Bell. I follow your guide to install the xsl extension, but seems that this guide doesnt work for me. would you please help?

      • Hi Bell,

        I'll need some information like server setup, existing software packages, operating system and steps and trouble shooting you've attempted so far.

        Cheers
        Dom

    • when I tried to copy, the terminal shows cp: cannot stat `/usr/lib64/php/modules/xsl.so': No such file or directory
      In centos where are the folder? :C

      • Can you confirm that xsl.so file is actually present in that directory. Also ensure that there are no typos or any other discrepancies when entering the command.

        Additionally, when you ran: find / -name "xsl.so"

        What were the paths for the files that were listed?

              1. yes I reboot :C
              2. the version is CentOS 6
              3. no, in usr/lib64 (php folder does not exist :C)
              4. you mean /usr/local/lib/php/extensions/no-debug-non-zts-20100525 or in the php.ini?
            • In regards to number 3, can you run the following and look for a similar path to php modules find / -name modules -type d or find / -name php -type d. In regards to number 4, yes /usr/local/lib/php/extensions/no-debug-non-zts-20100525.

            • Hmm okay. A couple of questions:

              1. First off, seems silly, but have you tried rebooting your server / apache? Depending on the config (I'm not familiar with GoDaddy's) you might just need to restart.
              2. What version of CentOS are you using? I wrote this guide based on CentOS 6.5
              3. Can you navigate to /usr/lib64/php/modules/ and list what's currently in this directory
              4. Can you navigate to your php extension library directory and list what's currently in there: php-config --extension-dir
            • when I run yum --disableexcludes=main install libxslt.x86_64

              root@ip-97-74-198-51 [~]# yum --disableexcludes=main install libxslt.x86_64
              Loaded plugins: fastestmirror
              Loading mirror speeds from cached hostfile
              * base: s2plmirror02.prod.sdl2.secureserver.net
              * extras: s2plmirror02.prod.sdl2.secureserver.net
              * updates: s2plmirror02.prod.sdl2.secureserver.net
              base | 3.7 kB 00:00
              extras | 3.4 kB 00:00
              updates | 3.4 kB 00:00
              Setting up Install Process
              Package libxslt-1.1.26-2.el6_3.1.x86_64 already installed and latest version
              Nothing to do

              -----

              yum list libxslt

              root@ip-97-74-198-51 [~]# yum list libxslt
              Loaded plugins: fastestmirror
              Loading mirror speeds from cached hostfile
              * base: s2plmirror02.prod.sdl2.secureserver.net
              * extras: s2plmirror02.prod.sdl2.secureserver.net
              * updates: s2plmirror02.prod.sdl2.secureserver.net
              base | 3.7 kB 00:00
              extras | 3.4 kB 00:00
              updates | 3.4 kB 00:00
              Installed Packages
              libxslt.i686 1.1.26-2.el6_3.1 @base
              libxslt.x86_64 1.1.26-2.el6_3.1 @base

            • Loaded plugins: fastestmirror
              Loading mirror speeds from cached hostfile
              * base: s2plmirror02.prod.sdl2.secureserver.net
              * extras: s2plmirror02.prod.sdl2.secureserver.net
              * updates: s2plmirror02.prod.sdl2.secureserver.net
              base | 3.7 kB 00:00
              extras | 3.4 kB 00:00
              updates | 3.4 kB 00:00
              Setting up Install Process
              Package libxslt-1.1.26-2.el6_3.1.i686 already installed and latest version
              Nothing to do

            • Hmm okay. What about yum --disableexcludes=main install libxslt.x86_64 ? If that doesn't work, can you run yum list libxslt and see what list is returned. If you see an appropriate package there you can try install it. Who's your hosting provider?

    • thank you very much for this guide!
      but it's doesn't work when i finished, i copied the "xsl.so", edited “php.ini", and restart server, and tried many other methods and many times, it still not work.
      can you help me? please...

      • No problems. Can you confirm you’ve copied the xsl.so to the php extension directory. If you have a screenshot or link to view more information that would be great!

    Related Post