0% complete

PHP Introduction · Lesson 3 of 7

Installing PHP

Install PHP and verify that the command line can run it.

Lesson

Install a supported PHP version using an operating-system package manager, a maintained PHP distribution, or a local development stack. Keep the PHP runtime and extensions updated, and use the same major version as your project. Verify the installation Run php --version in a terminal. If the command is not found, check that the PHP executable is on your PATH. Then create a file named hello.php and run php hello.php. For a local development server, open the project directory in a terminal and run php -S 127.0.0.1:8000. Visit that address in your browser. This built-in server is intended for development, not production hosting. Production deployments should use a properly configured web server and PHP process manager with access restricted to the application’s document root. Further guidance For every setup lesson, verify which PHP version and extensions are active in the same environment that runs the project. Keep a small reproducible script, use the command-line version output to diagnose configuration problems, and distinguish local development tools from production services. Practice task: Create a fresh example for Installing PHP. Predict the result before running it, then change one input and explain why the result changes. Test a normal case and one boundary or invalid case where it applies. Compare your output with the example and note one rule you would use in a real project.

Code examples

Check your PHP installation
PHP
echo PHP_VERSION;
Expected output
The PHP version installed on your machine.

Key points

  • Check the installed runtime with php --version.
  • The built-in PHP server is for local development only.
  • Use a supported version and install only extensions your project needs.

Your learning progress

Finish this lesson

Optional practice

PHP playground

This site does not execute learner-provided PHP code. Connect a secured PHP sandbox service before enabling code execution.

Execution is disabled. No code is sent to a server.