Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»PHP Framework»How to Setup Laravel Application on Ubuntu & Debian

    How to Setup Laravel Application on Ubuntu & Debian

    By RahulDecember 20, 20224 Mins Read

    Laravel is a powerful and popular open-source PHP framework for creating web applications. It is the preferred choice for many developers due to its intuitive syntax, scalability, and reliability. Setting up Laravel on Ubuntu & Debian is relatively easy, and this article will walk you through the steps.

    Advertisement

    Prerequisites

    Before we dive into setting up Laravel, let’s take a look at the prerequisites for doing so. Firstly, you will need a server running Ubuntu or Debian. You will also need to have the latest version of PHP installed on the server. Finally, you will need to install the Composer package manager, as it is required for Laravel.

    Once you have all the prerequisites in place, you can move on to the next step.

    Step 1 – Install LAMP

    The latest version of Laravel required PHP 8.0 or a newer version. To start with Laravel, we first need to set up a running LAMP server. If you have already run the LAMP stack skip this step else use the following commands to set up the lamp on the Ubuntu system.

    Install PHP

    sudo apt install python-software-properties
    sudo add-apt-repository ppa:ondrej/php
    sudo apt update
    sudo apt install -y php8.0 php8.0-mcrypt php8.0-gd php8.0-mbstring php8.0-xml
    

    Install Apache2

    sudo apt-get install apache2 libapache2-mod-php8.0
    

    Install MySQL

    sudo apt-get install mysql-server php8.0-mysql
    

    Step 2 – Install PHP Composer

    The composer is required for installing Laravel dependencies. So use the below commands to download and use as a command in our system.

    curl -sS https://getcomposer.org/installer | php
    sudo mv composer.phar /usr/local/bin/composer
    sudo chmod +x /usr/local/bin/composer
    

    Step 3 – Create Laravel Application

    Now that you have PHP and Composer installed on the server, you can move on to installing Laravel. To do this, you will need to open the terminal and run the following command:

    cd /var/www
    composer create-project --prefer-dist laravel/laravel my-laravel-app
    

    This will create a new Laravel project in the directory specified by `my-laravel-app`. After that, you will need to open the project directory and run the following command to install all the dependencies:

    cd /var/www/my-laravel-app
    sudo composer install
    

    Once the dependencies are installed, you can move on to the next step.

    The dependencies installation may take some time as per your network speed. After successfully installing all dependencies, set the proper permissions on all files.

    chown -R www-data.www-data /var/www/my-laravel-app
    chmod -R 755 /var/www/my-laravel-app
    chmod -R 777 /var/www/my-laravel-app/storage
    

    Now generate base64 random number encryption key, which is used by the Illuminate encrypter service.

    php artisan key:generate
    
    Application key set successfully.
    

    Edit the .env configuration file and update the required settings. Also, make sure APP_KEY is properly set as generated in the above command.

    Step 4 – Create Database for Laravel

    You may also require creating a database for your Laravel application. Login to your MySQL server and create MySQL database and user.

    1
    2
    3
    4
    mysql> CREATE DATABASE laravel;
    mysql> GRANT ALL ON laravel.* to 'laravel'@'localhost' IDENTIFIED BY 'secret';
    mysql> FLUSH PRIVILEGES;
    mysql> quit

    Now edit the .env file and update database settings.

    DB_CONNECTION=mysql
    DB_HOST=127.0.0.1
    DB_PORT=3306
    DB_DATABASE=laravel
    DB_USERNAME=laravel
    DB_PASSWORD=secret
    

    Step 5 – Apache Configuration

    Edit Apache default virtual host configuration file 000-default.conf and update DocumentRoot to Laravel public directory as below:

    vim /etc/apache2/sites-enabled/000-default.conf
    

    also add some more configuration.

    <VirtualHost *:80>
    
            ServerAdmin [email protected]
            DocumentRoot /var/www/my-laravel-app/public
    
            <Directory />
                    Options FollowSymLinks
                    AllowOverride None
            </Directory>
            <Directory /var/www/my-laravel-app>
                    AllowOverride All
            </Directory>
    
            ErrorLog ${APACHE_LOG_DIR}/error.log
            CustomLog ${APACHE_LOG_DIR}/access.log combined
    
    </VirtualHost>
    

    Reload Apache configuration changes by restarting the service using the below command

    sudo service apache2 restart
    

    Step 6 – Access Laravel Application

    You have successfully configured the Laravel 7 PHP framework on your system. Access the Laravel application in your favorite web browser

    How to Setup Laravel on Ubuntu and Debian

    Let’s start building an awesome application using Laravel PHP Framework. Thanks.

    Conclusion

    Now that you have set up Laravel on Ubuntu & Debian, you can start developing your web application. Setting up Laravel is fairly straightforward, and this article should have given you a good idea of how to do it. It is important to note that you should always keep your server and software up to date in order to ensure optimal performance and security. If you have any questions or need help setting up Laravel, we are here to help.

    Framework Laravel Laravel 5 PHP
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    How to Prevent SQL-injection in PHP using Prepared Statements

    Preventing SQL injection attacks with prepared statements in MySQL

    PHP Arrays: A Beginner’s Guide

    View 88 Comments

    88 Comments

    1. ak on August 12, 2019 4:19 pm

      where to put the part? you did not mention that!

      Reply
      • ak on August 12, 2019 4:20 pm

        the virtualhost part

        Reply
        • deyvi on October 3, 2019 10:01 pm

          https://tecadmin.net/install-multiple-php-version-apache-ubuntu/

          Reply
    2. Sulaiman on April 18, 2019 12:18 pm

      Not working for me… when i went to localhost in browser, its only show Apache2 Ubuntu Default Page

      Reply
    3. Hasan on March 15, 2018 3:37 pm

      This great doc about laravel installation, thank you so much 🙂 Here is go bookmark 🙂

      Reply
    4. pedicure chairs on March 13, 2018 4:09 pm

      hello, i work to step 4. I don’t generate key?
      my error :
      1. ails
      Composer could not find a composer.json file in /root
      To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ “Getting Started” section

      Reply
      • Rahul K. on March 14, 2018 4:27 am

        Does the steps 3 completed successfully?

        Reply
    5. Waleed on January 9, 2018 9:24 pm

      Awesome man. Very helpful.
      Simple and Clear – Just add that this doesn’t work with Ubuntu distro
      Also, why not use .local or something for local domains rather than .com, which can sometimes confuse users because .com will route them to actual site on the internet, say if there is another server being used on the local network.
      Thank You.

      Reply
    6. oyun ve teknoloji on December 28, 2017 12:05 am

      Working like a charm, thank you

      Reply
    7. Loic Le Joncour on December 23, 2017 6:26 am

      Hello,

      I used your tutorial on LinuxMint 18.2 Sonya.

      In laravel directory, vendor subdirectory is missing. So, at Step 4, the second command line does not run.

      How can I solve this problem ?

      Thank you
      Loic

      Reply
      • Catia on December 27, 2017 12:11 pm

        I have the same problem!

        Reply
        • Rahul K. on December 28, 2017 4:49 am

          Does step 3 command completed successfully?

          sudo composer install

          Reply
          • Catia on February 3, 2018 8:18 pm

            I have tried again today and worked! Sorry I did not answer earlier!

            Reply
    8. Marc on December 17, 2017 8:58 pm

      Many thanks for this great tutorial. After doing all the steps and trying to access the installation from the browser I get an empty folder with “Index of /” as a title. Any idea what could’ve gone wrong? Thanks in advance.

      Reply
    9. Marc on December 17, 2017 8:31 pm

      Many thanks for this great tutorial. I have set up everything as specified, but I see an empty folder when I browse to the domain name. Any idea how to solve this? Thanks in advance!

      Reply
    10. Ahmed Mowafy on November 15, 2017 1:08 pm

      Very Good .
      Very Good .
      Very Good .
      Very Good .
      Very Good .

      Reply
    11. stranger on November 15, 2017 1:00 pm

      All settings correct for using Composer Unable to write keys.dev.pub to: /home/ubuntu/.composer

      Step 1: just go to your Project Directory and run a Command sudo su

      Step 2: then Try to install the Composer using The Following Command

      Reply
    12. arman ahmad on October 12, 2017 11:56 pm

      /etc/apache2/sites-available/laravel.example.com.conf “directory does not exist”

      Reply
    13. Kalyar on August 10, 2017 2:07 pm

      my laravel project is returning apache2 default page instead login/index.php page .
      php 5.9, mysql 5.6 and LAMP server using with Ubuntu 14.04.
      It is ok on ubuntu 15.04.
      How do I trace? Would you help me please?

      Reply
      • Rahul K. on August 11, 2017 4:23 am

        You must have some issue in step 5. first, check if the virtual host is properly created and enabled. Are you accessing the site with ip or domain name?

        Reply
        • Marc on December 17, 2017 9:29 pm

          I had the same issue and found out it’s pointing to the var/www/html folder instead of var/www/laravel as specified in the configuration file. Any idea how to solve this? I also tried to put the domain name instead of the * but this results in a 500 error.

          Reply
    14. sheetal on July 21, 2017 9:17 am

      Fatal error: Class ‘Illuminate\Foundation\Application’ not found in /opt/lampp/htdocs/laravel/bootstrap/app.php on line 14

      I am getting such type of error

      Reply
    15. dinesh on March 28, 2017 1:29 pm

      I am getting blank page while using http://laravel.example.com

      Reply
      • copernic on May 8, 2017 3:48 pm

        execute this
        chown -R www-data.www-data .env

        Reply
    16. Omar Menchaca on November 25, 2016 8:53 pm

      Greate tutorial ..in order to avoid HTTP 500 when going to /public after installation make sure PHP 5.6 is running on server
      sudo a2dismod php5
      sudo a2enmod php5.6
      sudo service apache2 restart

      Reply
    17. Azaz Qadir on August 4, 2016 7:07 am

      I would suggest you to check out Cloudways platform (https://www.cloudways.com/en/laravel-hosting.php ). Using their platform, you can install laravel in just one click. There is no need to manually install and configure Linux or stack.

      Reply
    18. Sam on July 25, 2016 3:49 pm

      Thanks for the tutorial.
      I can’t seem to get pass the last section of part 3. I can’t set the permission on the files.
      Any suggestions?

      Thanks.
      ubuntu 14.04

      Reply
      • Zachariah Robichaud on July 26, 2016 3:04 pm

        You probably need to use sudo in front of the commands.

        I had to put the example here at this URL because I couldn’t add it here for some reason.
        http://laravel.io/bin/32lVD

        Reply
    19. Helias Fylactos on May 27, 2016 8:16 am

      the sudo add-apt-repository ppa:ondrej/php5 is deprecated. Step “install php5” shoul d be updated with the commands :

      sudo LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
      sudo apt-get update
      sudo apt-get install php5.6

      as suggested in the installer it self .

      Reply
    20. Stefan on May 13, 2016 9:04 am

      Hey, I’ve been following the tutorial on a debian machine.
      But when trying to reload apache2 I get ‘Job for apache2.service failed. See ‘systemctl status apache2.service’ and ‘journalctl -xn’ for details.’
      The are no other logs.

      Any suggestions?

      Reply
    21. gaurav on May 12, 2016 10:23 am

      I am follow step by step i am getting this error .
      `/opt/lampp/htdocs/laravel/app/storage’ : No such file or directory

      Reply
      • ARUN on December 15, 2016 1:06 pm

        try after remove app
        /laravel/storage

        Reply
    22. Jhon on April 23, 2016 6:09 pm

      LAMP = Linux Apache Mysql PHPMyAdmin , where is phpmyadmin ???

      Reply
      • Raghav Sikaria on August 1, 2016 8:33 am

        Hi John , you are almost correct . Actually P in the LAMP stands for PHP,Python,Perl ,etc. PHPMyAdmin is basically a web browser based GUI built on PHP for ease of access to database . It is not a part of LAMP stack , you’ll have to install it seperately .

        Reply
    23. yan on April 12, 2016 5:04 am

      work well for me too thanks

      Reply
    24. Alexandre on April 7, 2016 11:32 am

      Great tutorial. First time using Laravel and all steps worked smooth. Thanks!

      Reply
    25. Habeeb on April 4, 2016 9:24 am

      Hi,

      I am facing a problem in step – 4. Whenever i am trying to run the command php artisan key:generate, i am getting an error ,

      [ErrorException]
      file_get_contents(/opt/lampp/htdocs/mylaravel/laravel/.env): failed to open
      stream: No such file or directory

      Please help me.

      Thank You

      Reply
      • Vel on April 5, 2016 7:24 am

        Hi Habeeb,

        You can recheck hidden file view is enabled or not else try CTRL + H to view hidden file .env.example then rename the file to .env , now try to run the command “php artisan key:generate” to view application key.

        Reply
        • Sérgio Mafra on April 19, 2016 4:20 am

          I did what you tell, but I don’t have permission to rename it nor I can find it using terminal. Can you please be more specific?
          Thank you!

          Reply
    26. James Scott on March 31, 2016 10:35 am

      Hi Rahul, I have deployed my laravel apps on digitalocean from cloudways platform because I only had to do few clicks they took care of the rest. You did a good tutorial here and its good for beginners. I am sharing it in my network.

      Reply
    27. Mandy on March 24, 2016 11:30 am

      If you face issues, with routes giving a 404 when you access them, please make sure you enable mod_rewrite by doing: a2enmod rewrite

      Reply
    28. arams on March 21, 2016 4:03 pm

      Thank you
      A really great narrative and contains useful information.

      Reply
    29. Suba on March 16, 2016 7:06 pm

      I have set up everything as above stated, but when i type “laravel.example.com”, it navigates me to the localhost page. I have already spent so many days to fix the problem. Please, help me as soon as possible.

      1. I think my virtual host is not working.

      2 . I am using Ubuntu 15.10 .

      Let me know, if you need anything more to resolve my problem.

      Amazing Thanks in Advance!!! PLEASE, HELP ME!!

      Reply
    30. Chester on March 14, 2016 4:30 pm

      by step 5 when I input: $ vim /etc/apache2/sites-available/laravel.example.com.conf, I recieve ´the program ´vim’ can be found in the following packages… vim, vim-gnome, vim-tiny, vim-athena, vim-gtk and vim-nox.
      So entered apt-get install´ in front. However when I do this it outputs ¨Unable to locate package /etc/apache2/sites-available”. what should I do, should I install one of the the packages?

      Reply
      • Alex on June 2, 2017 8:40 pm

        You simply do not have the vim text editor installed. You have two options:

        1. Install vim, # apt-get install vim, then run the command in the tutorial

        2. Use another editor, # nano /etc/apache2/sites-available/laravel.example.com.conf

        Reply
    31. mustafa alp on March 4, 2016 12:32 am

      it helped thanks

      Reply
    32. Cadarrius on March 2, 2016 1:15 am

      The very last step is not clear. How do I know my server ID and domain name?

      Reply
    33. MikeDX on February 22, 2016 3:47 pm

      10/10 for the tutorial

      0/10 for including the $ prompt in each block of commands to use, making it really annoying to copy / paste to actualy use the instructions

      Reply
      • Kers on February 25, 2016 3:30 pm

        It’s always better to write the commands manually. You’ll learn faster from it. Besides the structure of these command are fairly easy. 😉

        I agree to the 10/10 tutorial rating tho.

        Reply
    34. Rahul on February 12, 2016 11:03 am

      Thanks

      Reply
    35. haikent on February 11, 2016 10:17 pm

      >>sudo composer install

      getting this error

      Loading composer repositories with package information
      The “https://packagist.org/packages.json” file could not be downloaded: Failed to enable crypto
      failed to open stream: operation failed
      https://packagist.org could not be fully loaded, package information was loaded from the local cache and may be out of date
      Installing dependencies (including require-dev)

      [ComposerDownloaderTransportException]
      The “http://packagist.org/p/symfony/console%248630ea4e7d5fdd743a5cd91696380
      ff9f48ff6c659262d76efd6495d96b80539.json” file could not be downloaded (HTT
      P/1.1 302 Found)

      install [–prefer-source] [–prefer-dist] [–dry-run] [–dev] [–no-dev] [–no-plugins] [–no-custom-installers] [–no-autoloader] [–no-scripts] [–no-progress] [-v|vv|vvv|–verbose] [-o|–optimize-autoloader] [-a|–classmap-authoritative] [–ignore-platform-reqs] [–] []…

      Reply
    36. Jagroop Singh on February 11, 2016 11:24 am

      thanks 🙂

      Reply
    37. Daisy on January 28, 2016 6:13 am

      I am getting issue setting up permissions:

      It has app directory inside web/laravel but not stoarge.

      Reply
      • Rahul on January 28, 2016 6:22 am

        Hi Daisy,

        It looks code is not properly downloaded. storage directory is available at https://github.com/laravel/laravel

        Reply
        • SAM on January 28, 2016 3:55 pm

          Hi,
          I encountered the same mistake as Daisy and I corrected by downloading from the source you gave. There is still no storage directory.

          Reply
          • JRoS on February 22, 2016 11:43 pm

            Looks like storage folder is not under app but under root folder. Is it supposed to be also under app?

            Reply
    38. Anto on January 12, 2016 11:26 pm

      Hello I have managed to install it as you put it. Now, I would like to know how could I use this in multiple projects, I mean, how to install laravel in other directories? I tried to adapt the steps but I get a 403 Forbidden. Can anybody help? Thanks

      Reply
    39. Mohamed Belhassen on January 12, 2016 3:18 pm

      It is a perfect article but it lacks the final step : adding an entry to the hosts file:

      127.0.0.1 laravel.example.com

      Please add it to the article for completeness.

      Reply
      • Shannanigans on January 23, 2016 11:41 am

        Agreed, add that missing step and it is the most useful laravel lamp setup article I have come across.

        Reply
        • Rahul on January 25, 2016 11:11 am

          Thanks Mohamed and Shannanigans,

          We have updated this tutorial accordingly.

          Reply
    40. Hitesh Parikh on January 8, 2016 10:28 am

      Great Tutorial. Thanks.
      It saves my day.

      Reply
    41. pue on December 29, 2015 9:29 pm

      Hi
      i see this when i try to lauch app ..

      Whoops, looks like something went wrong.

      1/1
      FatalErrorException in Route.php line 238:
      Class ‘SymfonyComponentRoutingRoute’ not found

      Reply
    42. Ajay on December 23, 2015 11:02 am

      Hi,

      Thanks for the step by step instructions on how to setup Laravel. I was able to do this with in no time.

      But when we create a new route and view, the system gives 404 error. for example shambhavicreations.in/test/

      We have been trying this for long but we are getting stuck.

      Best,

      Ajay

      Reply
      • washeul on April 21, 2016 10:55 am

        i got the same problem have you found any solution

        Reply
        • Zach Robichaud on May 10, 2016 6:56 pm

          Sorry if you already got this.

          In your app/Http/routes.php file add something like

          Route::get(‘test’, function(){
          print “this is working”;
          });

          Reply
    43. warlock on October 23, 2015 6:29 pm

      hey you forgot to mention..

      – Add an APP_KEY by running php artisan key:generate from the command line in your project root. This will generate a random, 32 character string which is used for encryption.

      – You should already have ‘cipher’ => ‘AES-256-CBC’, within your config/app.php file if it is a new project. That is where I think you are confused.

      You’re good to go 😀

      Reply
    44. sunghun on September 2, 2015 8:12 am

      I have problem during follow the description
      when I type
      [email protected]:.var/www$ git clone https://github.com/laravel/laravel.git

      fatal: could not create work tree dir ‘larval’.:permission denied

      how to should do?

      Reply
      • sunghun on September 2, 2015 8:15 am

        I solved it 😐

        Reply
    45. somu on August 4, 2015 8:44 am

      Everthing i installed step by step process,finally i got server not found in browser please any one knw let me

      Reply
      • Yogesh on January 11, 2016 10:44 am

        same here… have you solved it

        Reply
    46. Weezer on May 26, 2015 11:13 pm

      It should say this is for local machine, not a web server.

      Reply
    47. Dnil on May 19, 2015 3:35 pm

      I done the whole tutorial. But when I’m trying to access the http://laravel.example.com, the browser says, “Server Not Found” what do you think the reason? I’m using the Ubuntu 15.04 the latest version. Please help!

      Reply
      • Ahmed on August 5, 2015 5:45 am

        I have same problem… can you help me it solved with you?

        Reply
        • Sérgio on August 26, 2015 6:10 pm

          Hi,
          in your file /etc/hosts insert this line:
          127.0.0.1 lavarel.example.com

          Save and restart Apache.

          Reply
          • Dakotah on September 1, 2015 11:47 pm

            Can you give us a working example file plz.

            Reply
          • abdul Suadik on December 13, 2015 2:00 pm

            Please check the spelling for laravel in 127.0.0.1 lavarel.example.com

            Reply
          • Antonio on December 13, 2015 4:04 pm

            127.0.0.1 laravel.example.com

            you replaced v and r, it confused me for couple of minutes so I thought it s a good thing to point out for others…

            Besides that: yeah, this should’ve been part of tutorial

            Reply
          • Emanuel Acuña on December 31, 2015 9:07 pm

            Thanks, with this the problem was solved.
            Happy new year.

            Reply
      • Pavithra on December 14, 2015 7:11 am

        Hi, SÉRGIO

        How did solve the problem? Can you please the solution with me… Even I am facing the same problem of “Web-page not available” after following the all the above mentioned steps…

        Reply
    48. Marcos on May 5, 2015 10:46 pm

      And I can’t install phpmyadmin

      Reply
    49. Marcos on May 5, 2015 10:45 pm

      Hello.

      Version 5.6 in Ubuntu 15.04 does not work well.
      Php5-mcrypt package is not available (dependencies)
      And the setting is not good with mysqli.

      Could you help me to fix it?

      Reply
    50. Jain on April 30, 2015 10:51 am

      Hi,
      I got below error after i run a2ensite laravel.example.com
      ERROR: Site laravel.example.com does not exist!

      Please help

      Reply
      • Rahul on May 1, 2015 3:47 am

        Hi Jain,

        Please add .conf in Apache virtual host configuration file name. Rename file laravel.example.com to laravel.example.com.conf will work fine. I have updated article accordingly.

        Reply
        • Ninika Sharma on November 15, 2015 9:15 am

          I am still facing the same problem.

          When i run this command a2ensite laravel.example.com, i get this error

          ERROR: Site laravel.example.com does not exist!

          Reply
          • Rahul on November 16, 2015 4:59 am

            Hi Ninika,

            What is your VirtualHost filename created in step #4.

            Reply
        • Sasuke on April 24, 2016 7:24 am

          Inside “/etc/apache2/sites-enabled/” you should have a file named the same as the domain name with “.conf” extension. (based on the article, here it should be laravel.example.com.conf).
          If you don’t see one, make a copy of the etc/apache2/apache2.conf file and rename it. or just create a new one and copy the contents from this article.

          Reply
    51. rohan on April 21, 2015 7:13 pm

      Hey before step 4 tell users to add thee lines of code if their installation gets stuck due to mcrypt not available issue. worked for me.
      sudo apt-get install mcrypt php5-mcrypt
      sudo php5enmod mcrypt
      sudo service apache2 restart

      Reply
      • Rahul on April 22, 2015 5:18 am

        Thanks Rohan,

        We will update the article soon…

        Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Implementing a Linux Server Security Audit: Best Practices and Tools
    • cp Command in Linux (Copy Files Like a Pro)
    • 15 Practical Examples of dd Command in Linux
    • dd Command in Linux (Syntax, Options and Use Cases)
    • Iptables: Common Firewall Rules and Commands
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.