Install Laravel – PHP web framework

Laravel is a php web framework which following the model–view–controller (MVC) architectural pattern. It is gaining more and more popularity nowadays.

Get and install composer

Goto (https://getcomposer.org/) Click download.

Run the following:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

This will install ‘composer.phar ‘ in the current directory.

Move that to bin folder to get it globally available as a command and rename it to composer

$ mv composer.phar /usr/local/bin/composer

Open new tab and Type

$ composer

Install Lareval

Using composer

$ composer create-project --prefer-dist laravel/laravel blog "5.4.*"

From laravel/laravel github repo OR via larval installer

$ laravel new blog
-bash: laravel: command not found

Install it:

$ composer global require "laravel/installer"

this makes it globally accessible

Make sure to place the $HOME/.composer/vendor/bin directory (or the equivalent directory for your OS) in your $PATH so the laravel executable can be located by your system.

Open ~/.bash_profile OR ~/.bashrc in Mac

and add the following line:

export PATH="$PATH:$HOME/.composer/vendor/bin"

save and exit

Open New tab type:

$ laravel
Laravel Installer 1.4.1
Usage:
  command [options] [arguments]

Check Laravel version:

$ php artisan --version
Laravel Framework 5.4.27

You are ready to go!

Advertisements

Install latest PHP version on Mac using homebrew

Check php latest version here: http://php.net/downloads.php
=> Update your homebrew

$ brew update
$ brew upgrade

=> Install a centralized repository for PHP-related brews: homebrew-php
https://github.com/Homebrew/homebrew-php

Requirements
* Homebrew
* Yosemite, El Capitan, and Sierra. Untested everywhere else.

Run the following in your command-line:

$ brew tap homebrew/homebrew-php

$ brew search php

will show you all php formula

We will Install php 7.1, because php 7.1.8 is the latest stable version till now (Aug 2017)

$ brew install php71

Check php version installed

$ php --version
PHP 7.1.8 (cli) (built: Aug  7 2017 15:02:19) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies

You are done.

PostgreSQL 9.3 : Installation on ubuntu 14.04

Hi guys, I just started installing postgres on my ubuntu VM. I referred some docs, and followed this one: https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-14-04

Its pretty much explained in this page. But just explaining here the important things.

You can install postgres by ubuntu’s own apt packaging system. Update local apt repository, if u want.

$ sudo apt-get update
$ sudo apt-get install postgresql postgresql-contrib

Postgres uses role based access for the unix users. After the installation a default role called ‘postgres’ will be created. You can login to postgres account and start using or creating new roles with Postgres.

Sign in as postgres user

$ sudo -i -u postgres

Access the postgres console by

$ psql

But i cannot enter into the console and I got the following error:

postgres@8930a29k5d05:/home/rails/my_project$ psql
psql: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

What could be the reason for this error?

So just gone through Postgres doc (http://www.postgresql.org/docs/9.3/static/server-start.html). You can see the same error under the section 17.3.2. Client Connection Problems. But the solution is not mentioned.

Original Reason: PostgreSQL Server was not running after the installation.

I tried to reboot and thought, via init script the server will run automatically. That also not happened. So I understood that something prevents postgres from running the server. What is it?

Just check your postgres server is running or not

$ sudo -aux | grep post
postgres@8930a29k5d05:/home/rails/my_project$ ps -aux | grep post
root       136  0.0  0.2  47124  3056 ?        S    06:10   0:00 sudo -u postgres -s
postgres   137  0.0  0.3  18164  3220 ?        S    06:10   0:00 /bin/bash
postgres   140  0.0  0.2  15572  2192 ?        R+   06:10   0:00 ps -aux
postgres   141  0.0  0.0   4892   336 ?        R+   06:10   0:00 grep post

The server is not running.

Run the server manually by

root@8930a29k5d05:/home/rails/my_project#  /etc/init.d/postgresql start
 * Starting PostgreSQL 9.3 database server
                                                                                                                                                         [ OK ] 
root@8930a29k5d05:/home/rails/my_project# ps aux | grep post
postgres   158  0.1  2.0 244928 20752 ?        S    06:28   0:00 /usr/lib/postgresql/9.3/bin/postgres -D /var/lib/postgresql/9.3/main -c config_file=/etc/postgresql/9.3/main/postgresql.conf
postgres   160  0.0  0.3 244928  3272 ?        Ss   06:28   0:00 postgres: checkpointer process

postgres   161  0.0  0.4 244928  4176 ?        Ss   06:28   0:00 postgres: writer process

postgres   162  0.0  0.3 244928  3272 ?        Ss   06:28   0:00 postgres: wal writer process

postgres   163  0.0  0.5 245652  6000 ?        Ss   06:28   0:00 postgres: autovacuum launcher process

postgres   164  0.0  0.3 100604  3336 ?        Ss   06:28   0:00 postgres: stats collector process

root       178  0.0  0.0   8868   884 ?        S+   06:28   0:00 grep --color=auto post
root@8930a29k5d05:/home/rails/my_project#

Now it is working. If still not works, then try to reconfigure your locales as mentioned here

$ dpkg-reconfigure locales

It is strange that, after installing such a popular db software, it doesn’t provide any information regarding the failure of its own server. It should give the developers some clue so that they can save their precious time.

The reason of this failure, that I concluded is
1. After installation we have to run the server manually
OR
2. I tried resetting the locales (So if no locales set in the machine may prevented the postgres from starting automatically?)

Details about pg gem error: Can’t find the ‘libpq-fe.h header when doing bundle in Rails

If you are getting errors like:

installing pdf-reader 1.3.3
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

/home/vagrant/.rvm/rubies/ruby-2.2.0/bin/ruby -r ./siteconf20150306-5919-1rr483p.rb extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.

when trying to install pg gem,
you are just missing some dependancy library related to libpq. Install the following package


$ sudo apt-get install libpq-dev

then do


$ gem install pg -v 'version-no'

then do


bundle install

Details about Rails paperclip error: ‘There was an error processing the thumbnail for paperclip-reprocess’

I got this error while working with paperclip. The project was stable and I have no idea why this error happens at this point of time.

[paperclip] An error was received while processing: #
[paperclip] An error was received while processing: #<Paperclip::PaperclipError: There was an error processing the thumbnail for paperclip-reprocess20110822-2281-19969sz

So I was lazy to fix the error, and find that I have no imagemagick installed in my new system. After installing ‘imagemagick’ it got fixed.

$ sudo apt-get update
$ sudo apt-get install imagemagick --fix-missing