Showing posts with label Laravel-4. Show all posts
Showing posts with label Laravel-4. Show all posts

Laravel 4 : UnexpectedValueException (The stream or file LOG_FILE could not be opened: failed to open stream: No such file or directory)


The stream or file "PROJECT_ROOT/app/storage/logs/LARALVEL_LOG_FILE" could not be opened: failed to open stream: No such file or directory

This may happen when laravel can' find log file.
One solution is to create logs dir manually :


  1. #Goto your laravel project dir. Do the following on terminal:
  2. mkdir app/storage/logs

  3. #incase you forgot file permissions
  4. chmod -R 777 app/

Getting started with Laravel 4 on CentOS ... First Helloworld app with Laravel-4

Install PHP 5.4>:
At least PHP 5.4 is required to install laravel 4.
Uninstall old php versions php 5.3 <=
  1. yum remove php*

Install php 5.4:

  1. rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
  2. yum install php54w
Install php mcrypt extension:

  1. yum install php54w-mcrypt

Install PHP Data Objects (PDO) extension :

  1. yum install php54w-pdo

Install composer (Composer is a dependency manager for PHP.Something like Maven in Java.):

  1. cd /usr/local/bin/
  2. curl -sS https://getcomposer.org/installer | php
  3. mv composer.phar composer
  4. composer self-update

Run the following command to create your first laravel helloworld project:

  1. composer create-project laravel/laravel hello-laravel-4 --prefer-dist

This command will download and install a fresh copy of Laravel in a new hello-laravel-4 folder within your current directory.
Next run the composer install command in the root of your manually created project directory. 
  1. cd hello-laravel-4
  2. composer install
This command will download and install the framework's dependencies.
 Now give execute access to PROJECT_ROOT/app/ dir:


  1. chmod -R 777 app/

Make sure your current directory contains a file named artisan.
Now run the following command to run your first helloworld app:

  1. php artisan serve

Now browse to http://localhost:8000/ to see the output.You should see a screen saying 
"You have arrived." :)

First hello world app with Laravel 4 in WindowsXP

In windows XP at first download xampp 1.8.2 from here.
http://downloads.sourceforge.net/project/xampp/XAMPP%20Windows/1.8.2/xampp-win32-1.8.2-5-VC9-installer.exe
And install it.
And then download Composer from  https://getcomposer.org/
https://getcomposer.org/Composer-Setup.exe
(Composer is a dependency manager for PHP.Something like Maven in Java.)
While installing composer select php.exe from xampp installation directory(XAMPP_INSTALL_DIR\php\php.exe) when prompted.
Now navigate to a directory where you want to create your first laravel project(D:\l4)
with Command Prompt.Run the following command to create your first laravel project:

composer create-project laravel/laravel your-first-laravel-project --prefer-dist

This command will download and install a fresh copy of Laravel in a new your-first-laravel-project folder within your current directory.
Next run thecomposer install command in the root of your manually created project directory. This command will download and install the framework's dependencies.

Make sure your current directory contains a file named artisan.
Now run the following command to run your first helloworld app:
php artisan serve

Now browse to http://localhost:8000/
to see the output.You should see a screen saying "You have arrived."

Simplest way to run/test a php function in Laravel-4 ( Helloworld unit testing! )

Install phpunit:
1. Go to the root directory of your project (where the 'artisan' file is located).
2. Open 'composer.json. Include phpunit dependency in the JSON.
 Save and close the file. After adding the file content should look like:
  1. {
  2. "name": "laravel/laravel",
  3. "description": "The Laravel Framework.",
  4. "keywords": ["framework", "laravel"],
  5. "license": "MIT",
  6. "require": {
  7. "laravel/framework": "4.0.*",
  8. "geoip/geoip": "~1.14"
  9. },
  10. "require-dev": {
  11. "phpunit/phpunit": "3.7.*"
  12. },
  13. "autoload": {
  14. "classmap": [
  15. "app/commands",
  16. "app/controllers",
  17. "app/models",
  18. "app/database/migrations",
  19. "app/database/seeds",
  20. "app/tests/TestCase.php"
  21. ]
  22. },
  23. "scripts": {
  24. "post-install-cmd": [
  25. "php artisan optimize"
  26. ],
  27. "post-update-cmd": [
  28. "php artisan clear-compiled",
  29. "php artisan optimize"
  30. ],
  31. "post-create-project-cmd": [
  32. "php artisan key:generate"
  33. ]
  34. },
  35. "config": {
  36. "preferred-install": "dist"
  37. },
  38. "minimum-stability": "dev"
  39. }

3. Run the following command in that directory :
 
  1. composer update

 and wait for completion.

4. Now after that run the command "vendor\bin\phpunit" ("vendor/bin/phpunit" for linux)
 for running default tests
On Windows run:
  1. vendor\bin\phpunit
On Linux run:
  1. vendor/bin/phpunit
You will see something like this:


PHPUnit 3.7.29 by Sebastian Bergmann.

Configuration read from YOUR_PROJECT_DIR\phpunit.xml

.

Time: 188 ms, Memory: 5.50Mb

←[30;42m←[2KOK (1 test, 1 assertion)
←[0m←[2K

7. Now go to the directory YOUR_PROJECT_DIR/app/tests/
8. Open the file 'ExampleTest.php'. It's content should look something like this:

  1. <?php
  2. class ExampleTest extends TestCase {
  3. /**
  4. * A basic functional test example.
  5. *
  6. * @return void
  7. */
  8. public function testBasicExample()
  9. {
  10. $crawler = $this->client->request('GET', '/');
  11. $this->assertTrue($this->client->getResponse()->isOk());
  12. }
  13. }
  14. 7. Now write your own test function and call it in testBasicExample():
  15. class ExampleTest extends TestCase {
  16. /**
  17. * A basic functional test example.
  18. *
  19. * @return void
  20. */
  21. public function testBasicExample()
  22. {
  23. $crawler = $this->client->request('GET', '/');
  24. $this->assertTrue($this->client->getResponse()->isOk());
  25. self::my_test();//your method
  26. }
  27. public function my_test()
  28. {
  29. echo 'Hi I want to show you some test results :)';
  30. }
  31. }

8. Save and close the file and run again 'vendor\bin\phpunit'.And you will see output like this:

PHPUnit 3.7.29 by Sebastian Bergmann.

Configuration read from F:\laravel\laravelScrapbook\phpunit.xml

.Hi I want to show you test results :)

Time: 172 ms, Memory: 5.50Mb

←[30;42m←[2KOK (1 test, 1 assertion)
←[0m←[2K