DEV Community 👩‍💻👨‍💻

Swishyfishie
Swishyfishie

Posted on

Nice to meet you, PHP!

I have got a few messages on my LinkedIn regarding my PHP post the other day so I decided to write a bit about the start of my journey in the world of PHP.

My main motivation for learning this language is -and I'm going to be brutally honest- the job market. Studying Ruby on Rails at Flatiron Bootcamp was amazing, but the job prospects are grim as most of the Rails jobs are for people with a few years of experience, not juniors, but I derail (pun intended).

Okay so as a PHP junior, I've found a few useful resources and tools:

XAMPP

XAMPP is a popular PHP development environment that you can install on all the platforms (Linux, Windows and Mac). If you follow the instructions from here -- click on the video, you should have it up and running in no time.

You just open up the XAMPP after you installed it and click on the start buttons for the Apache and MySQL modules.

xampp interface

This will basically start your server which you'll find by default under the "localhost" address, so just type that in your browser.

You'll want to create your own php files, right? So in order to do that, go to the path 'xampp/htdocs' and create a folder with your project, maybe something cool like "todolist". Todo lists are cool, right? ...right?

Right!

Create your php files there and you can access them from your localhost address like this "localhost/todolist/index.php".

Simple, right?

Now you just need to know how to write PHP and you're sorted.

I highly recommend this FREE course by Brad Traversy.

Creating a database from 'localhost/phpmyadmin'

It's quite simple to create a database using XAMPP.

Type in your browser search bar 'localhost/phpmyadmin' and you'll see an overwhelming interface, but do not worry! It's not that scary if you actually look at it.

localhost php my admin interface

On the right side you can see the magic word "New". You can either press it, or be directed by default to the database panel where you have to enter the database name and just press create.

new database tab

For this example I've created a table named "posts" that has 4 columns.

The first column is the "id" which you need to make sure it has a type of "INT" (integer) and that it is automatically incremented, by checking the "A_I" checkbox.

The second one is designated for the body of the post (the actual content) with a type of "TEXT" -- no need to give it other attributes.

The third one, author is going to be a type of "VARCHAR" with a length of 255 characters

And the fourth will have a "DATETIME" type that we will give a default value of "CURRENT_TIME".

Press Save and you'll have a lovely table like this:

database table view

Of course, you can play around and go to the INSERT tab and populate your database, but going more in depth is out of this article's scope.

Postman

This is an amazing tool for testing your API -- if you want to build any. But you should want to build at least an API in your lifetime. It's fun and it's not that hard!

PHP API course - this one has Postman included and Postman course - this one is focused on Postman

VSCode

Use VSCode.

Top comments (22)

Collapse
andreidascalu profile image
Andrei Dascalu

My advice to you is ... dump xampp and go with Docker. Particularly with vscode you can use docker as a Dev environment as you would with your local filesystem.
Also consider that in 99% of the time a web app will run on a Linux system or a Linux backed container. Eventually you will start hitting the differences.

Collapse
swishyfishie2 profile image
Swishyfishie Author

Isn't docker a bit of an overkill for someone who's just started learning PHP?

Collapse
ricardobarantini profile image
Ricardo Barantini

You're right, stick to Xampp/Wamp/EasyPHP for now, it's the better tool when you are starting to learn this language.

Collapse
andreidascalu profile image
Andrei Dascalu

Overkill in what sense? You don't have to learn it straight off but you can use it in the sense that you can install it and everything else comes from the IDE

Collapse
andreidascalu profile image
Andrei Dascalu

Actually, I dumped phpstorm for vscode. While phpstorm is the best for php in general, vscode is more comprehensive (if you do web you will need js and vscode is the best for that, plus intellisense for a variety of other stuff like nginx/Apache configs).
Phpstorm has the best support for the vast majority of frameworks, that's for sure but beyond stuff like Laravel ok n particular I can't think of a single thing that phpstorm does that vscode with intelephense can't do at least just as well and for a fraction of the cost.

andreidascalu profile image
Andrei Dascalu

If You do, I would suggest intelephense instead of intellisense. Intellisense is the engine underpinning most language servers across supported languages. For PHP is ok (autocomplete is as good as any) but intelephense is way better with symbol find and replace, much better discovery of classes (composer or not) formatting with phpcs support and some integration with sonarqube rules (on clientside)

Thread Thread
andreidascalu profile image
Andrei Dascalu

I'm going to come back with another reply mostly because of the first sentence "I'm not sure why you'd want to work directly on containers or k8s pods" - it's one I hear a lot (particularly in the PHP world) and it's a very interesting thing.

About k8s pods, unless you happen to use PHP for microservices (particularly if you're using roadrunner instead of fpm or one of the newer microservice oriented frameworks like symlex or lumen) you probably don't need k8s generally (a regular monolith application is cumbersome to setup with k8s and won't perform nowhere nearly as well). But if, like me, you do then you will eventually work for a system that's big enough (my previous project had ~ 100 microservices spread across 4 languages) so that you can't run even the close dependencies locally. In that case what you would do is either run a local container + a tool called "telepresence" to have your local container effectively replace a container in a pod in a remote cluster or, alternatively, you would just run a remote pod alone. You would continue editing your code, running your xdebug, etc in Vscode with everything taking effect both locally and remotely. Technically that covers both cases.

Just locally, however, there's also the case when it's a bit of a headache to reliably install/build php modules locally (eg: on Mac and Windows you can't build/get all versions of php's amqp extension if you hope to keep your OS updated, same with redis to a certain extent). So, just run a Docker container. Same with the (granted, edge case) when you'd need to switch multiple PHP versions on the fly or you simply want a reliable environment tat closely mimics a stable remote (eg: I want to have modules x/y available but not z - will you uninstall and reinstall z whenever needed?)

andreidascalu profile image
Andrei Dascalu

Well, Microsoft doesn't offer all that much out of the box for PHP but withcl Intelphense, Gitlens and so on, Vscode does much more than phpstorm. Like I said, it lacks in specific support for PHP frameworks ( the only one fully supported is symfony) but other than that it can do exactly the same things (and more, from what I remember with phpstorm you can't work directly on the filesystem of a container or k8s pod)

Collapse
swishyfishie2 profile image
Swishyfishie Author

What a lovely and comprehensive addition to what I wrote! I deeply appreciate your input and yes, I agree with you that a framework is the realistic next step and the VSCode part was more of a meme haha! :D I've used some IDEs from jetbrains like WebStorm and RubyMine and I like them. Might try PHPstorm as well!

andreidascalu profile image
Andrei Dascalu

Well, guess it's a matter of taste. I like how intelephense does the navigation to function definition or usage way more than how phpstorm does it. I'm pretty sure you didn't try the "pro" as in paid version of intelephense which is what brings at least most of the stuff you mentioned (10 USD lifetime license) which is what actually comes in the ballpark of phpstorm (and container support to boot, can't really image why an editor could call itself a modern IDE without it)

Collapse
noprod profile image
NOPR9D ☄️

Nice to meet you, Swishyfishie!

Collapse
drkevorkian profile image
drkevorkian

Notepad++. Why use something more complicated?

andreidascalu profile image
Andrei Dascalu

Well, glad you found a way to make microservices that don't exchange information in any shape or form.

swishyfishie2 profile image
Swishyfishie Author

I touched Laravel a bit a few months ago and because I am used to Rails, it seemed quite familiar so I'll go with that! :D Thank you for the recommendations!

🌚 Life is too short to browse without dark mode