In our coding bootcamp, we use PHP from the Command Line Interface. But first, you have to install it! This can be a fraught process, so this blog article will give you step-by-step instructions on how to get it done. Soon, you’ll be able to use PHP from the Command Line and enjoy all the benefits that go with it!

  1. Go to the PHP official website and download the most up-to-date version of the software. Also, you’ll need to decide which version to download: “thread safe” or “non thread safe.” In our coding bootcamp we use “thread safe” because we are a WordPress bootcamp, and WordPress runs on an Apache server. And Apache is a threaded system, so the PHP version needs to work with that system. In other words, it needs to be thread safe.
    The official PHP website showing the latest version of the software.
  2. PHP will download as a zip file. Go into your downloads folder and extract the contents. Then, rename that folder “php” and drop it into your C: drive.
  3. In the C:/php folder, copy the php.ini-development file (literally, just copy-paste it into the same folder). Then, rename the file you just copied to “php.ini.”
  4. Open php.ini file in any code editor and search for extension_dir = “ext”. Uncomment that line by removing the semicolon at the beginning of the line.
    The php.ini file with the line containing extension_dir uncommented.
  5. Open your computer’s “Environment Variables.” You will do this differently on Windows, Mac and Linux machines. On a Windows machine, you can simply go to the search bar at the bottom of your screen and search for “env.” The “System Properties” window will open up. Click the “Environmental Variables” button near the bottom.
    The System Properties window will have an "Environmental Variables" button.
  6. Under “System Variables,” select “PATH” and click “Edit.”
    PATH lives in the System Variables popup window.
  7. Now we’re going to add two new entries to the PATH. The PATH is a group of universal commands that you can type into the Command Line Interface, and it will understand. But since we’re adding new commands to the PATH, we need to tell it what file to run when a given command is typed into the CLI. So, first click “New” and then “Browse.” Find C:\PHP, highlight it, and click “OK.” Next, do the same thing, but for your extension folder, which you should find at C:\PHP\ext.
    PHP is being added to the PATH.
  8. Click “OK” on the Environmental Variables window. It should close.
  9. Now you’re back at the System Variables window. Last time you were on this window, you clicked “Edit” on PATH. But this time, you’re going to click “New.”
  10. In the “New System Variable” window that appears, type in “PHPRC” in the “Variable Name” field and “C:\PHP” in the “Variable Value” field.
    The New System Variables popup window.
  11. Click OK on that window, then click OK on the Environmental Variables window and OK on the System Properties window.
  12. Now, restart your computer. When it comes back online, you can test whether you installed it successfully. Open your command like and type php -v and hit “enter.” You should see a printout in your command line of the version of PHP you’ve installed.

Congrats, you did it! You’re now ready to use PHP from the command line. But why should I install PHP on my computer, you might be asking? Read on.

Why should I use PHP from the command line?

PHP is a widely used programming language for web development, and despite being relatively old by programming language standards, it’s still in wide use thanks to its ease of use, flexibility, and ability to build complex web applications. While many web developers use PHP on remote servers, there are numerous benefits to installing PHP on your computer, and in this article, we will discuss those benefits.

Easy Development

When you install PHP on your computer, you can develop and test your PHP applications locally. This means that you can make changes to your code and instantly see the results without having to upload the files to a remote server. This can make the development process much faster and more efficient, as you don’t have to deal with the time delay of uploading files to a remote server and waiting for the results to be displayed.

Offline Testing

Another major benefit of installing PHP on your computer is that you can test your PHP applications offline. This can be particularly useful if you are developing in an area with limited internet connectivity, or if you need to test your application in a specific environment that is not available on a remote server. By installing PHP on your computer, you can test your application in a local environment that closely mimics the environment it will be deployed in.

Improved Performance

PHP applications run faster on your local machine than they do on a remote server. This is because local servers have more resources and less network latency than remote servers. By installing PHP on your computer, you can take advantage of this improved performance and ensure that your application runs as smoothly as possible. This can be particularly important if you are developing a large or complex web application that requires a lot of processing power.

Better Security

Developing PHP applications on your local machine reduces the risk of security breaches. You can configure your local environment to be as secure as possible, and you don’t need to worry about external threats such as hacking attempts or malware infections. Additionally, you can test your application for vulnerabilities in a controlled environment, which can help you identify and address any security issues before deploying your application to a remote server.

Flexibility

Installing PHP on your computer gives you the flexibility to work with any PHP framework or tool you choose. You can install any version of PHP, configure the environment to your liking, and work with any other tools you need to get the job done. This can be particularly important if you are working on a project that requires a specific version of PHP or if you need to work with specific libraries or tools that are not available on a remote server.

Cost Savings

Another advantage of installing PHP on your computer is that it can save you money. If you develop PHP applications on a remote server, you will need to pay for hosting fees and other costs associated with running your application on a remote server. By developing your application locally, you can save these costs and only pay for hosting when you are ready to deploy your application to a remote server.

Easier Debugging

Debugging PHP applications can be difficult, particularly if you are working on a remote server. When you install PHP on your computer, you can use a variety of debugging tools to identify and fix issues with your code. This can be particularly useful if you are working on a large or complex application, as it can help you identify issues more quickly and efficiently than debugging on a remote server.

In conclusion, there are numerous benefits to installing PHP on your computer, including improved development speed, offline testing, improved performance, better security, flexibility, cost savings, and easier debugging. Whether you are a seasoned developer or just starting with PHP, installing PHP on your computer can help you work more efficiently and effectively, and can help you build better web applications.