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 a 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

About Author

Leave a Reply

Your email address will not be published. Required fields are marked *

PAGE TOP
error

Enjoy this blog? Please spread the word :)

RSS
Follow by Email