{"id":3484,"date":"2018-04-30T19:18:10","date_gmt":"2018-04-30T15:18:10","guid":{"rendered":"https:\/\/www.howtoforge.com\/tutorial\/install-laravel-on-ubuntu-for-apache\/"},"modified":"2018-04-30T19:18:10","modified_gmt":"2018-04-30T15:18:10","slug":"installing-laravel-php-framework-on-ubuntu-18-04-lts-for-apache","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/installing-laravel-php-framework-on-ubuntu-18-04-lts-for-apache\/","title":{"rendered":"Installing Laravel PHP Framework on Ubuntu 18.04 LTS for Apache"},"content":{"rendered":"<p>Laravel is a very popular open source PHP framework aimed at easy development of applications. If you are looking for a new PHP framework to try, you should give Laravel a try.<\/p>\n<p>The following guide will\u00a0show you how to install and run Laravel on an Ubuntu 18.04 LTS based Apache server.\u00a0This tutorial works for Ubuntu 17.x as well. But for servers, you should prefer to use an Ubuntu LTS release like the current Ubuntu 18.04 LTS.<\/p>\n<h2 id=\"prerequisites\">Pre-Requisites<\/h2>\n<p>Before proceeding with the installation, it&#8217;s always a good idea to make sure your sources and existing software\u00a0are updated.\u00a0<\/p>\n<p class=\"command\">sudo apt-get update <br \/>sudo apt-get upgrade<\/p>\n<p>For this guide, we will assume that you have a basic server based on Ubuntu running. Before Laravel, we need to install other components that are essential.<\/p>\n<h2 id=\"installing-apache-and-php-\">Installing Apache and PHP 7.2<\/h2>\n<p>Next step is to install PHP along with several extra packages that would prove useful if you are going to work with Laravel.\u00a0<\/p>\n<p class=\"command\">sudo add-apt-repository ppa:ondrej\/php<br \/>sudo apt-get update<br \/>sudo apt-get install\u00a0<span>apache2 libapache2-mod-php7.2\u00a0<\/span>php7.2 php7.2-xml\u00a0php7.2-gd\u00a0php7.2-opcache\u00a0php7.2-mbstring<\/p>\n<p>Even though Ubuntu&#8217;s own repository has PHP, it&#8217;s better to add a 3rd party repository here because it gets more frequently updated. You can skip that step and stick to Ubuntu&#8217;s version if that&#8217;s what you prefer.<\/p>\n<h2 id=\"installing-laravel\">Installing Laravel<\/h2>\n<p>Before we finally delve into it, we also need Git version control to be installed. If you have it installed, you can skip the following step. If you don&#8217;t have, then you can <a href=\"https:\/\/www.howtoforge.com\/tutorial\/install-git-and-github-on-ubuntu-14.04\/\" title=\"Install Git and Github on Ubuntu\" target=\"_blank\" rel=\"noopener\">follow our guide<\/a>\u00a0to set it up first.<\/p>\n<p>To install Laravel, we need to install Composer first. It is a tool for dependency management in PHP that allows you to package all the required libraries associated with a package as one. To install Laravel and all its dependencies, Composer is required. It will download and install everything that is required to run Laravel framework. To install Composer, issue the following commands.<\/p>\n<p class=\"command\">cd \/tmp<br \/>curl -sS https:\/\/getcomposer.org\/installer | php<br \/>sudo mv composer.phar \/usr\/local\/bin\/composer<\/p>\n<p>The curl command downloads composer.phar package to your \/tmp directory. But we would want composer to run globally hence we need to move it to <em>\/usr\/local\/bin\/<\/em> directory under the name &#8216;<em>composer<\/em>&#8216;. Now we can run composer from anywhere.<\/p>\n<p>To install Laravel, move to the public html directory on your system. Since we are on Ubuntu and using Apache, we will install it in the \/var\/www\/html directory.<\/p>\n<p class=\"command\">cd \/var\/www\/html<br \/>sudo composer create-project laravel\/laravel your-project &#8211;prefer-dist<\/p>\n<p>The above command will create a &#8220;<strong>your-project<\/strong>&#8221; directory with Laravel installation in it. Composer uses git to download and install all the packages and modules that Laravel requires for functioning.<\/p>\n<h2 id=\"configuring-apache\">Configuring Apache<\/h2>\n<p>Now that we have installed Laravel, we move on to the step of configuring Apache web server.<\/p>\n<p>Next step is to give proper permissions to the project directory. For this, we need to enable access to it from the www-data group and to give it writing permissions to the storage directory.<\/p>\n<p class=\"command\">sudo\u00a0chgrp -R www-data \/var\/www\/html\/your-project<br \/>sudo chmod -R 775 \/var\/www\/html\/your-project\/storage<\/p>\n<p>Now go to the \/etc\/apache2\/sites-available directory and use the following command to create a configuration file for our Laravel install.<\/p>\n<p class=\"command\">cd \/etc\/apache2\/sites-available<br \/>sudo nano laravel.conf<\/p>\n<p>Now add the following content to the file and close it after saving. Replace yourdomain.tld with the domain name of your website inside the file.<\/p>\n<pre readability=\"9.4812680115274\">&lt;VirtualHost *:80&gt;<br\/>\u00a0\u00a0 \u00a0ServerName yourdomain.tld<p>\u00a0\u00a0 \u00a0ServerAdmin <a href=\"https:\/\/www.howtoforge.com\/cdn-cgi\/l\/email-protection\" class=\"__cf_email__\" data-cfemail=\"4a3d2f28272b393e2f380a2625292b262225393e\" target=\"_blank\" rel=\"noopener\">[email\u00a0protected]<\/a><br\/>\u00a0\u00a0 \u00a0DocumentRoot \/var\/www\/html\/your-project\/public<\/p><p>\u00a0\u00a0\u00a0 &lt;Directory \/var\/www\/html\/your-project&gt;<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 AllowOverride All<br\/>\u00a0\u00a0\u00a0 &lt;\/Directory&gt;<\/p><p>\u00a0\u00a0 \u00a0ErrorLog ${APACHE_LOG_DIR}\/error.log<br\/>\u00a0\u00a0 \u00a0CustomLog ${APACHE_LOG_DIR}\/access.log combined<br\/>&lt;\/VirtualHost&gt;<\/p><\/pre>\n<p>Now we have to enable this newly created .conf file and disable the default .conf file that is installed with the default Apache install. Also, we need to enable mod_rewrite so that permalinks can function properly.<\/p>\n<p class=\"command\">sudo a2dissite 000-default.conf<br \/>sudo a2ensite laravel.conf<br \/>sudo a2enmod rewrite<br \/>sudo service apache2 restart<\/p>\n<p>Your Laravel installation is now complete. Visit the IP address or domain name of your server with a web browser (in my case\u00a0<a href=\"http:\/\/192.168.1.100\">http:\/\/192.168.1.100<\/a>). You will see the Laravel default page.<\/p>\n<p><a class=\"fancybox\" id=\"img-laravel-on-ubuntu\" href=\"https:\/\/www.howtoforge.com\/images\/install-laravel-on-ubuntu-18-04-for-apache\/big\/laravel-on-ubuntu.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/05\/installing-laravel-php-framework-on-ubuntu-18-04-lts-for-apache.png\" alt=\"Laravel installed on Ubuntu 18.04 LTS\" width=\"550\" height=\"350\" title=\"\"><\/a><\/p>\n<p>Laravel Framework successfully installed on Ubuntu 18.04 LTS.<\/p>\n<h2 id=\"virtual-machine-download-of-this-tutorial\">Virtual machine download of this tutorial<\/h2>\n<p>This tutorial is available as ready to use virtual machine image in ovf\/ova format that is compatible with VMWare and Virtualbox. The virtual machine image uses the following login details:<\/p>\n<p><strong>SSH \/ Shell Login<\/strong><\/p>\n<p>Username: administrator<br \/>Password: howtoforge<\/p>\n<p>To become root user, run: sudo -s<br \/><span>Password: howtoforge<\/span><\/p>\n<p>The IP of the VM is 192.168.1.100, it can be changed in the file <strong><em>\/etc\/netplan\/01-netcfg.yaml<\/em><\/strong>. Please change all the above passwords to secure the virtual machine.\u00a0<\/p>\n<div>\n<p><b>Share this page:<\/b><\/p>\n<p>\n<a href=\"https:\/\/www.facebook.com\/sharer.php?u=https%3A%2F%2Fwww.howtoforge.com%2Ftutorial%2Finstall-laravel-on-ubuntu-for-apache%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/05\/installing-laravel-php-framework-on-ubuntu-18-04-lts-for-apache-1.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Fwww.howtoforge.com%2Ftutorial%2Finstall-laravel-on-ubuntu-for-apache%2F&amp;text=Installing+Laravel+PHP+Framework+on+Ubuntu+18.04+LTS+for+Apache&amp;via=howtoforgecom&amp;related=howtoforgecom\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/05\/installing-laravel-php-framework-on-ubuntu-18-04-lts-for-apache-2.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/twitter.com\/howtoforgecom\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/05\/installing-laravel-php-framework-on-ubuntu-18-04-lts-for-apache-3.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/plus.google.com\/share?url=https%3A%2F%2Fwww.howtoforge.com%2Ftutorial%2Finstall-laravel-on-ubuntu-for-apache%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/05\/installing-laravel-php-framework-on-ubuntu-18-04-lts-for-apache-4.png\" height=\"20\" alt=\"\" title=\"\"><\/a>\n<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Laravel is a very popular open source PHP framework aimed at easy development of applications. If you are looking for a new PHP framework to try, you should give Laravel a try. The following guide will\u00a0show you how to install and run Laravel on an Ubuntu 18.04 LTS based Apache server.\u00a0This tutorial works for Ubuntu &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-3484","post","type-post","status-publish","format-standard","hentry","category-36"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/3484","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=3484"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/3484\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=3484"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=3484"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=3484"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}