Hosting LAMP apps on Cloudron - Part 1
2 min read

Hosting LAMP apps on Cloudron - Part 1

The Cloudron is designed to be a platform for self-hosting turnkey applications. It is, however, perfectly capable of running custom LAMP apps as well.

Running LAMP apps on the Cloudron is no different than what is available on many hosting providers. You can upload your PHP code using SFTP and then modify the .htaccess and php.ini files as required. Most commonly used PHP extensions are pre-installed and you don't have to worry about keeping them up-to-date.

The main advantage of using the Cloudron to host your LAMP apps are:

  • DNS configuration, Let's Encrypt (SSL) certificate installation and renewal are automated.
  • You can use MySQL, LDAP, OAuth and send email out of the box.
  • Don't have to worry about app and server backups, restore and updates since the Cloudron takes care of it.
  • Run multiple LAMP apps, isolated from one another, on same server easily.

In this post, we will see an example of how to use the LAMP app and install ImpressPages in it.

Installing the LAMP app

First, install the LAMP app on your Cloudron from the Cloudron App Store.

When installing the app, you can specify the port in which SFTP will be available. You can disable SFTP by unchecking the checkbox, after you are done with using SFTP.

Uploading LAMP app using SFTP

Once installed, you can upload the ImpressPages app using an SFTP client like FileZilla.

  • Download and extract ImpressPages
  • Connect the SFTP client. The hostname is app's domain name. The SFTP port is 2222. The username/password is the same as your cloudron credentials.
  • Upload it to the public/ folder.

Configuring ImpressPages

Once uploaded, you can access ImpressPages by visiting the subdomain where you installed the app. The setup wizard requires the database credentials.

You can get the database credentials using the Cloudron CLItool.

$ sudo npm install -g cloudron

$ cloudron login <your cloudron domain>

$ cloudron list
Id                                    Title  Location  
------------------------------------  -----  --------
73190fd2-059d-4ee0-9ffe-1754e8a490ff  LAMP   impress  

$ cloudron exec --app <app-id> env | grep MSQL_
MYSQL_URL=mysql://aadc89e1a33d90f5:ax1YpQ37zyKlvj92S7oE0SWWQvZc1Tra611EZL9sYOlNjCsKpN2WY1XAfFefIPmktFiE3y6hlCF9u3wLCcRTcrLvuhgg1G9C1MdhlrKRoxas37kbe1qhvYgfAv8Do35z@mysql/aadc89e1a33d90f5
MYSQL_USERNAME=aadc89e1a33d90f5
MYSQL_PASSWORD=ax1YpQ37zyKlvj92S7oE0SWWQvZc1Tra611EZL9sYOlNjCsKpN2WY1XAfFefIPmktFiE3y6hlCF9u3wLCcRTcrLvuhgg1G9C1MdhlrKRoxas37kbe1qhvYgfAv8Do35z
MYSQL_HOST=mysql
MYSQL_PORT=3306
MYSQL_DATABASE=aadc89e1a33d90f5

Fill up the values in the installation wizard based on the values above and you should be set.

Finishing touches

On the Cloudron, we require that credentials (like MySQL access info) be not hardcoded into the app.  Instead, apps should use env vars exposed to them at run time. Such an approach lets the Cloudron cycle mysql passwords periodically as a security measure and also makes apps easily migratable.

Edit the config.php on the server (using FileZilla or the cloudron exec tool) and change the db credentials to the below:

'db' => array (
    'hostname' => getenv("MYSQL_HOST"),
    'username' => getenv("MYSQL_USERNAME"),
    'password' => getenv("MYSQL_PASSWORD"),
    'tablePrefix' => 'ip_',
    'database' => getenv("MYSQL_DATABASE"),
    'charset' => 'utf8',
  ), // Database configuration

You can read more about some enhancements we have added to the LAMP app in part 2.