How to setup PHP Development Environment | Install Apache – MySQL – PHP
What Is PHP? And Why I should learn PHP for developing a website?
PHP stands for PHP: Hypertext Preprocessor. Generally speaking, PHP is used to add a functionality to websites that HTML alone can’t achieve. PHP is a scripting language is used for creating websites in the following ways: perform calculation, collect user information (such as submit form, comment…), interact with database (MySQL, Postgress and so on…), create graphics, work with cookies….
What software do I need to write PHP?
PHP code is plain text and can be created in any text editor, such as Notepad on Windows or TextEdit on Mac OS X. Besides you can also use some PHP IDE such as: Netbeans, Zend Studio, PHP Storm, Dreamweaver, Komodo… for catching error easily when coding.
What you need for a local test environment?
To test PHP pages on your local computer, you need to install the following:
- A web server (Apache /IIS/Nginx)
Instead of installing each of software and configure for Apache work with PHP & MySQL, you should install XAMPP or WAMPP. It will help you save a lot of time when configuring.
XAMPP installs Apache, PHP, MySQL, phpMyAdmin, and several other tools on your computer in a single operation. Apart from the time it takes to download, the installation process normally takes less than five minutes. Once it has been installed, you need to change a few settings (change MySQL password), but most changes can be made through a web interface.
How to install XAMPP?
1. In a browser, go to https://www.apachefriends.org and download XAMPP for Windows.
2. Close all applications on your computer, and double-click the .exe file you downloaded. A dialog box asks you where you want to install XAMPP. The default is C:\. If you select the default, all the necessary files are extracted to a new folder called C:\xampp. Tips: You should select D partition or another data partitions to keep all your source code in XAMPP if your operating system corrupts and must be reinstalled .
At the end of the extraction process, the installer opens a Windows Command Prompt window with a series of questions about installation options. Type y or n, depending on your preference, and press Enter.
3. Start the XAMPP Control Panel. Start Apache and MySQL by clicking the top two Start buttons in the XAMPP Control Panel. If the servers start up without error, the control panel should display Running alongside Apache and MySQL, and the labels on the Start buttons should change to Stop
To verify that Apache and MySQL are running properly on your development machine. Simply open a browser and go to the following address: http://localhost. If everything has gone correctly, you’ll be redirected to http://localhost/dashboard/ like below screenshot.
The address, http://localhost, is an alias for the current computer you’re working on. When using XAMPP, navigating to http://localhost in a browser tells the server to open the root web directory. This is the htdocs folder contained in the XAMPP install directory.
Another way to use your server to access the root web directory on your local machine is to navigate to the IP address 127.0.0.1 —a numerical identifier assigned to any device connected to a computer network—that serves as the “home” address for all HTTP servers.
Write Your First PHP Page
Now open notepad or notepad++ or any your favorite PHP IDE such as: Netbeans, Eclipse, Komodo, PHP Storm…In this tutorial I will use notepad. And I will have a more detail tutorial about how to use PHP IDE in developing PHP website.
Open Notepad and type the following line:
<?php echo "Welcome to learncode24h.com"; ?>
Save this file with name welcome.php to htdocs in XAMPP. Open browser and type http://localhost/welcome.php and you will see the following page. echo statement ‘s used for printing a string on browser and we put a string in double quotes. If you have any problems when practicing, please leave a comment below.