Managing and deploying PHP applications
Starting a PHP application
- mStudio UI
- CLI
- API
To start a PHP application from the mStudio, follow these steps:
- Navigate to the project that you want to create the application in.
- Select the "Apps" menu item in the sidebar.
- Click the "Create App" button and select "Custom PHP app".
After the installation has completed, observe the installation directory in the UI.
To start a PHP application from the CLI, run the following command:
$ mw app create php --wait --document-root /public
The --wait
flag will cause the CLI to wait until the installation has completed. The --document-root
flag can be used to specify a subdirectory of the installation directory to be used as the document root. If the --document-root
flag is not specified, the entire installation directory will be used as the document root.
After the installation has completed, use the mw app get
command to observe the installation directory.
To learn how to deploy a PHP application via the API, read the article "Starting a PHP application".
Deploying your app
Deploying your code
After you have created your PHP app, you can deploy your code by moving it into the designated application directory. You may use any method that you prefer to deploy your code, such as a local Git clone, rsync or SFTP.
Have a look at our collection of deployment guides for more information on how to deploy your code.
Managing OPCache
PHP comes with a built-in opcode cache called OPCache. OPCache is enabled by default, and will cache the compiled PHP code in memory to improve performance. Depending on your configuration, it may take a while for the cache to be updated when you deploy new code.
To force a refresh of the OPCache (for example, after a deployment), you can use tools like CacheTool to connect to the PHP-FPM socket and clear the cache (refer to CacheTool's installation instructions for more information on how to install it). For example, you can run the following command to clear the PHP OPCache:
$ php ./cachetool.phar opcache:reset --fcgi=127.0.0.1:9000
Customizing your PHP configuration
For the entire project
To customize your PHP configuration for the entire project, you can make changes to the ~/.config/php/php.ini
file, or add a new .ini
file to the ~/.config/php/php.d
directory. Changes to these files will be detected automatically, and the PHP-FPM service will be restarted.
Per directory
To customize your PHP configuration for a specific directory, create a .user.ini
file in that directory.1 This file will be parsed by PHP and will override the default configuration.