> ## Documentation Index
> Fetch the complete documentation index at: https://docs.squarecloud.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Host a PHP Website or API

> Host a PHP website or API on Square Cloud: set MAIN to index.php, let Square Cloud install your Composer packages, and serve with the built-in server or Swoole.

The PHP runtime serves PHP websites and APIs. It includes Composer, Node.js for asset builds, and the Swoole extension.

## Before you begin

* PHP on your machine. If you don't have it, download it from the [official PHP website](https://www.php.net/).
* A Square Cloud account: [sign up](https://squarecloud.app/en/signup) with your email or GitHub.
* An active plan. See the [plans](https://squarecloud.app/en/pricing) and pick the one that fits your project.

## Configure Square Cloud

<Note>
  If you upload your application through the dashboard, you can skip this section: the dashboard creates the `squarecloud.app` configuration file for you.
</Note>

<Card title="Configuration file reference" icon="link" href="/en/getting-started/config-file">
  The `squarecloud.app` file tells Square Cloud how to run your application: its main file, memory, runtime version, name and, for a website, its subdomain.
</Card>

A complete configuration file for a website or API:

```systemd squarecloud.app theme={"system"}
MAIN=index.php
MEMORY=512
VERSION=recommended
DISPLAY_NAME=My website
SUBDOMAIN=mywebsite
```

## What Square Cloud runs

* If the `START` field is not defined in the configuration file, a local PHP server will be started with the command `php -S 0.0.0.0:80`, with the root of your ZIP as the document root. If the `START` field is defined, the value in it will be executed directly. For more information about configuration file parameters, visit [configuration parameters](/en/getting-started/config-file#configuration-parameters).

* If your project has a `composer.json` at its root, Square Cloud runs `composer install` before every start, so you don't need it in `START`. It uses the `composer.phar` from your ZIP when there is one, and the Composer included in the runtime otherwise. Upload `composer.lock` too, so the server installs the same versions you tested.

### Port and host

The default command already listens on port 80 and all network interfaces (`0.0.0.0`). When you write your own `START`, keep both: Square Cloud sets the `PORT` environment variable to `80`, and a server that listens only on `127.0.0.1` never receives requests.

## PHP with Swoole

* Swoole is a tool that improves standard PHP performance enabling the webserver to handle multiple requests asynchronously.

* With this tool, you can create microservices, websockets, background queues, among others. It also allows you to execute events just like JavaScript does.

* It is also important to mention that Swoole is compatible with other PHP frameworks. A good example of a PHP framework is Laravel which is compatible with Swoole thanks to Octane.

* You can use it instead of the standard PHP server by defining your custom START command. Example:

```bash theme={"system"}
npm install && npm run build && php artisan optimize && php artisan octane:start --host=0.0.0.0 --port=80 --workers=4 --task-workers=8 --server=swoole
```

* You can check out all the powerful functions of Swoole in the [Swoole manual](https://www.php.net/manual/en/book.swoole.php).

## Prepare the project

### Required files

* [`squarecloud.app`](/en/getting-started/config-file), at the root of the ZIP.
* `index.php`, or the file set in `MAIN`.
* `composer.json` and `composer.lock`, when you use Composer packages.

Square Cloud installs the packages listed in `composer.json` on its own. If your project also has Node dependencies (a `package.json`) to build assets, install and build them in `START`. For example:

```systemd squarecloud.app theme={"system"}
START=npm install && npm run build && php -S 0.0.0.0:80
```

<Warning>The configuration file (`squarecloud.app`) must be located at the root of the zip file. Otherwise, Square Cloud will not be able to find it during deploy.</Warning>

### What to leave out

* Your local `.env` file: set your secrets as [environment variables](/en/platform/environment-variables) instead. The default server uses the root of the ZIP as the document root, so any file you upload there can be downloaded.
* `vendor/`: Square Cloud installs it from `composer.json`.
* `node_modules/`, when your `START` command installs it.

## Framework guides

<CardGroup cols={3}>
  <Card title="Laravel" icon="laravel" href="/en/tutorials/api/laravel" />
</CardGroup>

## Deploy

### Via dashboard

<Steps>
  <Step title="Access the Upload Page">
    Access the [upload page](https://squarecloud.app/en/dashboard/new) and upload your project zip file.
  </Step>

  <Step title="Configure Your Environment">
    After uploading your zip, you will need to configure the name, main file or runtime environment and other settings for your project.\
    If you are uploading a web project, make sure to select "Web Publication" and set a subdomain to your project.
  </Step>

  <Step title="Deploy Your Project">
    Finally, click on the "Deploy" button to host your project on Square Cloud.\
    After deployment, you can monitor your project's status and logs from the dashboard.

    <Frame>
      <img src="https://cdn.squarecloud.app/docs/articles/dashboard/uploading.gif" alt="Uploading application to Square Cloud" style={{ borderRadius: "0.2rem" }} />
    </Frame>
  </Step>

  <Step title="Confirm Your App Is Live">
    Your first deploy usually takes less than a minute. In the [dashboard](https://squarecloud.app/en/dashboard), wait for your application status to show as running and check the logs for any startup errors.\
    If you deployed a website or API, open `https://<your-subdomain>.squareweb.app` in your browser: you should see your application responding. If you deployed a bot, send it a command to confirm it is online.
    <Tip>App not starting? See the [Troubleshooting guide](/en/platform/troubleshooting/app-wont-start) for the most common causes and fixes.</Tip>
  </Step>
</Steps>

### Via CLI

To use this method, your project needs a configuration file named `squarecloud.app` at its root. It tells Square Cloud how to run your application.

<Card title="Configuration file guide" icon="link" href="/en/getting-started/config-file">
  Learn how to create the `squarecloud.app` configuration file that defines your application's environment.
</Card>

<Steps>
  <Step title="Install the CLI">
    Install the [Square Cloud CLI](/en/cli-reference/installation). If you already have it, run the same command to update it:

    <CodeGroup>
      ```bash macOS, Linux, and WSL theme={"system"}
      curl -fsSL https://cli.squarecloud.app/install | bash
      ```

      ```bash Windows with npm theme={"system"}
      npm install -g @squarecloud/cli@latest
      ```
    </CodeGroup>
  </Step>

  <Step title="Log In">
    Run the command below. It opens your browser: approve the login there and the CLI is ready. There is no API key to copy. For scripts and CI, see [CLI authentication](/en/cli-reference/authentication).

    ```bash theme={"system"}
    squarecloud auth login
    ```
  </Step>

  <Step title="Upload Your Project">
    From your project folder, run the command below. The CLI zips the current folder, leaving out what [`squarecloud.ignore`](/en/getting-started/squarecloud-ignore) lists, and uploads it:

    ```bash theme={"system"}
    squarecloud upload
    ```

    To upload a zip you created yourself, pass it with `--file`:

    ```bash theme={"system"}
    squarecloud upload --file <path/to/zip>
    ```
  </Step>

  <Step title="Confirm Your App Is Live">
    Your first deploy usually takes less than a minute. Check your application status and logs directly from the terminal:

    ```bash theme={"system"}
    squarecloud app status
    squarecloud app logs
    ```

    If you deployed a website or API, open `https://<your-subdomain>.squareweb.app` in your browser: you should see your application responding. If you deployed a bot, send it a command to confirm it is online.
    <Tip>App not starting? See the [Troubleshooting guide](/en/platform/troubleshooting/app-wont-start) for the most common causes and fixes.</Tip>
  </Step>
</Steps>

## Next steps

<CardGroup cols={3}>
  <Card title="Environment variables" icon="key" href="/en/platform/environment-variables">
    Keep secrets and settings out of your code and read them at runtime.
  </Card>

  <Card title="Custom domain" icon="globe" href="https://help.squarecloud.app/en-us/article/how-to-set-up-your-own-domain-cnamedns-1fzbrgh/">
    Serve your app on your own domain, on the Standard plan and above.
  </Card>

  <Card title="Troubleshooting" icon="wrench" href="/en/platform/troubleshooting">
    Fix an app that does not start or a site that does not respond.
  </Card>
</CardGroup>

## Contact us

If you continue facing **technical difficulties**, our **specialized support team** is available to assist you. [**Contact us**](https://squarecloud.app/en/support) and we'll be happy to help you resolve any issue: support quality is a big part of why developers rate Square Cloud [**4.9/5 across 402 reviews**](https://www.trustpilot.com/review/squarecloud.app) on Google and Trustpilot.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.