4

I've been trying for the last hours to install Laravel 4 on my dreamhost account but I keep getting this error:

Warning: Unexpected character in input:  '\' (ASCII=92) state=1 in /home/user/test/artisan on line 46

Parse error: syntax error, unexpected T_STRING in /home/user/test/artisan on line 46

When I run

/usr/local/bin/php-5.4 -d memory_limit=256M composer.phar create-project laravel/laravel test

I've read that it may be because I use the wrong php version, but I've run the command above with

  • /usr/local/bin/php-5.4
  • /usr/local/bin/php-5.3
  • /usr/local/php53/bin/php
  • /usr/local/php54/bin/php

With the same result. Any ideas? Thanks in advance!

juanlu
  • 398
  • 1
  • 3
  • 12

3 Answers3

7

As mentioned by the answer from Sheikh Heera, the composer.phar must be run with PHP 5.3 or higher.

What has not been mentioned yet is that composer.json contains several references to PHP binary. When installing Laravel in an environment where PHP defaults to a version lower than 5.3 (e.g. WebFaction servers), all references to "php" within file composer.json must be changed to point to a newer version of PHP.

For example:

"post-install-cmd": [
  "php artisan optimize"
],

... must be changed to (something like):

"post-install-cmd": [
  "php54 artisan optimize"
],
Simo A.
  • 1,330
  • 13
  • 18
  • 7 months later, this saved my bacon. This isn't mentioned anywhere! Just 'rawr update to 5.3+!!'. Fantastic catch! – Don Boots Sep 19 '14 at 15:35
  • This was exactly my problem, using shared hosting and they support PHP 5.3+ but their default was 5.2. Thanks! – mmitchell Nov 18 '16 at 17:47
1

In artisan on line 46 there is

$artisan = Illuminate\Console\Application::start($app);

And according to the arror message Warning: Unexpected character in input: '\' the PHP parser didn't recognize the \ which is being used for namespace sincePHP 5.3.0 so it's clear that your PHP version is incorrect. Try to upgrade it. Check you version using

/usr/local/php5/bin/php -v
The Alpha
  • 143,660
  • 29
  • 287
  • 307
  • Then maybe something else is wrong but if `5.3.0 or higher` is installed then it' not about `namespace`. Are you sure about your version ? – The Alpha Jul 27 '13 at 17:05
0

I was guessing this was a PHP version issue and was right. thanks for the other answers guys!

Here is the specific answer if you have hosting from 1and1 / 1&1 create a .htaccess file in the root of your domain with this code in it

AddHandler x-mapp-php6 .php

Note: the "php6" maps to php version 5.4 also note, if there is already a .htaccess file, which there probably is, simply create a line at the beginning and insert this line of code. for example, my .htaccess file for a laravel 5 root domain looks like (thanks to help from http://laravel.io/forum/03-21-2014-laravel-production-deployment-on-1and1)

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On


AddHandler x-mapp-php6 .php


    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ /index.php [L]
</IfModule>

Note the / added to the RewriteRule ^ ... line as well as the php6 part

should be all good, check out their help link here

https://help.1and1.com/hosting-c37630/scripts-and-programming-languages-c85099/php-c37728/manually-set-the-version-of-php-using-an-htaccess-file-a614325.html

Max
  • 454
  • 4
  • 10