Posted in Frameworks, Laravel

Installing Laravel Framework on Ubuntu 16.04 using AWS EC2

One of the popular PHP framework – Laravel can be installed in Ubuntu using composer.

To setup an EC2 instance with Ubuntu 16.04, read this post. To set up LAMP stack, read this post.

Step 1: Install composer

  1. Get composer using curl
    $ curl -O https://getcomposer.org/composer.phar
  2. Rename composer.phar to composer
    $ mv composer.phar composer
  3. Make composer executable. After running this command you will be able to run it locally as ./composer
    $ chmod +x composer
  4. To make composer available globally, you need to move it to /user/local/bin

    $ sudo mv composer /usr/local/bin
  5. Test the installation by running this command. You will see composer’s command list
    $ composer

Step 2: Install Pre-requisites (only if not installed)

Laravel requires mbstring and dom. This sometimes will be missing with PHP installation. You need to perform this step only if you see any of these errors while performing next step:

laravel/framework v5.3.9 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.

or

phpunit/phpunit 5.7.5 requires ext-dom * -> the requested PHP extension dom is missing from your system.
  1. Install mbstring
    sudo apt-get install php-mbstring
  2. Install php-xml for dom issue
    sudo apt-get install php-xml

Step 3: Install Laravel

You can install Laravel in the html directory of /var/www/html/ using:

 sudo composer create-project laravel/laravel /var/www/html/ --prefer-dist

Or, you can specify the directory to install

 sudo composer create-project laravel/laravel laravel --prefer-dist

It takes few minutes depending on your network connectivity. Once it is complete, you can visit your URL in browser that lists Laravel directory. When traversed to public directory, you could see the Laravel’s welcome page.

If you cannot view its page, your server is preventing due to permission error. Change the permission for directory and files as suggested in this post. Now, you will be able to see the welcome screen.

Step 4: Changing DocumentRoot (optional)

Laravel can be accessed when you are in public directory. So your URL will be:

http://www.example.com/public

To access Laravel in root directory, you need to change the DocumentRoot in apache module. Goto /etc/apache2/sites-available/ and edit the configuration file for your domain using any editor (I use vi):

sudo vi /etc/apache2/sites-available/.conf

Find this line:

DocumentRoot /var/www/html/

And replace with

DocumentRoot /var/www/html/public

Restart Apache server

sudo service apache2 restart

Now, you can access Laravel!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s