Skip to Content

Getting started with PHP

My intention here is not to tell you how to program or anything like that, it’s simply to help you get started with the whole PHP thing that of course in terms of SAP.

Again, I’m no expert with PHP, in fact I guess you could say I am still a newbie myself. I’ve been playing around with it now for about 2 years and originally I said that I would avoid it. It just so happens that I’m flexible and I learned how flexible it was and things just took off from there. So let’s get to it shall we?

There are 3 things you need to get started with PHP for SAP development, oh and if you remember my bag you’ll know I am a big fan of those cost free solutions. So what are these three magical items?

image So please go out there and download each of those items so we can move along. So go ahead and install your apache server for example I have a partition on my system (T:) just for development it’s only 5GB in size but it’s more than enough. There I install the Apache HTTP server. Just the basic system install was all. Then I installed PHP, now I downloaded the PHP version 5 since for me it’s just playing around, I installed that under Apachephp. Then I configured the httpd.conf file located under apacheconf:

I’m not going to go through each line of the config just the ones related to connecting PHP to it.

I set the PHPRC variable, I believe this is only for the PHP 5 version but don’t quote me on that.

DocumentRoot “T:/websites”
SetEnv PHPRC T:/apache/php

Then I set my script alias so Apache knows what a .php file is.

ScriptAlias /php/ “T:/apache/php/”

Then of course to distinguish what a php script is I had to

AddType application/x-httpd-php .php .phtml

And of course the action for the type

Action application/x-httpd-php “/php/php-cgi.exe”

So with my Apache configuration all taken care of I jumped over to my PHP config. That’s the php.ini file located inder Apache/php. I didn’t do much at all to this file other than ensure that the extension directory was pointing to the right location and that the module for the SAPRFC was in place.

; Directory in which the loadable extensions (modules) reside.
extension_dir = “t:/apache/php/extensions”


Then I also copied the php_saprfc.dll to the extension directory from where I unpacked my SAPRFC download.

Now because I have this hooked to my Mini Me of WAS 6.20, the Saga continues…. system from this point I was done with what I needed to get started. However, if you don’t have the GUI installed please take a look at this Installing SAPRFC the topic of what needs to be done on the system has been covered there.

You’ll of course need to open up the example pages that come with SAPRFC and make some changes but you are basically all done and can get started. A nice quick example would be this one here:

SAPRFC-Class: Get List of Users in SAP-System

