PHP Environment Setup

Last Updated : May 3, 2021

To set up a PHP environment, we have to install few software packages and modify the configuration file based on our needs. Generally, to run any programming language, we need to install their software package in our local or server machine. This tutorial section will guide you on what to install and how to configure to make PHP work in the system.

Prerequisites for PHP

  • PHP Parser is a piece of software that converts PHP source code into computer understandable language
  • HTTP Server used to process your request and returns a response
  • Database used to store necessary information
  • Editor – a good editor will help to build an application effectively.

Software Installation Packages

We can install the above-mentioned prerequisites software separately or as a package. Based on our convenience, we can install and set up our desktop/laptop environment. We found that installing the above-mentioned software as a package avoids many configuration issues. Please find below the whole package for different OS,

  • XAMPP – is a trendy package and the most widely used one. It can be installed on Windows, Mac OS, and Linux Operating Systems
  • LAMPP – used for only Linux
  • WAMP – used for only Windows
  • MAMP – used for only Mac OS

Editors/IDEs for PHP Programming

We can write PHP code using any basic text editor like Notepad or TextEdit from Windows and Mac OS. However, having syntax highlighter-based editors gives you more control over the code, and you can quickly debug if any issues.

There are different Editors, and IDEs are available with paid/free of cost. Based on your need, you can download and install any Editors/IDEs. But, we strongly recommend that you start with Editors and use IDEs when you became an expert on PHP programming.

IDEs have more features like code syntax highlighter/error identifier, compiler, executer, debugger. In contrast, Editors may not have all these features, and due to its lightweight design, you can write PHP code seamlessly in Editors. Also, you can install add-on plugins to perform many of IDEs operations in Editors but not necessarily needed now.

Please find below some of the most widely used PHP Editors and IDEs.

We used Sublime Editor and Visual Studio Code Editor in many PHP projects, we didn’t find any difficulties with these Editors. You can try these too!

Testing PHP on your machine

To test your desktop/laptop/server PHP installation, you can run a simple script that shows all PHP-related settings from your machine.

Create a new file with the following code and save it as phpinfo.php in your local htdocs/ or www/ folder, then run https://www.writephponline.com/phpinfo.php or http://yourhost/phpinfo.php in your browser.

<?php phpinfo(); ?>

If you run the above file and if your web page gives all information shown in the below image, then your PHP installation has no issues. If you have any issues, then you can search on the internet and rectify them accordingly.

PHP.ini Settings

Once you have working PHP installation in your machine, the next step is to change some basic values in the php.ini file. To get the correct php.ini file, please check the path in the Loaded Configuration File section from your phpinfo information. There are many settings available inside php.ini however, we included a few important settings below to review and change if needed.

short_open_tag = on/off – which enables short tag <? ?>

upload_max_filesize – which helps to configure maximum upload size

post_max_size – which helps to configure maximum POST size for the PHP to handle

file_uploads – which helps to enable/disable file uploads on the server

display_errors = on/off – which helps to show/hide any script error while you running your web application on the browser

max_execution_time – which helps to set maximum execution time on the server

Now your system is ready to run any web-based application developed using PHP and MySql database. Let’s jump into the PHP tutorial series.