aws-templateslamp-production-ready

Deploy a PHP application

The broad steps to deploy a PHP application on Bitnami LAMP Production-Ready Stack are as follows:

  • Connect to any of the application instances over SSH.

  • Create a directory for the application in the /bitnami directory and give it appropriate permissions:

      $ sudo mkdir /bitnami/myapp
      $ sudo chown bitnami:bitnami /bitnami/myapp
    
  • Create a virtual host for the PHP application pointing to its public directory and save the corresponding configuration in the /opt/bitnami/apache/conf/vhosts/ directory:

      <VirtualHost *:80>
        DocumentRoot "/bitnami/myapp/public"
        DirectoryIndex index.php
    
        <Directory "/bitnami/myapp/public">
          Options Indexes FollowSymLinks
          AllowOverride All
          Require all granted
        </Directory>
      </VirtualHost>
    
  • Check the Apache configuration and confirm that the syntax is correct:

      $ apachectl configtest
    
  • Perform any related database initialization or configuration.

  • Restart services on each instance:

      $ sudo service bitnami restart
    

When you access the Elastic Load Balancer URL, you should now see the welcome page of the PHP application.

Example deployment: Laravel application

The following example demonstrates the commands and configuration needed to deploy a standard Laravel PHP application on Bitnami LAMP Production-Ready Stack.

  • Connect to any of the application instances over SSH.

  • Create a directory for the application in the /bitnami directory and give it appropriate permissions:

      $ sudo mkdir /bitnami/laravel
      $ sudo chown bitnami:bitnami /bitnami/laravel
    
  • Create a new Laravel application:

      $ composer create-project --prefer-dist laravel/laravel /bitnami/laravel
    
  • Update directory permissions:

      $ cd /bitnami/laravel/
      $ sudo chown bitnami:daemon -R storage bootstrap/cache
      $ sudo find storage bootstrap/cache -type f -exec chmod 664 {} \;
      $ sudo find storage bootstrap/cache -type d -exec chmod 775 {} \;
    
  • Create a virtual host for the Laravel application pointing to its public directory and save the corresponding configuration as /opt/bitnami/apache/conf/vhosts/laravel-vhost.conf:

      <VirtualHost *:80>
        DocumentRoot "/bitnami/laravel/public"
        DirectoryIndex index.php
    
        <Directory "/bitnami/laravel/public">
          Options Indexes FollowSymLinks
          AllowOverride All
          Require all granted
        </Directory>
      </VirtualHost>
    
  • Check the Apache configuration and confirm that the syntax is correct:

      $ apachectl configtest
    
  • Connect to the Amazon RDS database service using the MySQL command-line client and run the commands below to create a new database and user for the application:

      mysql> create database laravel;
      mysql> grant all privileges on laravel.* TO 'laravel'@'%' identified by 'guessme';
      mysql> flush privileges;
    
  • Put (or substitute) the values of the newly-created database and user in the /bitnami/laravel/.env file. Replace the URL-ENDPOINT placeholder with the correct endpoint for your Amazon RDS deployment:

      DB_CONNECTION=mysql
      DB_HOST=URL-ENDPOINT
      DB_PORT=3306
      DB_DATABASE=laravel
      DB_USERNAME=laravel
      DB_PASSWORD=guessme
    
  • Make substitutions in the Laravel database configuration for Amazon RDS:

      $ sed -i "s/utf8mb4/utf8/g" /bitnami/laravel/config/database.php
    
  • Run database migrations:

      $ cd /bitnami/laravel
      $ php artisan migrate
    
  • Restart services on each instance:

      $ sudo service bitnami restart
    

When you access the Elastic Load Balancer URL, you should now see the welcome page of the Laravel application.

TIP: To configure Elasticache to work with the Laravel application, refer to the Laravel cache configuration documentation.

Last modification June 10, 2020