Knowledge Base

How to install Laravel manually

This article describes how to install the Laravel PHP framework manually.

Although A2 Hosting servers are compatible with a wide variety of software applications, we cannot provide troubleshooting assistance for application-specific issues.

The steps and procedures to use in this article depend on whether or not your hosting account uses CageFS. To determine if CageFS is enabled for your account, please see this article.

Installing Laravel on an account that has CageFS enabled

To install Laravel on an account that has CageFS enabled, follow these steps:

  1. Log in to cPanel.
  2. In the Software and Services section of the cPanel home screen, click Select PHP Version.
  3. Confirm that the PHP version is set to 5.5 or later.
  4. In the list of PHP extensions, confirm that the json and phar check boxes are selected, and then click Save.
  5. Log in to your account using SSH.
  6. Laravel uses composer, a PHP dependency manager. To enable running composer by simply typing composer at the command prompt, type the following commands. Replace username with your account username:
    echo 'alias composer="php -d allow_url_fopen=On /home/username/composer.phar"' >> ~/.bashrc
    source ~/.bashrc
  7. To download the composer installer, type the following commands:

    cd ~
    curl -k -O https://getcomposer.org/installer
    
  8. To install composer, type the following command:

    php -d allow_url_fopen=On installer

    To confirm composer installed correctly, type the following command:

    composer -V

    Composer should display the version number. If it does not, repeat steps 6 to 8, paying close attention to the paths.

  9. To install Laravel, type the following command. Replace project with the project name that you want to use:

    composer create-project laravel/laravel project

    This command installs the Laravel project in the /home/username/project directory, where username represents your username, and project represents the project name.

  10. To enable running artisan by simply typing artisan at the command prompt, type the following commands. Replace username with your account username, and project with your project name:

    echo 'alias artisan="php /home/username/project/artisan"' >> ~/.bashrc
    source ~/.bashrc
    
    Artisan is the command-line interface to Laravel. When you create a Laravel project, Artisan is installed in the project directory. For more information about Artisan, please visit http://laravel.com/docs/artisan.
  11. To make the Laravel project files accessible to web visitors, you must create a symbolic link in the public_html directory that points to the /home/username/project/public directory. To do this, type the following command, replacing username with your username, project with the project name, and path with the URL path that you want visitors to use to access the project:

    ln -s /home/username/project/public /home/username/public_html/path
    
  12. In your web browser, go to http://www.example.com/path, where example.com represents your domain name, and path represents the path you specified in step 11. You should see the Laravel 5 page.

Installing Laravel on an account that does not have CageFS enabled

To install Laravel on an account that does not have CageFS enabled, follow these steps:

  1. Log in to cPanel, and then change the PHP version to 5.5.13.
    • For step-by-step instructions about how to change the PHP version in cPanel, please see this article.
    • If you have a managed VPS or managed Flex Dedicated server, and PHP 5.5 is not installed, please open a support ticket on the Customer Portal at https://my.a2hosting.com and we will install it for you.
  2. Log in to your account using SSH.
  3. Laravel uses composer, a PHP dependency manager. To configure composer and your shell environment to use PHP 5.5, type the following commands. Replace username with your account username:

    echo 'alias php="/opt/php/php-5.5.13/bin/php"' >> ~/.bashrc
    echo 'alias composer="/opt/php/php-5.5.13/bin/php -d allow_url_fopen=On /home/username/composer.phar"' >> ~/.bashrc
    source ~/.bashrc
  4. To download the composer installer, type the following commands:

    cd ~
    curl -k -O https://getcomposer.org/installer
    
  5. To install composer, type the following command:

    php -d allow_url_fopen=On installer

    To confirm composer installed correctly, type the following command:

    composer -V

    Composer should display the version number. If it does not, repeat steps 3 to 5, paying close attention to the paths.

  6. To install Laravel, type the following command. Replace project with the project name that you want to use:

    composer create-project laravel/laravel project

    This command installs the Laravel project in the /home/username/project directory, where username represents your username, and project represents the project name.

    At the end of the installation process, you may receive the following error message:

    Parse error: syntax error, unexpected '['

    To resolve this problem, follow these steps:

    1. Open the /home/username/project/composer.json file in your preferred text editor.
    2. Modify the scripts section in the composer.json file to use the PHP 5.5 binary as follows:
          "scripts": {
              "post-root-package-install": [
                  "/opt/php/php-5.5.13/bin/php -r \"copy('.env.example', '.env');\""
              ],
              "post-create-project-cmd": [
                  "/opt/php/php-5.5.13/bin/php artisan key:generate"
              ],
              "post-install-cmd": [
                  "/opt/php/php-5.5.13/bin/php artisan clear-compiled",
                  "/opt/php/php-5.5.13/bin/php artisan optimize"
              ],
              "pre-update-cmd": [
                  "/opt/php/php-5.5.13/bin/php artisan clear-compiled"
              ],
              "post-update-cmd": [
                  "/opt/php/php-5.5.13/bin/php artisan optimize"
              ]
          },
      
    3. Save your changes to the composer.json file.
    4. Type the following commands:

      cd ~/project
      rm composer.lock
      rm -rf vendor
      composer install
      

      The installation should now complete with no errors.

  7. To configure artisan to use PHP 5.5, type the following commands. Replace username with your account username, and project with your project name:

    echo 'alias artisan="/opt/php/php-5.5.13/bin/php /home/username/project/artisan"' >> ~/.bashrc
    source ~/.bashrc
    
    Artisan is the command-line interface to Laravel. When you create a Laravel project, Artisan is installed in the project directory. For more information about Artisan, please visit http://laravel.com/docs/artisan.
  8. To make the Laravel project files accessible to web visitors, you must create a symbolic link in the public_html directory that points to the /home/username/project/public directory. To do this, type the following command, replacing username with your username, project with the project name, and path with the URL path that you want visitors to use to access the project:

    ln -s /home/username/project/public /home/username/public_html/path
    
  9. In your web browser, go to http://www.example.com/path, where example.com represents your domain name, and path represents the path you specified in step 8. You should see the Laravel 5 page.

More Information

For more information about Laravel, please visit http://laravel.com.