{"id":6447,"date":"2019-09-12T07:45:05","date_gmt":"2019-09-12T07:45:05","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=6447"},"modified":"2021-11-16T10:14:25","modified_gmt":"2021-11-16T10:14:25","slug":"setting-a-local-development-environment-for-laravel-on-windows-install-laravel-on-windows","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/setting-a-local-development-environment-for-laravel-on-windows-install-laravel-on-windows\/","title":{"rendered":"Setting a Local Development Environment for Laravel on Windows | Install Laravel on Windows"},"content":{"rendered":"\n<p>Many developers use Windows for PHP projects, we will cover a basic XAMPP Setup for a Laravel project. Following these easy steps will help you run your PHP projects and install Laravel on Windows in a matter of minutes.<\/p>\n\n\n\n<p>1.<strong>Installing XAMPP for Laravel<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Download XAMPP for Windows from their official site: https:\/\/www.apachefriends.org\/download.html<\/li><li>For our example, we\u2019ve chosen PHP 7.1 and XAMPP 32 bit<\/li><li>Run the installer and select Apache, MySQL and phpMyAdmin<\/li><li>It\u2019s recommended to make the installation in C:\\ to avoid issues with Windows User permissions (or the drive where your Windows is installed)<\/li><li>After it\u2019s complete do not start anything just yet.<\/li><\/ul>\n\n\n\n<p>2.<strong>Setting PHP from Windows CMD<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Open Advanced System Settings (System Properties -&gt; Advanced)<\/li><li>Open Environment Variables<\/li><li>On the top window select Path and click on Edit<\/li><li>In the new window click on New<\/li><li>We need to enter the path to XAMPP\u2019s PHP<\/li><\/ul>\n\n\n\n<p>\n\nWe will also add MySQL\u2019s Path, click on New again and enter\n<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">C:\\xampp\\mysql\\bin<\/code><\/span><\/pre>\n\n\n<p>3.<strong>Composer from Windows CMD<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Download Composer\u2019s Windows .exe installer: https:\/\/getcomposer.org\/download\/<\/li><li>Place the installer and run it from the added to Path directory \u2013 <\/li><\/ul>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">C:\\xampp\\php<\/code><\/span><\/pre>\n\n\n<p>Now that we have Apache, PHP, MySQL and Composer installed, we\u2019re ready to install Laravel, set a Virtual Host with a custom domain for local development. XAMPP\u2019s Apache uses the htdocs folder for serving HTTP requests, we\u2019ll set our custom Laravel Virtual Host under C:\\xampp\\htdocs\\example\\ which will be opened locally from example.com<\/p>\n\n\n\n<p>4.<strong>Install Laravel on Windows with Composer<\/strong><br>\n<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Open Window\u2019s CMD or PowerShell<\/li><\/ul>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">cd C:\\xampp\\htdocs<\/code><\/span><\/pre>\n\n\n<p>\nInstall Laravel using Composer<br><\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">composer create-project --prefer-dist laravel\/laravel example<\/code><\/span><\/pre>\n\n\n<p>5.<strong>Creating MySQL Database for Laravel<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Open the CMD or PowerShell again<\/li><li>Access the MySQL CLI<\/li><\/ul>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">mysql -u root -p<\/code><\/span><\/pre>\n\n\n<p>\nCreate Database for Laravel\n<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">CREATE DATABASE laravel <span class=\"hljs-keyword\">DEFAULT<\/span> CHARACTER SET utf8 COLLATE utf8_general_ci;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>6.<strong>Setting Laravel\u2019s .env file<\/strong><br>\n<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Navigate to C:\\xampp\\htdocs\\example<\/li><li>Open the .env file and edit the MySQL Connection settings<\/li><\/ul>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">DB_HOST=localhost\nDB_DATABASE=laravel\nDB_USERNAME=root\nDB_PASSWORD=<\/code><\/span><\/pre>\n\n\n<p>7.<strong>Virtual Host with XAMPP<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Navigate to C:\\xampp\\apache\\conf\\extra<\/li><li>Open httpd-vhosts.conf and append:<\/li><\/ul>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\">NameVirtualHost *:80 \n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">VirtualHost<\/span> <span class=\"hljs-attr\">example.com:80<\/span>&gt;<\/span>\n DocumentRoot \"C:\\xampp\\htdocs\\example\\public\"\n ServerName example.com\n ServerAlias www.example.com\n <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Directory<\/span> \"<span class=\"hljs-attr\">c:<\/span>\/<span class=\"hljs-attr\">xampp<\/span>\/<span class=\"hljs-attr\">htdocs<\/span>\/<span class=\"hljs-attr\">example<\/span>\/<span class=\"hljs-attr\">public<\/span>\"&gt;<\/span>\n Require all granted <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">Directory<\/span>&gt;<\/span>\n <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">VirtualHost<\/span>&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>8.<strong>Enable mod_rewrite for Laravel<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Open the httpd.conf file in C:\\xampp\\apache\\conf\\extra<\/li><li>Look for LoadModule rewrite_module modules\/mod_rewrite.so and remove the ; at the start<\/li><\/ul>\n\n\n\n<p>9.<strong>Setting local domain with hosts file<\/strong><br>\n<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Navigate to c:\\Windows\\System32\\Drivers\\etc<\/li><li>Open the hosts file with Administrator Privileges<\/li><li>Append the line at the bottom<\/li><\/ul>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\">127<span class=\"hljs-selector-class\">.0<\/span><span class=\"hljs-selector-class\">.0<\/span><span class=\"hljs-selector-class\">.1<\/span> <span class=\"hljs-selector-tag\">www<\/span><span class=\"hljs-selector-class\">.example<\/span><span class=\"hljs-selector-class\">.com<\/span> <span class=\"hljs-selector-tag\">example<\/span><span class=\"hljs-selector-class\">.com<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Start Apache and MySQL, your local Laravel project will be opened from example.com and you\u2019re ready to start working on it. When ready you can contact us to have it deployed on a WebHostFace server<\/p>\n\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_11670\"><iframe loading=\"lazy\"  id=\"_ytid_76496\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  data-epytgalleryid=\"epyt_gallery_11670\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><div class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Many developers use Windows for PHP projects, we will cover a basic XAMPP Setup for a Laravel project. Following these easy steps will help you run your PHP projects and&#8230; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[5201],"tags":[5203,177],"class_list":["post-6447","post","type-post","status-publish","format-standard","hentry","category-laravel","tag-laravel","tag-php"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/6447","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=6447"}],"version-history":[{"count":6,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/6447\/revisions"}],"predecessor-version":[{"id":25445,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/6447\/revisions\/25445"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=6447"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=6447"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=6447"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}