Friday, January 31, 2014

Getting Started With Laravel from Scratch

Overview

To start with web and Laravel development, you'll need the following:

A Web Server : To actually run your web apps.

PHP : The language to write your apps in.

A Database : Where you can store your app data.

Composer : Used to manage PHP dependencies.

The Laravel Project Files : The actual Laravel source files.

This tutorial will walk you through the process of installing and configuring a web server as well as everything needed to start developing with Laravel. I'm working in Windows, so everything here is for the windows operating system.


Installing a web server

For our purposes, we will be using WampServer. It includes a web server (Apache), PHP, and a database (MySQL).

There are however a few things you need to change before being able to use Laravel.


Installation

Download and install the WampServer stack. I use WAMP SERVER (64 BITS & PHP 5.4) 2.4

Check if it’s working.

Run the server.

In a browser navigate to http://localhost.

You shoulde see the WampServer welcome page.


PHP path

Before going further, we have to put the PHP executable in our system path. This allows us to run PHP commands from anywhere in a command window.

For more detailed instructions, check out the PHP installation manual: PHP manual

Open the Windows Control Panel.

Choose System, then Advanced System Settings

In the Advanced tab, choose Environmental Variables

In System variables find the Path entry and choose Edit

At the end of the Variable Value add a ; and your PHP path

;[wamp_folder]\bin\php\phpx.x.x

Click OK

System Path

Be careful NOT to overwrite the system path. Only ADD your PHP path to it.

You can test if php.exe is in the system path by opening a command prompt and typing php. If it doesn’t give any errors, you can continue.


mod_rewrite

Next you have to enable the Apache module mod_rewrite. mod_rewrite along with your .htaccess file is needed by the Apache server so you can have pretty urls.

Left click on the WampServer tray icon.

Choose Apache -> httpd.conf. This opens the Apache configuration file.

In the file, find mod_rewrite. It should look like this:

#LoadModule rewrite_module modules/mod_rewrite.so

Remove the # at the start of the line so you have:

LoadModule rewrite_module modules/mod_rewrite.so

Save the file and close it.


openssl

The final step is to enable openssl for PHP. openssl is needed by Composer to download files.

php.ini

There are two php.ini files. One in the Apache folder and one in the PHP folder. I usually just change the settings in both files.

First, for the php.ini file in the Apache folder:

Go to [wamp_folder]\bin\apache\Apachex.x.x\bin

Open php.ini.

Find openssl. It should look like this:

;extension=php_openssl.dll

Remove the ; at the start of the line so you have:

extension=php_openssl.dll

Save the file and close it.


Now, do the same for the php.ini in the php folder.

Go to [wamp_folder]\bin\php\phpx.x.x

Open php.ini.

Find openssl. It should look like this:

;extension=php_openssl.dll

Remove the ; at the start of the line so you have:

extension=php_openssl.dll

Save the file and close it.

Restart WampServer.


Installing Composer

Composer is used to manage your PHP dependencies. It's also what I use to download Laravel.

The next two sections follows the documentation at Laravel.com so you can check that out if you need further help

First, download the Composer Windows installer at Composer-Setup.exe

Run the installer and install Composer.

php Path

The php executable is located at [wamp_folder]\bin\php\phpx.x.x. If you put the PHP folder in the system path as mentioned earlier, it should show up here. If not, go back and make sure your PHP folder is in the system path.

Test Composer

Open a Windows Command Window: Windows Key + r, type cmd and enter.

In the command window type composer and enter

If you see the Composer usage instructions, you're good to go.


Getting Laravel

The last step is to actually get the Laravel project files. Again, this is the same information as the Laravel start guide at Laravel.com .

The start guide shows you three ways of getting the Laravel project files. I'll be using composer create-project.

Where do I put my projects?

All the files for your web projects will go into the Wamp web folder at [wamp_folder]\www. These folders correspond to the urls of your web pages.

Open a command window in your wamp www folder.

Opening a Command Window

A quick way to open a command window at a specific folder is to browse to the folder in windows, then shift + right click on the folder and choose Open command window here.

In the command window type:

composer create-project laravel/laravel [your-project-name] --prefer-dist

Wait while the Laravel project files and dependencies download

When done, you should have a new folder with the name you specified in the composer command.

Test the Laravel project

If WampServer is not running, start it now.

Open your browser and go to http://localhost/[your-project-name]/public

You have arrived... I hope.


Congratulations

You should now have your first Laravel project and be ready to start creating web apps.


No comments:

Post a Comment