Skip to content

PHP and static sites

Custom PHP and Static applications run your own code. Create a server of that type first, then add applications to it.

A Custom PHP application runs your PHP code on the server’s PHP, behind Nginx.

  • Database: optional. When you add the application, Create a database is ticked; untick it if you don’t need one. The application uses the database engine chosen when the server was created, MySQL (MariaDB), MySQL 8 or PostgreSQL; it can’t be changed later. The database’s name, user and password are shown under Database › Databases, and PHP can read them with getenv() (see Connect to the database). An application created without a database has no Databases section.
  • Starting point: a placeholder page. index.php is served first.
  • Web server: Nginx only, so .htaccess files are ignored. Set redirects under Domains & SSL › Redirects.
  • PHP settings: choose the PHP version and limits under Settings › PHP. See PHP settings.

A static application is HTML, CSS, JavaScript and other files, served directly by Nginx.

  • No PHP and no database. The application has no PHP or Databases section.
  • Starting point: a placeholder page. index.html is served first.
  • Web server: Nginx only. Nginx serves the files itself, so .htaccess files are not read.
  • Clean URLs and errors: /about serves about.html when there is no about folder, and a 404.html in the web root is shown for missing pages.
  • Single-page apps: when you deploy from Git, open Static site › Site settings and click Turn on under Single-page app mode to answer index.html for every path that is not a file (React, Vue or Svelte routers). You can also tick Single-page app in the repository settings. It applies from the next deploy.

You have three ways to replace the placeholder:

  • Upload with SFTP using the application’s login under Files › SSH / SFTP. Your files go in htdocs, the application’s web root.
  • Use the file manager to upload, edit and unpack files in the browser.
  • Deploy from Git under Deployments. See Deploy from Git. A Custom PHP application can use the PHP or Laravel preset, and a static application the Static preset. The PHP and Static presets run no build commands. For a site that needs one, add build commands such as composer install or npm ci and npm run build, and set the Publish directory to the folder to serve, such as public or dist. Node.js is available to the build when a build command uses npm, npx or node. After each deploy, Netkeel loads the home page; if it answers with a server error (5xx), the previous release goes back live. You can turn the check off in the repository settings.

A Custom PHP application with a database gets its connection details as environment variables of its PHP, so your code reads them with getenv() (or $_SERVER) and you don’t copy the password into your files:

Variable MySQL (MariaDB) or MySQL 8 PostgreSQL
DB_CONNECTION mysql pgsql
DB_HOST localhost /var/run/postgresql (the socket folder)
DB_PORT 3306 5432
DB_DATABASE, DB_USERNAME, DB_PASSWORD The database name, user and password The database name, user and password
DB_SOCKET /run/mysqld/mysqld.sock Not set

A PostgreSQL application also gets DATABASE_URL and PGHOST, PGPORT, PGSOCKET, PGDATABASE, PGUSER and PGPASSWORD. See PostgreSQL databases.

With PDO and MySQL:

$pdo = new PDO(
"mysql:unix_socket=" . getenv("DB_SOCKET") . ";dbname=" . getenv("DB_DATABASE"),
getenv("DB_USERNAME"),
getenv("DB_PASSWORD")
);

With PostgreSQL, use "pgsql:host=" . getenv("DB_HOST") . ";dbname=" . getenv("DB_DATABASE") as the first argument.

If you change the database user’s password under Database › Databases, PHP gets the new one in the same step, so code that reads DB_PASSWORD keeps working.

Staging, cloning, moving to another server and import and export are WordPress-only for now. Backups work as for every application. To bring a site from another host, see Move a site to Netkeel.