Amina
Amina's Blog

lorem ipsum

Aug 13, 2024 5 minute read

Setup to Start Programming with PHP (and Laravel)

Table of Contents

  1. Install PHP
  2. Set up a Code Editor
  3. Install Composer
  4. Useful Links

Getting started with PHP and Laravel involves setting up a development environment that allows you to build and test web applications locally. Here are a few essential steps to install the necessary tools and prepare your system for PHP and Laravel development.

Install PHP

PHP is a server-side scripting language that powers many web applications. You'll need it installed on your machine to run and test PHP scripts locally.

There are two options to install PHP:

For simplicity, you can use a pre-packaged environment like:

These packages include PHP, Apache (a web server), and MySQL (a database server), making it easy to set up a local development environment.

If you're looking to start developing with Laravel, Laravel Herd is a great option, it's a PHP development environment, and it includes everything you need to get started with Laravel development, including PHP and nginx.

Manual PHP Installation

If you prefer manual installation:

  • Windows: Download PHP from php.net and follow the instructions for adding PHP to your system's PATH
  • macOS/Linux: Use Homebrew or a package manager to install PHP (brew install php for macOS, sudo apt install php for Ubuntu/Linux)

Verify Installation

Open your terminal/command prompt and check if PHP is correctly installed:

php -v

Set up a Code Editor

Choosing a good code editor or integrated development environment (IDE) is crucial for efficient coding:

  • Visual Studio Code: A popular, free editor with a wide range of extensions for PHP and Laravel development
  • PHPStorm: A premium IDE tailored for PHP development, with deep integration for Laravel
  • Sublime Text: A lightweight editor with useful plugins for PHP

I personally use PHPStorm, it's really powerful, and has a lot of features like, smart code completion and refactorings, instant error detection, and many more. It's also the go-to IDE for popular PHP frameworks, including Laravel.

Plugins

Plugins can enhance the functionality and tailor the development environment of your code editor to meet specific needs. They allow you to add features like syntax highlighting, code completion, debugging tools, and integrations with version control systems.

This not only improves your productivity by automating repetitive tasks but also helps you catch errors early and streamline your workflows. With plugins, a basic code editor can be transformed into a powerful, customized tool that suits the unique requirements of different programming languages and projects.

A lot of code editors come with certain plugins already installed, so you should check if you need them, if not you should disable those you don't need.

Another thing you should do, is make the code editor comfortable for yourself. There are a lot of great plugins like Prettier, or Rainbow Brackets, which can help you make your code more readable for yourself and for others. Of course, there are a lot of theme plugins, which can make the whole coding experience feel a little more special.

For my IDE, a plugin I have installed, and I think it is a must-have for Laravel-Developers, is Laravel Idea.

Here are only a few features Laravel Idea has:

  • Powerful code generations
  • Advanced routing, validation, request fields, gates & policies, config, translations, views, and a lot of other completions
  • Livewire, InertiaJs, Dusk, Laravel-modules, and other third-party packages support

Install Composer

Composer is a dependency manager for PHP that allows you to manage libraries and packages in your projects, including Laravel.

Installation Steps:

  • Download Composer from the official website
  • Follow the installation instructions for your OS
  • Ensure Composer is available globally by adding it to your systemโ€™s PATH

Verify Installation

Open your terminal/command prompt and type:

composer --version

Now you are ready to start experimenting with your setup by creating simple PHP scripts or a new Laravel project. Dive into Laravel's extensive documentation to explore its capabilities.


Amina