Unit 10 ยท Back-End Programming

10.1.3Setting up a local development environment

  1. Download and install XAMPP (apachefriends.org). It bundles Apache (web server), PHP, MariaDB/MySQL and phpMyAdmin.
  2. Open the XAMPP Control Panel and Start Apache and MySQL (green).
  3. Your web root is the htdocs folder (e.g. C:\xampp\htdocs). Create a folder myapp inside it.
  4. Create myapp/hello.php:
PHP
<!DOCTYPE html>
<html>
<body>
  <h1>Hello from PHP</h1>
  <?php
    echo 'Today is ' . date('Y-m-d H:i') . '<br>';
    echo 'Your IP: ' . $_SERVER['REMOTE_ADDR'];
  ?>
</body>
</html>
  1. Open http://localhost/myapp/hello.php in the browser. (Never double-click the file: it must be served through http://localhost.)
  2. phpMyAdmin is at http://localhost/phpmyadmin.

Troubleshooting: port 80 in use (stop Skype/IIS or change Apache port to 8080 and use localhost:8080); blank page (turn on errors: ini_set('display_errors', 1); error_reporting(E_ALL); while developing, and read xampp/apache/logs/error.log); "file download instead of run" (you opened the wrong URL or Apache is off). Alternative: php -S localhost:8000 in a folder if PHP is installed.