generallamp

Get started with Laminas

NOTE: We are in the process of modifying the file structure and configuration for many Bitnami stacks. On account of these changes, the file paths stated in this guide may change depending on whether your Bitnami stack uses native Linux system packages (Approach A), or if it is a self-contained installation (Approach B). To identify your Bitnami installation type and what approach to follow, run the command below:

 $ test ! -f "/opt/bitnami/common/bin/openssl" && echo "Approach A: Using system packages." || echo "Approach B: Self-contained installation."

The output of the command indicates which approach (A or B) is used by the installation, and will allow you to identify the paths, configuration and commands to use in this guide. Refer to the FAQ for more information on these changes.

Approach A: Bitnami installations using system packages

The Laminas Project was previously known as Zend Framework, and is not included by default in Bitnami installations. However, it can be easily enabled using Composer. In this guide, you will learn how to install and configure a Laminas project.

Installation and Testing

NOTE: This section assumes that the application project directory will be located at /opt/bitnami/projects/APPNAME. Remember to replace the APPNAME placeholder with the application name, such as myapp.

  • First, create a project directory where to store your application. Run the following commands:

    $ sudo mkdir -p /opt/bitnami/projects/APPNAME
    $ sudo chown $USER /opt/bitnami/projects/APPNAME
    
  • Create the Laminas project. Run the following command:

    $ composer --no-interaction create-project -s dev laminas/laminas-mvc-skeleton /opt/bitnami/projects/APPNAME
    
  • Grant write permissions for the web server to the data directory. Run the following command:

    $ sudo chown daemon:daemon /opt/bitnami/projects/APPNAME/data
    
  • Create the Apache configuration for your application. Follow these steps:

    • Create the /opt/bitnami/apache2/conf/vhosts/APPNAME-vhost.conf file containing the application’s HTTP virtual host configuration with the configuration block shown below:

      <VirtualHost 127.0.0.1:80 _default_:80>
        ServerAlias *
        DocumentRoot /opt/bitnami/projects/APPNAME/public
        <Directory "/opt/bitnami/projects/APPNAME/public">
          Options -Indexes +FollowSymLinks -MultiViews
          AllowOverride All
          Require all granted
        </Directory>
      </VirtualHost>
      
    • Create the /opt/bitnami/apache2/conf/vhosts/APPNAME-https-vhost.conf file containing the application HTTPS virtual host configuration with the configuration block shown below:

      <VirtualHost 127.0.0.1:443 _default_:443>
        ServerAlias *
        DocumentRoot /opt/bitnami/projects/APPNAME/public
        SSLEngine on
        SSLCertificateFile "/opt/bitnami/apache2/conf/bitnami/certs/server.crt"
        SSLCertificateKeyFile "/opt/bitnami/apache2/conf/bitnami/certs/server.key"
        <Directory "/opt/bitnami/projects/APPNAME/public">
          Options -Indexes +FollowSymLinks -MultiViews
          AllowOverride All
          Require all granted
        </Directory>
      </VirtualHost>
      
  • Finally, restart the Apache server:

    $ sudo /opt/bitnami/ctlscript.sh restart apache
    

You can now verify that the example application is working by visiting its URL using your browser at http://SERVER-IP/. Here is an example of what you might see:

Laminas welcome page

Configuration

If your application will use a database, MySQL support is already available by default. If you plan to use PostgreSQL, enable the pdo_pgsql extension in the /opt/bitnami/php/etc/php.ini file.

extension=pdo_pgsql

Approach B: Self-contained Bitnami installations

The Laminas Project was previously known as Zend Framework, and is not included by default in Bitnami installations. However, it can be easily enabled using Composer. In this guide, you will learn how to install and configure a Laminas project.

Installation and Testing

NOTE: This section assumes that the application project directory will be located at /opt/bitnami/frameworks/laminas/htdocs. Remember to replace the APPNAME placeholder with the application name, such as myapp.

  • First, create a project directory where to store your application. Run the following commands:

    $ sudo mkdir -p /opt/bitnami/frameworks/laminas/htdocs
    $ sudo chown $USER /opt/bitnami/frameworks/laminas/htdocs
    
  • Create the Laminas project. Run the following command:

    $ composer --no-interaction create-project -s dev laminas/laminas-mvc-skeleton /opt/bitnami/frameworks/laminas/htdocs
    
  • Grant write permissions for the web server to the data directory. Run the following command:

    $ sudo chown daemon:daemon /opt/bitnami/frameworks/laminas/htdocs/data
    
  • Create the Apache configuration for your application. Follow these steps:

    • Create the Apache configuration directory for the sample application:

      $ sudo mkdir -p /opt/bitnami/frameworks/laminas/conf
      
    • Create and edit the /opt/bitnami/frameworks/laminas/conf/httpd-app.conf file and add the content below to it. This is the main configuration file for your application, so modify it further depending on your application’s requirements.

      <Directory /opt/bitnami/frameworks/laminas/htdocs/public>
          Options -Indexes +FollowSymLinks -MultiViews
          AllowOverride All
          Require all granted
      </Directory>
      
    • Create and edit the /opt/bitnami/frameworks/myapp/conf/httpd-prefix.conf file and add the following configuration block:

      Alias /laminas/ "/opt/bitnami/frameworks/laminas/htdocs/public"
      Alias /laminas "/opt/bitnami/frameworks/laminas/htdocs/public"
      Include "/opt/bitnami/frameworks/laminas/conf/httpd-app.conf"
      
    • Edit the Apache configuration file at /opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf and add the following line

      Include "/opt/bitnami/frameworks/laminas/conf/httpd-prefix.conf"
      
  • Finally, restart the Apache server:

    $ sudo /opt/bitnami/ctlscript.sh restart apache
    

You can now verify that the example application is working by visiting its URL using your browser at http://SERVER-IP/. Here is an example of what you might see:

Laminas welcome page

Configuration

Before using the example application, here are a few important points to consider:

  • If your application will use a database, MySQL support is already available by default. If you plan to use PostgreSQL, enable the php_pdo_pgsql extension in the /opt/bitnami/php/etc/php.ini file.

    extension=php_pdo_pgsql
    
  • To move the Laminas application such that it is available at the root URL of the server (without the /laminas URL suffix), follow these steps:

    • Edit the /opt/bitnami/frameworks/laminas/conf/httpd-prefix.conf file so that it looks like this:

      DocumentRoot "/opt/bitnami/frameworks/laminas/htdocs/public"
      #Alias /laminas/ "/opt/bitnami/frameworks/laminas/htdocs/public"
      #Alias /laminas "/opt/bitnami/frameworks/laminas/htdocs/public"
      Include "/opt/bitnami/frameworks/laminas/conf/httpd-app.conf"
      
    • Restart the Apache server:

      $ sudo /opt/bitnami/ctlscript.sh restart apache
      

    You should now be able to access the example application at the root URL of your server.

More Information

Learn more about developing applications with the Laminas Project at https://docs.laminas.dev/.

Last modification June 10, 2020