how to composer create-project laravel

This guide will help all PHP developers who are looking to try their hands with Laravel on MAC OS.

Laravel, has couple of dependencies and I will not get into all of that, I wanted this installation and setup process to be less complex for any developer reading this and for that have already done lot of research, based on my experience this is the easiest way to get started (there could be more options available with greater minds out there)

Any PHP developer would be familiar with XAMPP, So I would use what we already have installed.

Step 1: Install (Composer)

Point your browser address bar to https://getcomposer.org/composer.phar

Then open Terminal and type bellow to test:

php ~/Downloads/composer.phar --version

Above, command will output as below composer version:

Composer version 1.7-dev (sd2guirofdhdsgjkfg3fsdj4bfdhf) 20xx–00–00 21:36:46

Now let’s copy to bin and install it, with below command:

cp ~/Downloads/composer.phar /usr/local/bin/composer
sudo chmod +x /usr/local/bin/composer

Let’s test, if all is good with composer:

composer --version

You should get below output:

Composer version 1.7-dev (sd2guirofdhdsgjkfg3fsdj4bfdhf) 20xx–00–00 21:36:46

Step 2: Create a new Laravel project

While in Terminal, browse where you want to setup your app and run below command:

composer create-project laravel/laravel demowebsite

Note: demowebsite can be any userdefined name of your project

If you are connected over internet, should se as below, this may take a while based on your internet connection speed.

Installing laravel/laravel (v5.6.12)
- Installing laravel/laravel (v5.6.12): Downloading (100%)
Created project in demowebsite
> @php -r "file_exists('.env') || copy('.env.example', '.env');"
Loading composer repositories with package information
Updating dependencies (including require-dev)

Step 3: Configure virtual host and system host

Browse to, XAAMP/etc/extra/httpd-vhosts.conf open in any text editor and append at the end of file as below:

<VirtualHost *:80>
DocumentRoot “/Applications/XAMPP/htdocs/demo/laravelwebsite/public”
ServerName laravelwebsite.demo
</VirtualHost>

To add entry to system Host, type below command in Terminal:

sudo nano /etc/hosts

Add,

127.0.0.1 laravelwebsite.demo //comment existing one prefixing #

Commands to follow for editing and saving:

ctrl key + 0 //Save
ctrl key + m //To Append
ctrl key + x //To Exit

Once done, now restart Apache server via XAMPP manager.

Important: In order to enable custom virtual hosts to work you need to uncomment below in xamppfiles/etc/https.conf

# Virtual hosts
Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf //removing the # before "Include......"

All set, well not really, let’s test what we get in the browser:

Point you browser to http://laravelwebsite.demo

You may encounter this error as below:

The stream or file "laravel/app/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied

Simple and most suggested solution is to allow permission as below:

chmod -R 777 storage //full rights 777

But, wait this is absolutely dangerous to do while you go in production, as this would open doors for hackers to get into and install any script and make your life difficult.

The more secure way suggested to do this is as below:

// changes the owner to be your username and the web server sudo chown -R $USER:_www /pathtolaravel
// find every file "-type f" , every directory "-type d" execute the chmod command to 664 and 775 for both.
sudo find /pathtolaravel -type f -exec chmod 664 {} \; 
sudo find /pathtolaravel -type d -exec chmod 775 {} \;
// changes the owner recursively across the storage and bootstrap/cache folders and gives web server read, write and execute permissions
sudo chgrp -R _www storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache

Once the permissions are set successfully, reload the browser address bar pointing to http://laravelwebsite.demo

Programmer

01.11.2018
Hiring
We're looking for a web programmer to join an exciting IT solution company working together with people from different disciplines. Essential Duties and Responsibilities: Responsible for clients application and website system development and im...
read more

Speed up iMac

31.08.2019
Uncategorized
Most improvements in macOS Sierra are not immediately visible to the ordinary macOS user. Especially under the hood many improvements have been made in the area of performance and safety. Some users experience a slow Mac after installing MacOS sierra...
read more

php artisan make:auth in laravel 6.0

11.09.2019
Innovation
#php #laravel #tutorial #laravel6 As you may have known by now that laravel 6.0 has been out. Though it’s expected to have a lot of changes in the major release but in 6.0 there are not that many changes. It’s more like 5.9 in te...
read more