Setup your PHP Slim Framework Tutorial

What is Slim Framework? Slim Framework is the most famous php micro framework to create the REST api for your web application or mobile application. REST api is the communication between client and server side in the technology world. Slim framework is very light weight and easy to use to develop REST api according to your needs. I will teach you how to setup your php slim framework and create the REST api in your application. It is just easy.

Prerequisites

1. PHP programming language to perform script

2. SQL query to retrieve data from database

3. XAMPP to run your web server and MySQL

Start your XAMPP

In the first step, you need to run your web server and MySQL to proceed. If you dont know how to use XAMPP go to this link.

Go to your Website path

After you running your XAMPP, go to your xampp directory then go to htdoc folder. Example : C:\xampp\htdocs. After that create a new folder in the htdocs folder for slim project. I name my folder to slim-framework-rest-api.

Install Composer

If you don have php composer, go to install composer in your computer to download dependency in your project. Go to //getcomposer.org/download/ You can either install via .exe or type the command in your cmd.

Open command prompt and Install Slim Framework

Enter the command to navigate to the slim project folder name that you create just now. After that, enter

to install slim framwork in your directory. You can follow the picture below.

download slim in command prompt

Understanding route

Go to the main slim index file in the slim folder, for example my path is C:\xampp\htdocs\slim-framework-rest-api\vendor\slim\slim\example\index.php. The following will route the index.php to / and /hello/{name}.

index.php

.htaccess

Access slim home path

Enter local url in your browser for example : //localhost:63343/htdocs/slim-framework-rest-api/vendor/slim/slim/example/.

If you see error such as the bottom pic.

slim-2You may modify index.php

to the full path of autoload.php

Success access slim

After that, access again the path and you will be see the screen such as below.

slim-3

You can also try another route for example for my situation //localhost:63343/htdocs/slim-framework-rest-api/vendor/slim/slim/example/hello/questdot

This route specify in the index.php

Edit Virtual Host

Go to the apache\conf\extra path for example my path is C:\xampp\apache\conf\extra to edit the virtual host file configuration which is “httpd-vhosts.conf. Edit and add the following text in your “httpd-vhosts.conf” file to change your project home path. For my case, my home path for the slim project is C:\xampp\htdocs\slim-framework-rest-api\vendor\slim\slim\example.

<VirtualHost *:80>
DocumentRoot “C:/xampp/htdocs/slim-framework-rest-api/vendor/slim/slim/example”
ServerName slimexample
</VirtualHost>

Edit hosts file

Go to edit your hosts file inside the Windows directory C:\Windows\System32\drivers\etc. Right click the hosts file and edit it in the notepad. If you cannot edit the hosts file, drag the hosts file to your desktop and edit it.

Add this line in your hosts file (127.0.0.1 slimexample)

 

Now, you can access by using this path //slimexample/ in your browser. 

(Visited 1,720 times, 1 visits today)
Advertisements

Kristofer Ng

A crazy android and web developer. Passion on developing android application and exploring new technology as a hobby.

You may also like...

1 Response

  1. October 19, 2016

    […] previous tutorial, you already understand how to setup php slim framework in your computer and also learn how to […]

Leave a Reply

Your email address will not be published. Required fields are marked *

GET YOUR EBOOK FOR FREE

Unlock free ebook "Beginning Programming ALL-IN-ONE Desk Reference for DUMMIES" now!

We will send a copy to your email