Well, I too use mamp for testing out laravel on my local machine (I have a dedicated dev server for other stuff). Everything works just fine for me.
A few questions.
Thanks for responding so quickly.
I installed MAMP 3
I cd into Projects folder and ran composer and created a project called luna
When I navigate to localhost:8888 I see index of my project luna
If I click on luna I see the index with all the Laravel folders: git, contibuting, app, artisan, boostrap, composer,json, composer.lock, phpunix.xml, public, readme.md, server.php, vendor
I opened Projects > Luna > app > routes.php and tried a simple example from CodeBright:
Route::get('my/page', function(){
return 'Hello World!';
}
Based on my understanding of routes, I assumed that I should be able to navigate to http://localhost/luna/my/page and see the "Hello World" message.
But I get an 404 error "The requsted URL /luna/my/page was not found on this server"
If I update routes.php to:
Route::get('/', function(){
return View::make('hello');
});
Then when I go to localhost:8888/luna/public i get the "You Have Arrived" page
Let's forget about the mamp for now. Let's make sure your laravel installation works.
in the laravel directory, where you ran composer, type "php artisan serve". This will run an internal webserver, which opens up 8000 port by default. Once you have that, open your browser and access http://localhost:8000
If that works, you have an issue with your mamp configuration.
If it is mamp, check the following
Let me know how it goes. If nothing works out, I will just send you my mamp config.
When I open my browser and access http://localhost:8000 I get the "You have arrived" page
Things are working when I use the default return View::make('hello');
But if I add my own route like:
Route::get('/',SomeController@index');
Then I get page error stating that something went wrong.
So as long as I use localhost/luna/plublic/ I can get to my pages
Is that correct? or is there a way to hide the /plubic from my dev environment?
Ok..that confirms that you've installed laravel correctly. It's matter of your server configuration now.
Just point to public. In MAMP 3, click 'Preferences...' then click 'Apache' then change the Document Root to your 'public' directory. Restart MAMP.
see if changing document root works.
IF NOT,
Open /Applications/MAMP/conf/apache/httpd.conf
Look for <Directory />
change <Directory /> to <Directory /YOUR LARAVEL FOLDER/public>
inside <Director> and <Directory, add
Options Indexes Includes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
restart mamp and see if it works.
xuamox said:
Thanks for responding so quickly.
I installed MAMP 3
- start/stop - everything is checked, and at startup open /MAMP/
- Apache Port: 8888, MySQL Port: 8889
- PHP 5.5.10
- Apache Document Root "Projects" folder
I cd into Projects folder and ran composer and created a project called luna
When I navigate to localhost:8888 I see index of my project luna
If I click on luna I see the index with all the Laravel folders: git, contibuting, app, artisan, boostrap, composer,json, composer.lock, phpunix.xml, public, readme.md, server.php, vendor
I opened Projects > Luna > app > routes.php and tried a simple example from CodeBright:
Route::get('my/page', function(){ return 'Hello World!'; }
Based on my understanding of routes, I assumed that I should be able to navigate to http://localhost/luna/my/page and see the "Hello World" message.
But I get an 404 error "The requsted URL /luna/my/page was not found on this server"
If I update routes.php to:
Route::get('/', function(){ return View::make('hello'); });
Then when I go to localhost:8888/luna/public i get the "You Have Arrived" page
Make sure you delete the index.html in public
First of all, the mcrypt problem is not MAMP's problem!
Mac ships with a php version that doesn't come with mcrypt extension natively. Even if you install MAMP doesn't mean your computer is going to use the new PHP 5.5 interpreter.
If you do a check in terminal,
$ which php
You will probably get something like /usr/bin/php
and this is not what you want.
You should open up the .bash_profile ( if you don't have, create one. ) at your home directory /Users/yourname
, and export the PHP you want the system to use.
For Instance, assuming you use PHP5.3.14, the newest MAMP should ship with PHP5.5, depends on your need, you should check out the /Applications/MAMP/bin/php
folder to get the right PHP version you need.
export PATH=/Applications/MAMP/bin/php/php5.3.14/bin:$PATH
You are recommended to use virtual host when using Laravel. That should solve your 404 error.
$ sudo vi /etc/hosts
Enter your password, and add a line, for example
127.0.0.1 myapp.dev
Then, navigate to /Applications/MAMP/conf/apache/extra
,
Add the following line to this file. httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "/Applications/MAMP/htdocs/your_laravel_installation/public"
ServerName myapp.dev
</VirtualHost>
Finally, restart your apache server and access `http://myapp.dev" and see if it works. You would need to attach http:// in the very first time, as the internal DNS might not be wired up appropriately.
If I remember correctly, there shouldn't be any configuration you need to change to both MAMP and Laravel to boot your app.
Hope it helps.
$ which php
returns: /Application/MAMP/bin/php/php5.5.10/bin/php
Good. Do you still have problems running php artisan
? If not, the CLI portion is good to go.
The web portion, did you setup a virtual host? The code I had above was assuming you use port 80 tho. You should be able to change that setting in MAMP.
Code Bright gives this as an example, and I tried to customize and implement, but then I can't restart MAMP server.
<VirtualHost *:80>
# Host that will serve this project.
ServerName app.dev
# The location of our projects public directory.
DocumentRoot /path/to/our/public
# Useful logs for debug.
CustomLog /path/to/access.log common
ErrorLog /path/to/error.log
# Rewrites for pretty URLs, better not to rely on .htaccess.
<Directory /path/to/our/public>
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
</Directory>
</VirtualHost>
It shouldn't really matter where the location is. You just need to switch the location you are having. Let's try the most basic one ↓ ( Make sure the port is at 80 tho )
<VirtualHost *:80>
DocumentRoot "/Projects/luna/your_laravel_installation/public"
ServerName myapp.dev
</VirtualHost>
Try setup a virtual host and see if the routes are good.
You could make a test.php with phpinfo() in your public folder to see if it routes to the correct location.
If http://myapp.dev/test.php works,
For testing purpose, you should wipe out your routes.php.
Route::get('test', function() {
return 'I am here';
});
if a plain route works, then it's your controller's problem.
PS
Make sure you do $ php artisan dump-autoload
When you create a controller or new model, you should try to do that to make sure those new files are autoloaded.
PS2 Check your log located at app/storage/logs/, see if there is any errors?
As a side note... I would recommend looking at Vagrant. I know you're only looking into Laravel for the first time recently, but once you start experimenting, a virtual machine is the way to go. It has the advantage of being an almost complete sandbox -- where you can play around and not worry about messing anything up. If anything goes wrong you can have a new VM up in seconds.
Here is a pretty good starting point for getting a fresh Laravel installation up and running in a few minutes. You won't look back!
It sounds like to me xuamox is new to MAMP and Laravel and never configured an Apache before.
xuamox, which example are you trying to do? what page are you on codebright?
It sounds like you're just copying and pasting without updating values of those configurations. It WILL not work if you just copy and paste. Point me to the example you're reading.
It's not Laravel issue. It's server configuration issues.
After countless hours messing around with MAMP, I have decided to use Vagrant instead. Vagrant is much easier to work with, and the installation process makes much more sense to me. Thanks for suggesting that I take a look at Vagrant. It's definitely the way to go for any beginner.
Also, for a really decent Bash file, check out: https://github.com/fideloper/Vaprobash/blob/master/Vagrantfile
Vagrant + Vaprobash has been a winning combination for me. I highly recommend it for anyone new to Laravel and virtual servers.
If you use Vaprobash, remember to use the "Develop" version of the Vagrantfile.
Kudos to Chris Fidao who contributed Vaprobash and has gone above and beyond to help users get started with Vagrant. and Laravel
So this one is not actually solved since the xuamox decided to ditch MAMP and use Vagrant instead. What about for those of us who want to use MAMP? I haven't been able to find an answer to this issue.
I have the solution to this problem. This also gave me many headaches starting out. I have learned to keep a journal of errors and issues I encounter with configuring applications.
If error PDOException' with message 'SQLSTATE[HY000] [2002] No such file or directory
in CLI
sudo mkdir /var/mysql
cd /var/mysql
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock
If php version pointing to Mac PHP version and not MAMP
then in CLI
touch .bash_profile
open .bash_profile
then type:
export PATH=/Applications/MAMP/bin/php/php5.5.10/bin:$PATH
https://discussions.apple.com/message/20527774#20527774
To download Mcrypt PHP Library
awsp said:
It shouldn't really matter where the location is. You just need to switch the location you are having. Let's try the most basic one ↓ ( Make sure the port is at 80 tho )
<VirtualHost *:80> DocumentRoot "/Projects/luna/your_laravel_installation/public" ServerName myapp.dev </VirtualHost>
Try setup a virtual host and see if the routes are good.
You could make a test.php with phpinfo() in your public folder to see if it routes to the correct location.
If http://myapp.dev/test.php works,
For testing purpose, you should wipe out your routes.php.
Route::get('test', function() { return 'I am here'; });
if a plain route works, then it's your controller's problem.
PS Make sure you do
$ php artisan dump-autoload
When you create a controller or new model, you should try to do that to make sure those new files are autoloaded.PS2 Check your log located at app/storage/logs/, see if there is any errors?
awsp, my test.php works, but my basic /test route does not. Any suggestions?
How about ...
http://myapp.dev/index.php/test
If above is working, maybe you want to check Apache's configuration. You should probably check if your mod_rewrite is working correctly. If I remember correctly, somebody had a problem from IRC that his Apache setting didn't allow individual .htaccess to be overridden. I guess it's also a good idea to check that out as well.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community