Connect a web application to MySQL

The web service receives HTTP requests while MySQL stores records. They are separate services: the application connects using the MySQL protocol.

1. Use one project and environment

Create Web and MySQL services in the same project and environment, such as production. Review database resource costs and top up before starting paid resources. Do not replace an existing database password.

2. Set connection variables

Obtain MYSQL_HOST, MYSQL_PORT, MYSQL_DATABASE, MYSQL_USER and MYSQL_PASSWORD from the database connection settings. Ensure these variables reach the web service. The host may be an internal network address.

3. Use the PHP example

The lixev/mysql-demo branch of the testrender4 repository below contains a PDO MySQL form. Its Dockerfile installs pdo_mysql. The example creates only the lixev_demo_messages table.

4. Verify persistence

Submit a test message, reload the page, then open it in a fresh browser session. The record should load from MySQL again. Do not submit personal information to the public demonstration form.

5. Connect from your computer

Opening a MySQL address with https:// does not provide a database administration interface. DBeaver needs a TCP host and port or an SSH tunnel. An internal host may not be directly reachable from your computer.

This form was tested on Lixev: a direct SQL query confirmed the record, and a fresh browser session loaded it again. Check backups and persistent storage separately.