array( “ASHOST”=>”″ // application server ,”SYSNR”=>”00″ // system number ,”CLIENT”=>”000″ // client ,”USER”=>”cmehcr1″ // user ,”PASSWD”=>”xxxxxxx” // password ) ,”show_errors”=>false // let class printout errors ,”debug”=>false)) ; // detailed debugging information // Call-Function $result=$sap->callFunction(“SO_USER_LIST_READ”, array( array(“IMPORT”,”USER_GENERIC_NAME”,”*”), array(“TABLE”,”USER_DISPLAY_TAB”,array()) )); // Call successfull? if ($sap->getStatus() == SAPRFC_OK) { // Yes, print out the Userlist ?>”; } ?>

SAP-Name User-Nummer
“, $user[“SAPNAM”],” “,$user[“USRNO”],”

printStatus(); // or print your own error-message with the strings received from // $sap->getStatusText() or $sap->getStatusTextLong() } // Logoff/Close saprfc-connection LL/2001-08 $sap->logoff(); ?> 

So the example there is the standard one from SAPRFC, example_userlist.php, and so in order to use this you will need a few pieces from SAPRFC. OK, you really only need to ensure that the saprfc.php file is located. This file is the main class file containing all the little bits and pieces you need to connect.

// saprfc-class-library

or something like
// saprfc-class-library

So you don’t have to have copies of the file everywhere. Just remember it should be a relative path meaning within the same structure, I tried with and it just didn’t work perhaps one of those PHP experts might know a way do it?


As for editing and working with the files I tend to use whatever editor is handy at the moment whether it be Eclipse with PHP Eclipse or just plain old Notepad. There are a ton of editors out there for PHP and they vary in what they offer. I’ve been dealing with HTML and web based development for awhile so I tend to stick to Eclipse with PHP Eclipse mainly because I still do Java and Perl development. But if you are strictly PHP you might want to check out one of these editors, located at Snapfiles or jump over to there you’ll find some good links for editors as well.

Now that about covers all the basics of what you need to get started. From here you just have to learn how to program in PHP. For that you simple need to type “PHP tutorial” into your favorite search engine and you’ll find a million resources. As for the connection to the SAP system, that is a RFC function call, the function of course you’ll still need to program in ABAP.

With that I’ll leave you to playing around, watch for my next weblog in the next couple of days regarding PHP and SAP.

You must be Logged on to comment or reply to a post.
  • Hello,
      Just wanted to know what combination Apache,PHP and SAPRFC is required for me to get started.I have tried a lot of combinations from my end, but couldn't make it work.

    Sridhar Karra

      • Hello,
        I have tried out Apache 2.0.x, php5.0.3 and SAPRFC version.After doing all the setting either the server dosen't start up or it gives me an error.

        Sridhar Karra

        • What's the error? Or maybe you should just jump over to the PHP forum it would be easier to answer and help you there as opposed to the comments here.
          • Hello,
            Got the missing links....Thx a lot for the minimal configuration which you have provided.It has  helped me.Thx a lot again.
            Proper combination of PHP and SAPRFC is the key.i am using PHP 5.0.3 and the latest SAPRFC and apache server version 1.3.12.

            Sridhar Karra

  • Hi,
    I'm keen to try RFC and have installed the Mini Basis System (from ABAP Objects book) on Windows XP.
    Currently attempting to use Python. PHP is my next choice, although I would need to do a bit more setup. I'm having problems with logging in via RFC - keep getting:
    '103 - RFC_ERROR_LOGON_FAILURE You are not authorized to logon to the target system (error code 1).' with the user and password I am using (a valid dialog user). This appears to indicate that the user is invalid in some way for RFC access.

    I have set up this user with a role that has S_RFC as well as SAP_ALL, SAP_NEW to make testing easier. I seem to have missed something.

    This is very frustrating!

    How did you set up the user you use in the example here?

  • I have been working with php based frontend systems for a while now and have found WAMP ( to be an excellent integrated package.

    WAMP stands for Windows Apache MySql & PhP. Using it may save some effort in terms of downloading and installing.


  • Hello there,

    I have a problem running the php_saprfc.dll

    I uploaded it in my PHP extensions directory and when I try to start the service, I get this error message :

    >>PHP Startup: saprfc: Unable to initialize module
    >>Module compiled with module API=20050922
    >>PHP compiled with module API=20090626
    >>These options need to match

    I have this error with saprfc-1.4-5.1.1

    I tried with saprfc-1.4.1 (php_saprfc_530.dll) as well and then I get this error message :

    >>PHP Startup: saprfc: Unable to initialize module
    >>Module compiled with build ID=API20090626,TS
    >>PHP compiled with build ID=API20090626,TS,VC6
    >>These options need to match

    My system is :
    -Windows XP SP3
    -Apache 2.2.11
    -PHP 5.3.0

    Thank you for any fix or information


    Julien Matthey

      • OK so I downloaded and extracted the dll file to my PHP extention directory.

        Now I get this error message :

        >>PHP Startup: Unable to load dynamic library 'c:/wamp/bin/php/php5.3.0/ext/php_sapnwrfc-5.2.8.dll' La procédure spécifiée est introuvable.

        I am running this under 'localhost' with a Wamp server (yes in french...)

        • Hi Julien,

          as I can already see from the path of your PHP installation the SAP NW RFC DLL is not matching the PHP Version. Please try to get a matching PHP Version or try to compile it from the source. The standard alternative with PHP would be using WebServices.

          Best regards
          Gregor Wolf

          • Hello,

            Would PHPRFC work on an Open Suse Linux ?

            I am installing a new machine for this and I wonder which OS I can choose for this to work. It didn't work on my windows XP with Wamp server.

            Thank you for information.