Since CAS is capable of integrating applications made in many different languages, you may want to take the time to get everything you can authenticating through it. Every different language needs a separate client though, which needs to be installed and configured. The official client for PHP is phpCAS. The instructions I have here were originally done in 3.4.8 of CAS and 1.2.2 of phpCAS on the 11.04 version of Ubuntu. If you’re using a different flavor of linux the commands may differ slightly, and if you’re using Windows, all of the example directories and commands will probably be different. I will make notes where applicable.
Requirements:
- A CAS server accessible through https. It may be possible to get phpCAS to work without it, but it is safer and probably easier just to set up the https.
- A webserver such as Apache, but any that will be capable of running PHP will do.
- PHP5 with cURL installed on the machine.
Directions:
- The easiest way to install is through PEAR with the command “pear install http://downloads.jasig.org/cas-clients/php/current.tgz”. If PEAR is not already installed, it will tell you the command needed to install it. If on Windows or a flavor of linux that does not provide a command to install PEAR, a manual install would probably be easier. Just download from the link in the command above and extract somewhere logical (if you’re on Windows, you’ll need something like 7zip to open the .tgz) and add the include_path to your php.ini file.
- Go to the directory web pages are served from for that server (/var/www/) and copy config.php and example_simple.php from the examples directory provided with phpCAS’s documentation (/usr/share/php/doc/CAS/docs/examples). Other examples can be copied if desired, but this is all that is necessary to test the connection.
- Modify Config.php to reflect the setup of the machine it is install on. This file is included in all of the example files, so you should only need to change this once. For a typical machine, the following changes were made:
- $phpcas_path = ‘/usr/share/php’;
- $cas_host = ‘localhost’;
- $cas_context = ‘/cas-server-webapp-3.4.8’;
- $cas_port = 8443;
- In a web browser, go to http://localhost/example_simple.php to test the server. It should redirect you to the CAS login page and then return you once logged in. If you were already logged in through another app, it will automatically take you to the requested page.
While it may not seem like much as it is, the examples included with phpCAS will give you a good basis for using this client with your own PHP applications. Do keep in mind that Single Sign On with CAS does not mean Single Sign Off, so always log out of your applications separately. Also remember that Authentication and Authorization are separate concepts and CAS will only decide if a valid username and password were provided. It is up to your application to determine if that username should have access.
8 thoughts on “Installing and configuring phpCAS”
hello,
I followed all instructions to execute a CAS client, the authentication is successful (a message is displayed), but never returns me to my original application.
Do you must register the application for which I want the authentication?
It can be hard to say without looking more closely at the application itself (assuming this is a completely custom php application), but it sounds like it is not redirecting back to the source application because it doesn’t know where to redirect back to. I’ve only dabbled with phpCAS, no full blown applications with it, but I would suggest making sure that all of the various URL parameters are completely filled out and working. Good Luck!
Hi Gerrit,
I’m trying to test phpCAS functionality. I want to use XAMPP for these purposes. Can I use Apache HTTP (not Tomcat) for phpCAS testing or do I need to get the Java CAS server (cas-server-ver) and Apache Tomcat? Also, could you please clarify what values are required for “$cas_host, $cas_context and $cas_port”?
We only use tomcat because we have other applications that run on it. As long as a web server can interpret the PHP, it can use phpCAS. As far as those three variables, it’s pretty straightforward: host is the base URI that the server is located at, context is the specific path on the host machine to the server, and port is just the port that the server is listening on. Going back to my example, I can access the main CAS server by going to https://localhost:8443/cas-server-webapp-3.4.8 in a web browser, so I set up my variables as given in the example. Hope that clears things up.
Hello ,
i’m very new to phpCAS , i’m have three web applications , for that i want to create CAS , is there any sample example configuration script or video for beginners . ?
Other than the example folder mentioned in the post (CAS/docs/examples) the online documentation has more examples and information listed here: https://wiki.jasig.org/display/CASC/phpCAS+examples
Past that, I can’t say too much, since I’ve never gone through the full effort of “CASifying” a web app, merely configuring ones that were already designed to do so. The information on their site is rather well done, so it should be able to tell you what you need to know.
Hello Gerrit,
I am trying to setup CAS server on my local windows server but just not understanding few things. What entry should we do in php.ini for CAS server.
Very good tutorial, had sought an example like this. I have configured the CAS server on Centos 6.6 and phpCAS files are in /usr/share/pear
Thanks, great contribution