<commit_before>---
layout: default
title: Getting Started with PHP
---

# Getting Started with PHP

This guide walks you through setting up a basic PHP web application with tests.

 1. Create and switch to project directory

        $ mkdir php-example
        $ cd php-example

 1. Create `.rock.yml`

        runtime: php54

 1. Create `php.ini`

        extension=dom.so

 1. Create `composer.json`

        {
            "require": {
                "EHER/PHPUnit": "*",
                "slim/slim": "*"
            }
        }

 1. Build project

        $ rock build

 1. Create `public` directory

        $ mkdir public

 1. Create `lib` directory

        $ mkdir lib

 1. Create `lib/web.php`

        <?php

        require __DIR__ . '/../vendor/autoload.php';

        function greeting() {
            return 'Hello World';
        }

 1. Create `public/index.php`

        <?php

        require __DIR__ . '/../lib/web.php';

        $app = new \Slim\Slim();

        $app->get('/', function () {
            echo greeting();
        });

        $app->run();

 1. Create `bin` directory

        $ mkdir bin

 1. Create `bin/hello-world`

        #!/usr/bin/env bash

        exec php -S "${HTTP_HOST-127.0.0.1}:${HTTP_PORT-8000}" -c "${PROJECT_PATH}/php.ini" -t "${PROJECT_PATH}/public"

 1. Make it executable

        $ chmod 755 bin/hello-world

 1. Start `hello-world` and kill it using Ctrl+C<commit_msg>Remove php.ini and switch to phpunit in php54<commit_after>---
layout: default
title: Getting Started with PHP
---

# Getting Started with PHP

This guide walks you through setting up a basic PHP web application with tests.

 1. Create and switch to project directory

        $ mkdir php-example
        $ cd php-example

 1. Create `.rock.yml`

        runtime: php54

 1. Create `composer.json`

        {
            "require": {
                "phpunit/phpunit": "*",
                "slim/slim": "*"
            }
        }

 1. Build project

        $ rock build

 1. Create `public` directory

        $ mkdir public

 1. Create `lib` directory

        $ mkdir lib

 1. Create `lib/web.php`

        <?php

        require __DIR__ . '/../vendor/autoload.php';

        function greeting() {
            return 'Hello World';
        }

 1. Create `public/index.php`

        <?php

        require __DIR__ . '/../lib/web.php';

        $app = new \Slim\Slim();

        $app->get('/', function () {
            echo greeting();
        });

        $app->run();

 1. Create `bin` directory

        $ mkdir bin

 1. Create `bin/hello-world`

        #!/usr/bin/env bash

        exec php -S "${HTTP_HOST-127.0.0.1}:${HTTP_PORT-8000}" -t "${PROJECT_PATH}/public"

 1. Make it executable

        $ chmod 755 bin/hello-world

 1. Start `hello-world` and kill it using Ctrl+C
{'fraction_non_alphanumeric': 0.1306980056980057, 'fraction_numerical': 0.0202991452991453, 'mean_word_length': 1.6650853889943074, 'pattern_counts': {'":': 6, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1343979', 'n_tokens_mistral': 959, 'n_tokens_neox': 829, 'n_words': 260}