Guides
PHP application

Quickstart guide for a PHP application

In this guide, you'll learn the process of deploying a PHPapplication on Wasmer Edge. We will cover installation of the CLI, setting up a new PHP application, and deploying it.

Deploying a PHP application

Install Wasmer

Click here for instructions on how to install Wasmer if you haven't done it already!

Initialize the local directory

With the CLI installed, let's create a new PHP application! We begin creating a new empty directory - after that, we will need to run a single command.

$ mkdir my-php-application 
$ cd my-php-application
$ wasmer deploy --template=php-starter
It seems you are trying to create a new app!
 Who should own this app? · <you> 
 What should be the name of the app? · <your-app-name> 
 Unpacked template
 Do you want to deploy the app now? · yes
Loading local package (manifest path: <current-working-directory>)
 Correctly built package locally
 Package correctly uploaded
 Succesfully pushed release to namespace <you> on the registry 
Deploying app <your-app-name> (<you>) to Wasmer Edge...
 
App <your-app-name> (<you>) was successfully deployed 🚀
https://<your-app-name>-<you>.wasmer.app
 
 Unique URL: https://<app_id>.id.wasmer.app
 Dashboard:  https://wasmer.io/apps/<you>/<your-app-name>
 
Waiting for new deployment to become available...
(You can safely stop waiting now with CTRL-C)
.
𖥔 Deployment complete

The wasmer deploy --template=php-starter command will prompt you for the following:

  • App owner: This is the owner of the app. It can be your username or an organization; if you're logged in, the command will prompt you to choose from your namespaces: by default, it will be your username.
  • App name: This is the name of your app. By default, it will be the name of the current directory.

The above command will do the following:

  • Download the template from the registry
  • Deploy it to Wasmer Edge with the user-provided informations

Let's check it:

$ curl https://<your-app-name>-<you>.wasmer.app
1	=>	PHP code tester Sandbox Online
emoji	=>	😀 😃 😄 😁 😆
2	=>	5
5	=>	89009
Random number	=>	<random!>
PHP Version	=>	8.3.4

Update the app

Your directory should now look like this:

    • index.php
    • info.php
  • README.md
  • app.yaml
  • wasmer.toml
  • To illustrate the lifecycle of an app, let's edit the index.php file in the app folder:

    app/index.php
    <?php 
      echo 'Hello World!';   
      var_dump($_SERVER); 
    ?>

    Now, simply run wasmer deploy again:

    $ wasmer deploy
    Loading local package (manifest path: <current-working-directory>)
     Correctly built package locally
     Package correctly uploaded
     Succesfully pushed release to namespace <you> on the registry 
    Deploying app <your-app-name> (<you>) to Wasmer Edge...
     
    App <your-app-name> (<you>) was successfully deployed 🚀
    https://<your-app-name>-<you>.wasmer.app
     
     Unique URL: https://<app_id>.id.wasmer.app
     Dashboard:  https://wasmer.io/apps/<you>/<your-app-name>
     
    Waiting for new deployment to become available...
    (You can safely stop waiting now with CTRL-C)
    .
    𖥔 Deployment complete

    Let's check it again:

    $ curl https://<your-app-name>-<you>.wasmer.app
    Hello World! <more text..>

    Testing your PHP application locally

    To test your PHP application locally simply run

    $ wasmer run . --net 
    Starting server on http://127.0.0.1:8000
    ℹ️

    You can see all the available options with wasmer run --help or click here to see the full documentation.

    Let's try to cURL the server:

    $ curl http://127.0.0.1:8000
    1	=>	PHP code tester Sandbox Online
    emoji	=>	😀 😃 😄 😁 😆
    2	=>	5
    5	=>	89009
    Random number	=>	286
    PHP Version	=>	8.3.4
    Hello	=>	World

    Conclusion

    Congratulations! You have successfully deployed a PHP application on Wasmer Edge 🚀.

    Tip: To make changes to your PHP application, simply modify the index.php file in the app directory and run wasmer deploy again to deploy the changes.

    Resources

    wasmer-examples/php-wasmer-starter