Setting Up Your First Slim Project

Kelvin
Kelvin
Aug 28, 2017 · 3 min read

In the previous post, I talked about why using a micro-framework/framework is a better option than embedding HTML into PHP files. However, there were a lot of assumptions made about the set up of the project. In this post, I will specify how to set up your slim project so you can start building your web apps on your windows computer.

The majority of these steps are useful for web development with PHP in general. So if you’re not using the slim micro-framework for your project, most of these steps will still apply.

Install XAMPP

XAMPP is a cross-platform web-server that contains interpreters for PHP and Perl. This is what will allow us to serve our PHP application. Installation is straight forward. You can download it here. Once the download has completed, run the installer. After installation, navigate to the PHP folder within XAMPP and copy the path. Add this to your PATH environment variable. You can do the same for Perl if you wish although it will not be relevant for this process.

This is not absolutely vital for Slim apps as they use an app server but it’s still a useful tool if you need to run a simple web server on your computer.

Install cURL

cURL is a popular command-line web transfer protocol. We are going to use this to obtain the composer package manager(see next step) before installing. You can download cURL here. You might need to install Visual C++ Redistributable for Visual Studio. If you haven’t already, you will be instructed by the cURL installer to do so before you continue.

Once you have installed cURL, navigate to the location of curl.exe. This will usually be in C:\Program Files\cURL\bin. If you have installed it in a different location, use that location instead. Add this location to your environment PATH variable. After you have completed that, open a command prompt and type:

curl --version

You should see the version of cURL display on the command prompt window.

You are now ready to move onto the next step.

Install Composer

Now that you have cURL installed, it’s time to install composer. Composer is a dependency manager for PHP. It will allow you to install the packages that you need in your application. A package is reusable code that can be imported and used in an application without needing to be edited. This saves time as you don’t have to code functionality that you already get from a package making it easier to focus on your application logic.

You can get composer here and follow the installation guide. I prefer to use curl to install composer as it’s straight forward.

On your command prompt, navigate to htdocs and type the following:

curl -S https://getcomposer.org/installer | php

This will download composer.phar into the directory. You are now ready to start installing packages.

Installing Slim

To initialize a slim project, the easiest way is using the slim skeleton. In your htdocs folder, type the following command:

php composer.phar create-project slim/slim-skeleton [my-app-name]

This will create your app’s directory and set up your slim project.

You are now ready to run your application. Navigate to your application directory and type the following command:

php -S localhost:8080 -t public public/index.php

To view your app, visit “localhost:8080” on your browser. Your slim app is now up and running!

The “src” folder is where all the configuration goes. The index.php file is where all app requests are routed through. App routes reside in the routes.php file. Project templates can be found in [my-app-name]/templates. This is where all your HTML files go.

If you’re interested in more content from me, visit my personal blog. If you are interested in acquiring my services, visit my personal website and feel free to contact me.

)

Kelvin

Written by

Kelvin

Full-stack software developer. #WebDev #Programming

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade