ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Installing Laravel on Ubuntu 20.04

    IT Discussion
    linux php php 7.4 ubuntu laravel ubuntu 20.04
    3
    28
    2.3k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • scottalanmillerS
      scottalanmiller
      last edited by scottalanmiller

      Laravel is a powerful, and popular development framework built on PHP and commonly deployed to Ubuntu. However, explicit directions taking into account the exact needs of an Ubuntu deployment are surprisingly sparse, and those that work often install Laravel as the root user, instead of by user as it is intended to be installed. So we are going to provide a full install here to make this easy for you. And to make things clear, we will install using sudo commands, so every command is run, as listed, by the end user and not as root. So no confusion.

      sudo apt install php php-bcmath php-cype php-ctype php-json php-mbstring php-pdo php-tokenizer php-xml php-zip composer
      

      Now edit /etc/php/7.4/apache2/php.ini, you will need sudo to do this. Like this:

      sudo vi /etc/php/7.4/apache2/php.ini
      

      And we need to uncomment two lines:

      ...
      extension=fileinfo
      ...
      extension=openssl
      ...
      

      Now as the user, we use composer to install Laravel.

      composer global require laravel/installer
      echo 'export PATH="$PATH:$HOME/.config/composer/vendor/bin"' >> ~/.bashrc
      source ~/.bashrc
      

      That's it Laravel should be up and running. You can test by creating a project with it.

      laravel new MyFirstLaravelApp
      
      1 Reply Last reply Reply Quote 3
      • 1
        1337
        last edited by

        I don't understand why you have to uncomment lines in the php.ini for fileinfo & openssl extensions but not the others?

        I was under the impression that if you installed any php-* package, for instance php-openssl, then you'd have it loaded and activated, ready-to-go.

        scottalanmillerS 1 Reply Last reply Reply Quote 0
        • 1
          1337
          last edited by 1337

          Another question about composer.

          It's a package manager right? Why do they use that instead of the package manager for the OS?

          And when you do composer global require laravel/installer I assume it downloads laraval and the installer? Why did you manually have to load all the php-packages if those are required for the laravel package?

          I can't understand why they made it so you need to use two package managers and why they don't appear to be integrated at all.

          The entire idea of a package manager is that you can easily install what you want and all dependencies are taken care of.
          Like, apt install laravel and you're done.

          scottalanmillerS 3 Replies Last reply Reply Quote 0
          • scottalanmillerS
            scottalanmiller @1337
            last edited by

            @Pete-S said in Installing Laravel on Ubuntu 20.04:

            I don't understand why you have to uncomment lines in the php.ini for fileinfo & openssl extensions but not the others?

            Because they are part of php-common, so automatically installed, but all the pieces of common are commented out so you have to turn them on. Those two are required, so you have to enable them since you cant install them on their own.

            php-openssl doesn't exist anymore, hence the issue.

            1 1 Reply Last reply Reply Quote 0
            • scottalanmillerS
              scottalanmiller @1337
              last edited by

              @Pete-S said in Installing Laravel on Ubuntu 20.04:

              The entire idea of a package manager is that you can easily install what you want and all dependencies are taken care of.
              Like, apt install laravel and you're done.

              Sort of, but there are definite differences. For example, installing composer is a system-wide installation; an OS level installation.

              Composer is for user-level installs into your own home directory. And it is packages from "inside an application". This is the same anywhere. If you add something inside of an app, it's traditional for the app itself to handle it.

              In many cases you can use either. But to standardize development across operating systems essentially all programming languages have their own development managers. NodeJS, PHP, Java, Go, Python, Ruby.... it's for lots of reasons. But primarily because one is run by the user, one by the admin.

              1 1 Reply Last reply Reply Quote 0
              • scottalanmillerS
                scottalanmiller @1337
                last edited by

                @Pete-S said in Installing Laravel on Ubuntu 20.04:

                And when you do composer global require laravel/installer I assume it downloads laraval and the installer? Why did you manually have to load all the php-packages if those are required for the laravel package?

                So in this case you need the system admin to install the PHP packages. They are system level packages. But the end user is downloading scripts to run themselves with Laravel.

                1 Reply Last reply Reply Quote 0
                • 1
                  1337 @scottalanmiller
                  last edited by

                  @scottalanmiller said in Installing Laravel on Ubuntu 20.04:

                  @Pete-S said in Installing Laravel on Ubuntu 20.04:

                  I don't understand why you have to uncomment lines in the php.ini for fileinfo & openssl extensions but not the others?

                  Because they are part of php-common, so automatically installed, but all the pieces of common are commented out so you have to turn them on. Those two are required, so you have to enable them since you cant install them on their own.

                  php-openssl doesn't exist anymore, hence the issue.

                  I don't quite understand. You have php-openssl as one of the packages you install on the first line. If it's already installed by default from the php metapackage, you could omit that right?

                  scottalanmillerS 1 Reply Last reply Reply Quote 0
                  • scottalanmillerS
                    scottalanmiller @1337
                    last edited by

                    @Pete-S said in Installing Laravel on Ubuntu 20.04:

                    I can't understand why they made it so you need to use two package managers and why they don't appear to be integrated at all.

                    While certainly possible, you can imagine the problems that would arise when you want to install different PHP packages or conflicting versions for each user. You want developers to be isolated from one another. Can you do that with system admin level installs? Yes, but it would be complex. Can you do that with end users doing their own installs?

                    That's really the biggest thing, devs need control of their frameworks differently from software packages. I think that looking at Laravel as a package is the wrong way to think of it. Think of it like downloading some code to build off of, that there is some automation to make it easier to work with makes it misleading.

                    If you were a dev, and wanted to work with some code components you found online, you'd just download the code and edit it to get started. You'd not think of having the admin install something.

                    Think of it like Git in that regard. Composer is closer to Git than to DNF/APT. And in fact, in many cases, it's Git that you'd use instead.

                    1 Reply Last reply Reply Quote 0
                    • scottalanmillerS
                      scottalanmiller @1337
                      last edited by

                      @Pete-S said in Installing Laravel on Ubuntu 20.04:

                      @scottalanmiller said in Installing Laravel on Ubuntu 20.04:

                      @Pete-S said in Installing Laravel on Ubuntu 20.04:

                      I don't understand why you have to uncomment lines in the php.ini for fileinfo & openssl extensions but not the others?

                      Because they are part of php-common, so automatically installed, but all the pieces of common are commented out so you have to turn them on. Those two are required, so you have to enable them since you cant install them on their own.

                      php-openssl doesn't exist anymore, hence the issue.

                      I don't quite understand. You have php-openssl as one of the packages you install on the first line. If it's already installed by default from the php metapackage, you could omit that right?

                      Ah, that was a mistake. I ran that command by mistake and it wasn't needed, but was in my command history and I copied it. It was needed on older Ubuntu, but 20.04 moved it into php-common and changed how it works.

                      1 1 Reply Last reply Reply Quote 0
                      • 1
                        1337 @scottalanmiller
                        last edited by 1337

                        @scottalanmiller said in Installing Laravel on Ubuntu 20.04:

                        @Pete-S said in Installing Laravel on Ubuntu 20.04:

                        The entire idea of a package manager is that you can easily install what you want and all dependencies are taken care of.
                        Like, apt install laravel and you're done.

                        Sort of, but there are definite differences. For example, installing composer is a system-wide installation; an OS level installation.

                        Composer is for user-level installs into your own home directory. And it is packages from "inside an application". This is the same anywhere. If you add something inside of an app, it's traditional for the app itself to handle it.

                        In many cases you can use either. But to standardize development across operating systems essentially all programming languages have their own development managers. NodeJS, PHP, Java, Go, Python, Ruby.... it's for lots of reasons. But primarily because one is run by the user, one by the admin.

                        OK, so your post is the installation of the development environment using laravel and not when you install a laravel web application on a production server?

                        Otherwise it would be the admin that installs it all.

                        scottalanmillerS 2 Replies Last reply Reply Quote 0
                        • scottalanmillerS
                          scottalanmiller @1337
                          last edited by

                          @Pete-S said in Installing Laravel on Ubuntu 20.04:

                          @scottalanmiller said in Installing Laravel on Ubuntu 20.04:

                          @Pete-S said in Installing Laravel on Ubuntu 20.04:

                          The entire idea of a package manager is that you can easily install what you want and all dependencies are taken care of.
                          Like, apt install laravel and you're done.

                          Sort of, but there are definite differences. For example, installing composer is a system-wide installation; an OS level installation.

                          Composer is for user-level installs into your own home directory. And it is packages from "inside an application". This is the same anywhere. If you add something inside of an app, it's traditional for the app itself to handle it.

                          In many cases you can use either. But to standardize development across operating systems essentially all programming languages have their own development managers. NodeJS, PHP, Java, Go, Python, Ruby.... it's for lots of reasons. But primarily because one is run by the user, one by the admin.

                          OK, so your post is the installation of the development environment using laravel and not when you install a laravel web application on a production server?

                          Correct, you install Laravel for development. When you install production apps, you don't know what framework that they are written in or manage that stuff. Generally.

                          That's not 100% true. It's common to do it both ways. One where you leave loads of needed packages out and expect the installer to go out and get that code, this is sometimes done for licensing reasons. But typically you package all of your code into a single installer.

                          So, as an example, it would be standard to use Laravel to build an app that you want to sell. Then when people deploy it, say on CentOS, you provide a single RPM for the installation of your app.

                          1 1 Reply Last reply Reply Quote 1
                          • 1
                            1337 @scottalanmiller
                            last edited by

                            @scottalanmiller said in Installing Laravel on Ubuntu 20.04:

                            @Pete-S said in Installing Laravel on Ubuntu 20.04:

                            @scottalanmiller said in Installing Laravel on Ubuntu 20.04:

                            @Pete-S said in Installing Laravel on Ubuntu 20.04:

                            I don't understand why you have to uncomment lines in the php.ini for fileinfo & openssl extensions but not the others?

                            Because they are part of php-common, so automatically installed, but all the pieces of common are commented out so you have to turn them on. Those two are required, so you have to enable them since you cant install them on their own.

                            php-openssl doesn't exist anymore, hence the issue.

                            I don't quite understand. You have php-openssl as one of the packages you install on the first line. If it's already installed by default from the php metapackage, you could omit that right?

                            Ah, that was a mistake. I ran that command by mistake and it wasn't needed, but was in my command history and I copied it. It was needed on older Ubuntu, but 20.04 moved it into php-common and changed how it works.

                            OK, that makes sense. I saw you changed the post as well.

                            scottalanmillerS 1 Reply Last reply Reply Quote 0
                            • scottalanmillerS
                              scottalanmiller @1337
                              last edited by

                              @Pete-S said in Installing Laravel on Ubuntu 20.04:

                              Otherwise it would be the admin that installs it all.

                              Exactly, Laravel is "code for developers to use as a baseline" for development. Whereas something made with Laravel would be expected to be deployed by an admin to be run as a server.

                              1 Reply Last reply Reply Quote 1
                              • scottalanmillerS
                                scottalanmiller @1337
                                last edited by

                                @Pete-S said in Installing Laravel on Ubuntu 20.04:

                                @scottalanmiller said in Installing Laravel on Ubuntu 20.04:

                                @Pete-S said in Installing Laravel on Ubuntu 20.04:

                                @scottalanmiller said in Installing Laravel on Ubuntu 20.04:

                                @Pete-S said in Installing Laravel on Ubuntu 20.04:

                                I don't understand why you have to uncomment lines in the php.ini for fileinfo & openssl extensions but not the others?

                                Because they are part of php-common, so automatically installed, but all the pieces of common are commented out so you have to turn them on. Those two are required, so you have to enable them since you cant install them on their own.

                                php-openssl doesn't exist anymore, hence the issue.

                                I don't quite understand. You have php-openssl as one of the packages you install on the first line. If it's already installed by default from the php metapackage, you could omit that right?

                                Ah, that was a mistake. I ran that command by mistake and it wasn't needed, but was in my command history and I copied it. It was needed on older Ubuntu, but 20.04 moved it into php-common and changed how it works.

                                OK, that makes sense. I saw you changed the post as well.

                                I did, I took out the duplicated packages.

                                1 Reply Last reply Reply Quote 0
                                • 1
                                  1337 @scottalanmiller
                                  last edited by

                                  @scottalanmiller said in Installing Laravel on Ubuntu 20.04:

                                  @Pete-S said in Installing Laravel on Ubuntu 20.04:

                                  @scottalanmiller said in Installing Laravel on Ubuntu 20.04:

                                  @Pete-S said in Installing Laravel on Ubuntu 20.04:

                                  The entire idea of a package manager is that you can easily install what you want and all dependencies are taken care of.
                                  Like, apt install laravel and you're done.

                                  Sort of, but there are definite differences. For example, installing composer is a system-wide installation; an OS level installation.

                                  Composer is for user-level installs into your own home directory. And it is packages from "inside an application". This is the same anywhere. If you add something inside of an app, it's traditional for the app itself to handle it.

                                  In many cases you can use either. But to standardize development across operating systems essentially all programming languages have their own development managers. NodeJS, PHP, Java, Go, Python, Ruby.... it's for lots of reasons. But primarily because one is run by the user, one by the admin.

                                  OK, so your post is the installation of the development environment using laravel and not when you install a laravel web application on a production server?

                                  Correct, you install Laravel for development. When you install production apps, you don't know what framework that they are written in or manage that stuff. Generally.

                                  That's not 100% true. It's common to do it both ways. One where you leave loads of needed packages out and expect the installer to go out and get that code, this is sometimes done for licensing reasons. But typically you package all of your code into a single installer.

                                  So, as an example, it would be standard to use Laravel to build an app that you want to sell. Then when people deploy it, say on CentOS, you provide a single RPM for the installation of your app.

                                  That sounds logical , thanks!

                                  1 Reply Last reply Reply Quote 0
                                  • 1
                                    1337
                                    last edited by 1337

                                    @scottalanmiller

                                    Just a side note, but you are implying you already have apache up and running - since that is where you changed the php.ini files.

                                    Do laravel have any module requirements or needed config settings for apache as well?

                                    It's for example not unusual that you need to have mod_rewrite to beautify URLs or that you need to have htaccess files allowed etc.

                                    1 scottalanmillerS 2 Replies Last reply Reply Quote 0
                                    • 1
                                      1337 @1337
                                      last edited by

                                      @Pete-S said in Installing Laravel on Ubuntu 20.04:

                                      @scottalanmiller

                                      Just a side note, but you are implying you already have apache up and running - since that is where you changed the php.ini files.

                                      Do laravel have any module requirements or needed config settings for apache as well?

                                      It's for example not unusual that you need to have mod_rewrite to beautify URLs or that you need to have htaccess files allowed etc.

                                      Perhaps you should assume a newly installed, clean ubuntu 20.04 as your base system.

                                      scottalanmillerS 1 Reply Last reply Reply Quote 0
                                      • scottalanmillerS
                                        scottalanmiller @1337
                                        last edited by

                                        @Pete-S said in Installing Laravel on Ubuntu 20.04:

                                        @scottalanmiller

                                        Just a side note, but you are implying you already have apache up and running - since that is where you changed the php.ini files.

                                        Do laravel have any module requirements or needed config settings for apache as well?

                                        It's for example not unusual that you need to have mod_rewrite to beautify URLs or that you need to have htaccess files allowed etc.

                                        No Apache, that's a PHP config file. You don't really use Apache in development, you can even test applications using Artisan with PHP in user space. I don't use Apache for production deployments either, we use Nginx.

                                        1 1 Reply Last reply Reply Quote 0
                                        • scottalanmillerS
                                          scottalanmiller @1337
                                          last edited by

                                          @Pete-S said in Installing Laravel on Ubuntu 20.04:

                                          @Pete-S said in Installing Laravel on Ubuntu 20.04:

                                          @scottalanmiller

                                          Just a side note, but you are implying you already have apache up and running - since that is where you changed the php.ini files.

                                          Do laravel have any module requirements or needed config settings for apache as well?

                                          It's for example not unusual that you need to have mod_rewrite to beautify URLs or that you need to have htaccess files allowed etc.

                                          Perhaps you should assume a newly installed, clean ubuntu 20.04 as your base system.

                                          It is, the PHP package creates that directory.

                                          1 Reply Last reply Reply Quote 0
                                          • black3dynamiteB
                                            black3dynamite
                                            last edited by

                                            Can’t php modules be enabled using phpenmod?

                                            1 Reply Last reply Reply Quote 1
                                            • 1
                                            • 2
                                            • 1 / 2
                                            • First post
                                              Last post