One of the popular PHP framework – Laravel can be installed in Ubuntu using composer.
Step 1: Install composer
- Get composer using curl
$ curl -O https://getcomposer.org/composer.phar
- Rename composer.phar to composer
$ mv composer.phar composer
composerexecutable. After running this command you will be able to run it locally as
$ chmod +x composer
- To make composer available globally, you need to move it to /user/local/bin
$ sudo mv composer /usr/local/bin
- Test the installation by running this command. You will see composer’s command list
Step 2: Install Pre-requisites (only if not installed)
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.
phpunit/phpunit 5.7.5 requires ext-dom * -> the requested PHP extension dom is missing from your system.
sudo apt-get install php-mbstring
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:
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):
Find this line:
And replace with
Restart Apache server
sudo service apache2 restart
Now, you can access Laravel!