Installing Slim Framework for PHP
Learn how to install Slim Framework on your web hosting account. Just use our step-by-step Slim for PHP instructions. Hosting.com makes it easy!
This article describes how to manually install the Slim Framework for PHP, a compact framework for developing web applications and APIs.
Installing the Slim Framework
You can manually install the Slim Framework for PHP on your hosting.com account.
Note
Although hosting.com servers are compatible with a wide variety of software applications, we cannot provide troubleshooting assistance for application-specific issues.
To install the Slim Framework, follow these steps:
-
Download the Slim Framework at https://github.com/codeguy/Slim/zipball/master to your computer.
-
Extract the .zip file on your computer. You should now have a folder named codeguy-Slim-bc5f5a8 (or a similar name).
-
Use FTP to upload the contents of the codeguy-Slim-bc5f5a8 folder (but not the codeguy-Slim-bc5f5a8 folder itself) to the public_html directory of your hosting.com account. For more information about how to access your account using FTP, please see this article.
Note
Alternatively, you can upload the Slim Framework files to a subdirectory located beneath the public_html directory. If you do this, make sure your PHP script files use the correct path to the Slim Framework subdirectory.
-
Use a web browser to go to your website's URL, such as http://www. example.com, where example.com represents your domain name. You should see the Welcome to Slim page.
Running a test application
Now that you have the Slim Framework installed, let's run a quick test application. To do this, follow these steps:
-
Create a file named slimtest.php in your account's public_html directory.
-
Copy and paste the following sample code into the slimtest.php file:
<?php require 'Slim/Slim.php'; \Slim\Slim::registerAutoloader(); $app = new \Slim\Slim(); $app->get('/hello/:name', function ($name) { echo "Hello, $name"; }); $app->run(); ?>
Note
This code sample assumes that you uploaded the Slim Framework files to the public_html directory, which contains the Slim subdirectory. If you uploaded the Slim Framework to another directory, make sure you modify the path in the require statement.
-
Use a web browser to go to the URLhttp://www.example.com/slimtest.php/hello/world, whereexample.com represents your domain name. You should see Hello, world.
Tip
As you may have noticed, the trailing part of the URL is handled as a variable. Therefore, you can type anything you want after the /hello/ section, and it will display in the browser.
More Information
-
For general information about the Slim Framework, please visit http://www.slimframework.com.
-
To view the online documentation for the Slim Framework, please visit http://docs.slimframework.com.
Related Articles
Updated 1 day ago