Laravel is a PHP Web framework with an expressive and elegant syntax that is intended for the development of Web applications. This topic describes how to use Laravel to create an application, link a MySQL database, and deploy the application in Web+.

Prerequisites

Configure a PHP IDE
Notice Before using the Laravel framework to develop applications, you must install PHP 5.5.9 or later.

Step 1: Create an application

  1. Use the following command to call Composer and create a project named webplusdemo. The process requires a few minutes to complete.
    composer create-project --prefer-dist laravel/laravel webplusdemo
  2. Use the following command to start the PHP built-in Web server to run the project.
    php artisan serve
  3. Open a browser, and enter the address shown in the following figure to access the application.

Step 2: Create a deployment package

  1. Navigate to the project directory, and use the following command to enable Laravel built-in authentication components.
    php artisan make:auth
  2. Specify the corresponding environment variables that are defined in Web+ for database-related settings in the .env file.
    DB_CONNECTION=mysql
    DB_HOST=${WP_RDS_CONNECTION_ADDRESS}
    DB_PORT=${WP_RDS_PORT}
    DB_DATABASE=${WP_RDS_DATABASE}
    DB_USERNAME=${WP_RDS_ACCOUNT_NAME}
    DB_PASSWORD=${WP_RDS_ACCOUNT_PASSWORD}
  3. Use the following command to install the required dependencies.
    composer install
  4. Use the zip command to archive all files in the project and create a deployment package named webplusdemo.zip.
    zip -r webplusdemo.zip . /

Step 3: Deploy the application in Web+

  1. Log on to the Web+ console.
  2. On the Overview page, click Create in the upper-right corner of the Last Updated Deployment Environments section.
  3. In the Basic Information step, select PHP in the Technology Stack Type setting, and enter an application name and application description. After the configuration is complete, click Next.
  4. In the Deployment Environment Information step, enter a deployment environment name, and select Upload Local Application in the Deployment Package Source setting. Upload the newly compressed deployment package named webplusdemo.zip, configure the deployment package version, and click Next.
  5. In the Configurations step, select Custom in the Predefined Configuration setting.
  6. View the ApsaraDB for RDS field and select MySQL in the Database Type setting. Then, configure the other required settings, such as the database version, database edition, and instance type.
  7. View the Lifecycle Hooks field and enter the following command in the PostPrepareApp setting.
    cd $APP_HOME && /usr/local/php/bin/php artisan migrate 
  8. Click Creation Complete at the bottom of the page.
  9. In the Creation Complete step, click View Application or Creation Complete and go to the Overview tab of the Application Details page. Click the name of a deployment environment to go to the Overview tab of the Deployment Environment Details page. Then, click the link next to the Public IP Address label to view the homepage of the application.

More information