In this guide you can find how to add your own PHP application on top of the LAMP/MAMP/WAMP Stack or any Virtual Machine or AMI.
How to create the basic application structure?
All PHP application are configured in a similar way in Bitnami. The following folders are into your installation directory or in "/opt/bitnami" if you are using the Virtual Machines or AMIs.
This is the basic folder structure:
- apps/ This is the folder where are all the PHP applications (for example: apps/phpmyadmin, apps/wordpress, etc). In this guide we will use "myapp" name for the folder.
- apps/myapp |- htdocs |- conf |- data (optional)
On Windows: You can create the folders manually
On OS X: On Linux: You can run the following commands:
$ mkdir /installdir/apps/myapp $ mkdir /installdir/apps/myapp/htdocs $ mkdir /installdir/apps/myapp/conf
- apps/myapp/htdocs In this folder you can find the PHP application files. This is where you should copy the application files or your PHP files.
On Linux: You can uncompress the application code into this folder. You can find below two examples for uncompressing a ".zip" file or a ".tar.gz" file:
$ tar -xzvf myapp.tar.gz -C /installdir/apps/myapp/htdocs $ unzip myapp.zip -d /installdir/apps/myapp/htdocs
- apps/myapp/conf/httpd-prefix.conf This is the Apache configuration file to configure your application at "http://example.com/myapp".
Alias /myapp/ "/installdir/apps/myapp/htdocs/" Alias /myapp "/installdir/apps/myapp/htdocs" Include "/installdir/apps/myapp/conf/httpd-app.conf"
- apps/myapp/conf/httpd-app.conf. This is the main configuration file for your application. The content could be different depending on your application.
<Directory /installdir/apps/myapp/htdocs> Options +FollowSymLinks AllowOverride None <IfVersion < 2.3 > Order allow,deny Allow from all </IfVersion> <IfVersion >= 2.3> Require all granted </IfVersion> </Directory>
(If you are using the Virtual Machine or the AMI, remember that "installdir" is /opt/bitnami).
If your application uses .htaccess files, you should change the "AllowOverride None" option with "AllowOverride All". Check this note to move the .htaccess file to the main configuration.
Once you have these files, you should add the following line at the bottom of the Apache configuration file "/installdir/apache2/conf/bitnami/bitnami-apps-prefix.conf".
... Include "/installdir/apps/myapp/conf/httpd-prefix.conf"
Then, restart the Apache server and you can access your application at http://example.com/myapp
sudo /installdir/ctlscript.sh restart apache
How to deploy a demo app?
PHP development stacks (LAMP/MAMP/WAMP and LAPP/MAPP/WAPP) ships a "docs" folder with a demo app in the installation directory. This demo application ships the configuration files mentioned in the previous section.
(If you are using the Virtual Machine or the AMI, remember that "installdir" is /opt/bitnami)
- Copy the "demo" folder from the "/installdir/docs/demo" to "/installdir/apps". If you are using Linux or OS X you can do that from a Terminal:
$ cd installdir $ cp -r docs/demo apps
- Then add the following entry in the "/installdir/apache2/conf/bitnami/bitnami-apps-prefix.conf" file:
How to enable PHP-FPM in your custom application?
Take into account that PHP-FPM won't work on Windows systems.
The first thing you need to do is to enable PHP-FPM in your Apache server. To do it, you can follow the steps in this wiki entry.
Once it is done, you need to configure your application properly to use PHP-FPM. You have to modify some files
Insert the following lines at the beginning
<IfDefine USE_PHP_FPM> <Proxy "unix:/installdir/php/var/run/myapp.sock|fcgi://myapp-fpm" timeout=300> </Proxy> </IfDefine>
And then these ones inside the Directory
<Directory "/installdir/apps/myapp/htdocs"> .... <IfDefine USE_PHP_FPM> <FilesMatch \.php$> SetHandler "proxy:fcgi://myapp-fpm/" </FilesMatch> </IfDefine> </Directory
Now, create the folder php-fpm inside the conf directory, so that the structure is like this
apps/myapp |- htdocs |- conf |- php-fpm |- data (optional)
and create a file called pool.conf inside with the following content
[myapp] listen=/installdir/php/var/run/myapp.sock include=/installdir/php/etc/common-dynamic.conf include=/installdir/apps/myapp/conf/php-fpm/php-settings.conf include=/installdir/php/etc/environment.conf pm=dynamic
Now you need to include the following line in the php-fpm.conf conf
Finally restart Apache
/installdir/ctlscript.sh restart apache
If are using a virtual machine or cloud image, or in the case that you installed as root a native installer for Mac OS X or Linux, you need to give read permissions to the the apache user or group. In these installations apache is running as the daemon user.
sudo chgrp daemon /opt/bitnami/apps/demo/htdocs
|NOTE: This guide uses "/opt/bitnami" to refer to the installation directory. This is the default installation directory for Virtual Machines and Cloud Images. If you have installed your Bitnami stack in a different folder, replace "/opt/bitnami" with your installation directory in the examples.|