PHP Environment Setup
PHP is an interpreted and object-oriented scripting language. PHP can be written on a simple text editor. Web server applications are used to run the program.
What are the requirements for PHP programming?
- IDE
- Web Server
- Database
- AMP
What is an IDE?
IDE (Integrated Development Environments) are those applications that are used to develop other applications. IDE’s can perform all the functions required to develop an application. An IDE includes Source Code editor, Compiler, Debugger, and other built-in tools.
Which are the most popular IDEs for PHP?
- VS Code
- Eclipse
- NetBeans
- Atom
- IntelliJ IDEA
- PHPStorm
- Xcode
- Brackets
- Komodo Edit
- WebStorm
What is a web server?
To load a web page written in PHP requires a web server application. PHP is supported on almost every web server application. The most commonly used web server application is Apache Server.
PHP Database
PHP can be integrated with most of the databases which are currently used in the industry namely MySQL, PostgreSQL, Oracle, and Microsoft SQL Server. MySQL database is the most commonly used database. MySQL is an open-source relational database management system.
What is AMP?
AMP denotes the software stack which is used for the PHP installation. In AMP, A stands for “Apache” M stands for “MySQL” and P stands for “PHP”. The most commonly used AMPs are:
- WAMP: WAMP is the acronym for the software stack Windows, Apache, MySQL, PHP. It is developed for the Windows operating system. Download link: https://www.wampserver.com/en/
- LAMP: LAMP is the acronym for the software stack Linux, Apache, MySQL, PHP. It is developed for the Linux operating system. Download link:http://csg.sph.umich.edu/abecasis/LAMP/download/
- MAMP: MAMP is the acronym for the software stack Mac, Apache, MySQL, PHP. It is developed for the mac operating system. Download link: https://www.mamp.info/en/downloads/
- XAMPP: XAMPP is the acronym for the software stack Cross, Apache, MySQL, PHP, Perl. It is developed for the cross-platform. Download link: https://www.apachefriends.org/download.html
How to install XAMPP:
Even though XAMPP supports every operating system we are showing the steps to install XAMPP on windows
- Download the XAMPP application according to the system specification.
- After the successful download run the .exe file and grant the required permissions for the installation.
- Select all the required components and click next
- Select the folder where to install the xampp on the system or set it as the default path and click next
- Click on the Next button
- Click on the Next button to install the xampp
- Click on the finish button to complete the installation process
- Select the language
- Now XAMPP is ready to use. Click on the start button of Apache and MySQL
- if there is no error occurred XAMPP will run successfully
If XAMPP run successfully the PHP programs can be run on the localhost.
How to run a PHP program?
- Open any text editor for this program we are using notepad
- Write the PHP code in the notepad. For example, we are writing the code to print Hello World
- To save the file click on save or save as menu in file menu or use the shortcut ctrl + s or ctrl + shift + s
- Now select the xampp folder from the drive
- Then select the htdocs folder from the xampp folder
- Then create a new folder for saving the PHP file. Here we are creating a folder in name as the demo
- Now we have to give a name to the PHP file, here we are saving in name as “first_program” with the extension “.php” (a PHP file should always be saved with the extension of .php). Then change the save as type to “all files” and save the file by clicking on the save button.
- After saving the file we should open the control panel of XAMPP
- if there is no error occurred the window will open as below. Then we have to click on the start button of Apache and MySQL
- If it successfully starts Apache and MySQL we can see green color on Apache and MySQL and PID corresponding to it.
- After the successful start of Apache and MySQL open the localhost on any web browser according to your preference. Now we can see the folder we created with the name of “demo” and on opening the folder we can see the PHP file we created in the name of “first_program”
- On opening the PHP file the program will run and the output will be visible on the screen