• Skip to main content
  • Skip to primary sidebar

Technical Notes Of
Ehi Kioya

Technical Notes Of Ehi Kioya

  • About
  • Contact
MENUMENU
  • Blog Home
  • AWS, Azure, Cloud
  • Backend (Server-Side)
  • Frontend (Client-Side)
  • SharePoint
  • Tools & Resources
    • CM/IN Ruler
    • URL Decoder
    • Text Hasher
    • Word Count
    • IP Lookup
  • Linux & Servers
  • Zero Code Tech
  • WordPress
  • Musings
  • More
    Categories
    • Cloud
    • Server-Side
    • Front-End
    • SharePoint
    • Tools
    • Linux
    • Zero Code
    • WordPress
    • Musings

How To Install Laravel On A Local Machine

Tagged: Laravel, PHP

  • This topic has 0 replies, 1 voice, and was last updated 2 years, 8 months ago by Chinomnso.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • November 28, 2019 at 3:55 pm #81257
    Spectator
    @chinomnso

    Some Laravel newbies find it hard to go through the very first step of using Laravel – installing it on their local machine. This article teaches how to install Laravel on a Windows machine, although the principles can be applied to other systems. I’m writing this article assuming that Visual Studio Code is the text editor you will be using.

    Install XAMPP

    XAMPP comes with Apache, MySQL, PHP and Perl. This way, you have Apache as the web server, MySQL for the database on which Laravel will run, and a PHP interpreter. Go to apachefriends.org and download the latest version of XAMPP. Installing XAMPP is a pretty straightforward process, so I ‘m not covering it here. However, if you have any port issues that make it impossible for XAMPP to function properly, be sure to check if any other apps are using ports 80 and 3306. XAMPP runs Apache and MySQL respectively on these ports. So, you need to free them up if they are being used by other apps.

    Install Composer

    Download Composer, a PHP dependency manager from composer.org and run the .exe file. Some have described Composer as “NPM for PHP”. So I hope that explains what composer would do fo you as you use Laravel. During the installation, you will be prompted to supply the path to PHP on your computer. On a Windows machine running XAMPP, it is most likely going to be C:\xampp\php\php.exe. Click Next, ignore the proxy section of the setup and proceed. Composer is now installed and is ready to work on your system.

    Install Visual Studio Code

    Download and install Visual Studio Code, a lightweight text editor from code.visualstudio.com. You’ll be using terminal commands a lot while working with Laravel, and you don’t want to be hopping between your terminal and Visual Sode Code. Visual Studio Code has an integrated terminal that uses Power Shell, but we will be using Git Bash.

    Install Git

    Download git from https://git-scm.com/downloads and install. In Adjusting your PATH environment section, choose the last option. For the remaining options, choose the defaults.

    Launch Visual Studio. Go to View > Integrated Terminal. You will notice it is using Windows PowerShell. Locate the Settings file by going to File > Preferences > Settings, or by clicking CTRL + , (comma). It is a JSON file, so don’t expect to see any buttons or other UI elements you can interact with. Using the search feature, search for “terminal”. Replace the path to PowerShell with the path to Git Bash. Save the file, then close your integrated terminal, reopen it and you will notice that it has changed from PowerShell to Git Bash.

    Assuming you are in the root folder of your machine (C:\), use the following command to migrate to the directory where your Laravel files will be:

    cd xampp/htdocs/
    

    Download Laravel

    Now you’re in the htdocs/ directory, it is now time to download Laravel to your machine. Remember, we installed Composer. We will use it to handle the download. Here’s the command we will use:

    composer create-project laravel/laravel project_name
    

    Under normal circumstances, this should take around 2 minutes to complete. Using the following command in your terminal, migrate into the directory created by the previous command that also downloaded the Laravel files:

    cd project_name
    

    Set up a virtual host

    Head over to your browser, and try loading http://localhost/project_name. You should see a page listing all the files in your project directory. That certainly is not what you want. In fact, this poses a huge security risk if left as is. If you click public/, you should see the default Laravel homepage with navigation in the centre of the page. This again, is not what you want.

    It’s now time to create a virtual host. To do that, we need to edit two files. Head over to C:\xampp\apache\conf\extra\. Open the httpd-vhosts.conf file with a text editor. Copy the following code and paste it at the end of the file:

    
        DocumentRoot "C:/xampp/htdocs/"
        ServerName localhost
    
    
    
        DocumentRoot "C:/xampp/htdocs/project_name/public"
        ServerName project_name.dev
    
    

    The code above creates a faux domain name and points requests to the “public” folder of your application. Be sure to change the “project_name” to the actual name of your project, and “devs” to whatever you want as a domain extension. Using a text editor again, navigate to C:\Windows\System32\drivers\etc. Open the hosts file. Copy the following code and paste at the end of the file:

    127.0.0.1 localhost
    127.0.0.1 project_name.dev
    

    The code above routes all requests to the “domain name” you created back to localhost, ensuring that your browser does not take the request to the internet. Save the file and restart Apache by opening your XAMPP control panel, stopping the Apache service and starting it again. Head over to your browser and enter http://localhost/project_name.dev. This will be the root of your application. If this were live on the web, no one will be able to see your file structure as we saw before.

    At this point, Laravel is all set up and ready to run. Go ahead and play around with the file system, classes, namespaces, models, views, controllers and routes.

  • Author
    Posts
Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.
Log In

Primary Sidebar

FORUM   MEMBERSHIP

Log In
Register Lost Password

POPULAR   FORUM   TOPICS

  • How to find the title of a song without knowing the lyrics
  • How To Change Or Remove The WordPress Login Error Message
  • The Art of Exploratory Data Analysis (Part 1)
  • Welcome Message
  • Replacing The Default SQLite Database With PostgreSQL In Django
  • Getting Started with SQL: A Beginners Guide to Databases
  • How to Implement Local SEO On Your Business Website And Drive Traffic
  • About
  • Contact

© 2022   ·   Ehi Kioya   ·   All Rights Reserved
Privacy Policy