Environment Setup Guide - PHP

This page contains instructions for setting up the PHP programming language runtimes for various operating systems.

Learnosity can be used with any server-side language. Additionally, we have created language specific Native SDK Integrations for PHP, Java, .Net, Python, Ruby, and Node.js. These allow you get going faster with Learnosity.

Note: There are no specific requirements for Learnosity use within your environment, beyond the inclusion of our SDK mentioned above.

On this page:

PHP comes preinstalled on some macOS versions, so no install may be required, and you can potentially run PHP right away by opening the Console and typing:

php -S localhost:8000

The folder where you run that command will be treated as the web root.

If you get an error such as "php: command not found", use the following command to install PHP:

brew install php
  1. From the command line, run sudo apt install php and enter your password.
  2. The latest version of PHP will be installed.

The following steps are the same for macOS and Linux operating systems.

Create your Hello World PHP file (macOS / Linux)

Create a new www folder in your ~/Public directory. You can do this from the command line using mkdir ~/Public/www.

Open a blank text file, copy-paste the following sample, and save it to ~/Public/www/hello.php.

<html>
    <head>
        <title>PHP Test</title>
    </head>
    <body>
        <?php echo '<p>Hello World</p>'; ?>
    </body>
</html>

This hello world example is from the PHP documentation.

Start your PHP server (macOS / Linux)

PHP comes with its own basic web server, which can be used for development and testing. To start the server:

  1. From the command line, navigate to /Documents/www
  2. Run the following command: php -S localhost:8000. You should see output like this:
lrn$ php -S localhost:8000
PHP 8.x Development Server started at $date, $time
Listening on http://localhost:8000
Document root is ~/Public/www
Press Ctrl-C to quit.

Test your PHP server (macOS / Linux)

  1. Point your web browser to http://localhost:8000/hello.php.
  2. A plain web page with “Hello World” at the top should appear. If so, your PHP server is working. If not, follow the Linux troubleshooting instructions in the PHP documentation.
  3. Setup complete.

 

Install PHP and the Microsoft Visual C libraries

Below, choose a version of PHP, in the 8.x range.

Installing PHP 8.x on Windows

  1. Go to the official PHP site, select a version of PHP 8.x and download the zip file from the download page.
  2. Download the file, choosing the Zip archive format.
  3. Extract the contents to a new folder, for example, C:\php. Ensure that php.exe is at the top level of this folder.

Installing the Microsoft Visual C++ Redistributable for Visual Studio

The Microsoft Visual C++ Redistributable for Visual Studio 2022 will be neede for your PHP installation and works with most contemporary PHP versions. Visit this page to download and install the applicable x86 or x64 flavored file for your operating system.

Once that's done, move on to the next step.

Adding the PHP folder to the Windows path environment variable

  1. Go to Start > Settings. In the Settings dialog, type 'environment variables' into the search bar. Click Edit the System Environment Variables. The System Properties dialog appears.
  2. Click the Environment Variables button. The Environment Variables dialog appears.
  3. Select the Path variable under System variables in the lower half of the window and then click Edit. The Edit environment variable dialog appears.
  4. Windows 10: append ;C:\php to the end of the path variable, or
  5. Windows 11: click the New button and enter C:\php . Click Ok to confirm (if you selected a different folder for the PHP location, then use that location instead).
  6. Click Ok on the Environment Variables dialog.
  7. Restart any open command line windows for the new settings to take effect.

Create your PHP “Hello World” file (Windows)

  1. Create a new www folder on your hard drive, for example, at C:\www.
  2. Open a blank text file, copy-paste the following sample, and save it to C:\www\hello.php:
<html>
    <head>
        <title>PHP Test</title>
    </head>
    <body>
        <?php echo '<p>Hello World</p>'; ?>
    </body>
</html>

Note: Ensure that hello.php has not been named hello.php.txt by your text editor. If it has, rename it to hello.php. This hello world example is from the PHP documentation.

Start your PHP server (Windows)

PHP comes with its own basic web server, which can be used for development and testing. To start the server:
  1. Open the Command Prompt then navigate to C:\www.
  2. Run the following command: php -S localhost:8000 
    You should see output like this:
C:\www> php -S localhost:8000
PHP 8.x Development Server started at $date, $time
Listening on http://localhost:8000
Document root is C:\www
Press Ctrl-C to quit.

Test your PHP server (Windows)

  1. Point your web browser to http://localhost:8000/hello.php.
  2. If your PHP server is working, a plain white page with “Hello World” at the top should appear. If not, follow the troubleshooting instructions on the PHP site.
  3. Setup complete!
Was this article helpful?

Did you arrive here by accident? If so, learn more about Learnosity.