Six Easy Setups for Local PHP Development — Beginners
I decided to write on this obviously simple topic because a lot of people still find it difficult! 😱😳😰 These people include beginners who battle with a lot of difficulties just trying to echo their hello world using PHP, oldies who have years of experience writing PHP but have failed to migrate to modern paradigms in PHP and naysayers who behave as if PHP murdered a member of their family 😂.
At this point let me say, using *AMPs is old school and there are faster and easier way of setting up the lovely blue elephant 🐘.
Actually, it is just one way of setup that I would be talking about but I will be enumerating on different flavors of the one way. The one way is simply installing global installation of PHP which allows you to run PHP code everywhere on your machine, unlike the *AMPs that restrict you to the boys-quarter of htdocs and www folders 😜. Also, the *AMPs do not let you see that you can actually use PHP beyond the web.
Let’s get started …
Simply install PHP globally on your Machine
On a Mac, simply do:
brew install php7.2
On a Linux machine, simply do:
sudo apt-get install php7.2
On a Windows machine, simply extract the binary downloaded from php.net to your C:/ and remember to add it to your System’s Environment Variables.
Once that is done on respective machines, kindly run:
to confirm that your installation was successful. You should see a response similar to this:
Below are the ways you can use your PHP installation easily:
1. Start PHP local web server
In the root of your PHP application or file. Simply start PHP web server using:
php -S localhost:8000
to run your index file or specify the name of the file you simply want to run like:
php -S localhost:7777 filename.php
With this, you will see a response like:
You can easily see your pages served by visiting http://localhost:port_number.
2. Use PHP interactive shell
A good number of PHP developers are not aware of this. It is simply a REPL environment to quickly run your span with some PHP code. Simply run:
This is an example:
3. Using the php command
Simply type php before a filename to execute a PHP script. Below is an example:
4. Using Sublime Text’s Build System.
If you use Sublime Text editor, you can run your php script within ST3 using the Build System feature by running cmd + B or Ctrl + B. To setup build system for PHP in ST3, follow the guideline here. Here is an example:
5. Using Atom’s Build System
Similar to using ST3’s Build System, running PHP code within your Atom editor comes out of the box. Just run cmd + I or Ctrl + I.
6. Using PHP Server within Atom
Starting PHP server within Atom editor is easy by using this plugin. With this, you can easily spin up your server with few keys. See example below:
I hope you found something of benefit from this simple post.
If you liked this, click the💚 below so other people will see this here on Medium. Also, if you have any questions or observations, use the comment section to share your thoughts.