Clean Install of Laravel using Code Bright Basic Routing Example Not Routing - php

I've just as of right now started to learn Laravel and Composer and I've been following the Basic Routing example I found in Code Bright. I've cloned the Laravel repo, and installed it using Composer as mentioned in the previous Installation section of Code Bright, and am using the Apache config suggested, which is fairly similar to what I would normally use in my other apps using XAMPP, but when I enter in the url to see the route output I get "Whoops, looks like something went wrong".
Step 1
git clone https://github.com/laravel/laravel.git laravel
Step 2
composer install
Step 3
<VirtualHost *:80>
# Host that will serve this project.
ServerName laravel.dev
ServerAlias laravel.dev
# The location of our projects public directory.
DocumentRoot "D:/htdocs/laravel/public"
# Useful logs for debug.
ErrorLog "logs/laravel.dev-error.log"
CustomLog "logs/laravel-access.log" common
# Rewrites for pretty URLs, better not to rely on .htaccess.
<Directory "D:/htdocs/laravel/public">
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
</Directory>
</VirtualHost>
Step 4
Route::get( 'my/page', function() {
return 'Hello World!';
});
Step 5
http://laravel.dev/my/page
I'm running off of Windows, with PHP version 5.5.11 via XAMPP, most recent Composer is installed via Windows installer so on PATH, and Laravel is installed globally.

Got it! I had to turn on debug in app/config/app.php, which popped up the issue in an amazingly descriptive debug screen, and then run key generate since the error was the absence of the encryption key
php artisan key:generate

Related

Gitpod, Docker and Mod_rewrite

I'm struggling with getting mod_rewrite to work, using Gitpod with a Docker container. Currently the webservice returns a status 500, when I create a .htaccess with a mod_rewrite logic in it.
The initial setup
Docker file:
FROM php:8.1-apache
RUN docker-php-ext-install pdo pdo_mysql
.htaccess file:
RewriteEngine On
RewriteRule .* index.php
apache2.conf:
DirectoryIndex index.html index.htm index.php
DocumentRoot "${GITPOD_REPO_ROOT}/${APACHE_DOCROOT_IN_REPO}"
<Directory "${GITPOD_REPO_ROOT}/${APACHE_DOCROOT_IN_REPO}">
AllowOverride all
Require all granted
</Directory>
Also checked the variables to have the correct values present.
This would return a httpstatus 500 when browsing the website.
What did I do
Added the mod_rewrite module to the dockerFile
RUN a2enmod rewrite
This didn't result in any change. The image gets nicely build without a problem.
Validating the setup
check if the module is available in the browser using: print_r(apache_get_modules());. The module is not in the list.
Has it been installed properly? Running apachectl -M on the commandline. Here it shows the module as rewrite_module (shared). Looks like it has been installed properly
The question
At this point I'm stuck and my knowledge runs out. On the commandline the module is enabled, but in the webbrowser it is not. Checked all the settings I could find on google, but no success.
Any suggestions on where I could continue my investigation to have this issue resolved?

laravel New project - getting Index of /name instead of welcome page

I just created a new laravel project on XAMPP using the "composer create-project --prefer-dist laravel/laravel name 5.2.29".
I get a list of files (Index of/) instead of laravel welcome page.
How I can fix this?
XAMPP can't find your index.php file which is inside your public/ directory try to set /public directory as your root directory to do so create a .htaccess in your root folder and add these lines
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Now your web directory points to public
there is 2 options for you to see the wolcome page.
Copy all the files (not folders) from public folder to index folder.
open terminal on this specific folder and write php artisan serve , in this terminal will provide you the link for welcome page.
NB: make sure you'r using latest version of XAMPP
Normal, because the one only directory who should be accessible via url in laravel is public/, so the below url will show laravel's homepage
http://localhost:3000/Application/public
But with Xampp, you can use apache virtualhost's feature to point your-local-domain.dev to C:\Xampp\htdocs\Application\public
Or of course you can use this commande
php artisan serve
So if you are using laragon just like me and you just added the project. What worked for me was simply restarting the laragon server.
If the above doesnt work, just simply switch the root directory settings and switch it back. It should work now
Locate your .conf file inside your /etc/apach2/sites-enabled directory (for example: auto.myapp.test.conf ), open it. Add "/public" at the end of: DocumentRoot and Directory:
<VirtualHost *:80>
DocumentRoot "C:/laragon/www/myapp/public"
ServerName foco.test
ServerAlias *.foco.test
<Directory "C:/laragon/www/myapp/public">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Finally, restart apache server.

How to run Laravel project on normal Apache?

I have Laravel project and can run it with
php artisan serve
I am executing this command inside D:\Users\Dims\Design\MyApplication directory. After that I can see site on http://localhost:8000 and can navigate it, although slow.
Now I am configuring the same place to serve by apache:
<VirtualHost *:80>
ServerAdmin webmaster#myapplication.app
DocumentRoot "D:\Users\Dims\Design\MyApplication\public"
ServerName myapplication.app
ErrorLog "logs/myapplication-error.log"
CustomLog "logs/myapplication-access.log" common
<Directory />
AllowOverride none
Require all granted
DirectoryIndex index.php
</Directory>
</VirtualHost>
Not, that I pointed application not to the root of the project, but to the public directory. This makes me able to open home page of the site, but clicking any links causes error 404.
If I serve
DocumentRoot "D:\Users\Dims\Design\MyApplication"
with Apache, I am unable to see home page at all, saying 403 forbidden. This probably because this directory has no index.php.
So, is it possible to serve Laravel project with Apache?
Yes, it's absolutely possible to serve Laravel applications with Apache. To debug why your links are producing 404 errors, you'll have to provide more information about the URLs these links point to. It's best to always use Laravel's url(), secure_url() or route() helper functions when printing URLs. Also confirm that the Apache module mod_rewrite is enabled (Laravel Installation: Web Server Configuration)
Set up the apache server host file as shown below:
<VirtualHost *:80>
ServerAdmin user#email.com
DocumentRoot D:\Users\Dims\Design\MyApplication\public
ServerName exampledomain.com
ServerAlias www.exampledomain.com
ErrorLog "C:/some_dir/example.error.log"
CustomLog "C:/some_dir/example.access.log" combined
<Directory "D:\Users\Dims\Design\MyApplication\public">
Options -Indexes
DirectoryIndex index.php index.html
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Now that you have set the server name to exampledomain.com you also need to set up the hosts(DNS) file in windows so that you can type in exampledomain.com in your browser and access your laravel project.
Editing the hosts file:
Please follow the steps below:
Press the Windows key.
Type Notepad in the search field.
In the search results, right-click Notepad and select Run as
administrator.
From Notepad, open the following file:
c:\Windows\System32\Drivers\etc\hosts
Make the following changes to the file.
At the end of the file add the following line:
127.0.0.1 exampledomain.com www.exampledomain.com
Click File > Save to save your changes.
What we did here was to tell windows that when we try to access exampledomain.com or www.exampledomain.com do not try to find the server over the internet but take the request to the local machine itself(127.0.0.1) which will in return serve your laravel project.
You can also find one another method here at wikihow -> http://www.wikihow.com/Install-Laravel-Framework-in-Windows
If after configuring the virtualhost you're still unable visit your laravel app, but it works fine with artisan serve, check your apache php version:
Check /etc/apache2/mods-enabled and if the php module is lower than the one required in laravel specifications, update it. In my case:
$ a2dismod php7.0
$ a2enmod php7.2
$ service apache2 reload
Solution found at: https://laracasts.com/discuss/channels/laravel/unexpected-illuminatesupportarrphp-on-line-388

How to Install already created project of Laravel

I have a project which was developed on Laravel. I copied the project and pasted it in XAMPP's htdocs folder.
When I run the project from localhost/LaravelProjectName, it opens following screen:
When I open http://localhost/prg/public/, it opens the login screen, but when I click on any link it opens the page with the following error message:
Whoops, looks like something went wrong.
I searched this on net but couldn't find anything related.
I have Install and update Composer in my destination folder
Use http://localhost/prg/public/index.php
from this url all other route will work just fine.
or use this code inthe .htaccess file in public folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
this will enable you work from http://localhost/prg
You need to set the DocumentRoot of your VirtualHost to /public in your XAMPP/Apache configuration.
<VirtualHost *:80>
ServerName myapp.localhost
DocumentRoot "/full/path/to/laravel/install/public"
<Directory "/full/path/to/laravel/install/public">
AllowOverride all
</Directory>
</VirtualHost>
You would also want to update your hosts file with:
Linux/Mac: /etc/hosts
Windows: c:\Windows\System32\Drivers\etc\hosts
127.0.0.1 myapp.localhost
you can enable debug mode by editing .env file. its locate in root folder.
APP_DEBUG=true
or in the config/app.php
'debug' => env('APP_DEBUG'),
this will gives you what is error rather than "Whoops, looks like something went wrong"
other that navigating to your public folder, you can launch laravel by navigating to root folder in cmd and type 'php artisan serve' it serves your website to localhost:8000
(needs install composer.)
if not work, probably you need to run command 'composer update' to get dependencies.
http://laravel.com/docs/5.0

I can't seem to get started with Zend Framework 2 skeleton app

I'm following through the getting started skeleton app tutorial on the Zend homepage:
http://framework.zend.com/manual/2.2/en/user-guide/skeleton-application.html
I've got as far as being able to enter into the browser address bar "zf2-tutorial.localhost/" and my Zend welcome page should appear. It doesn't, the apache web folder (/var/www) directory appears instead. If I enter "http://zf2-tutorial.localhost/1234" to test whether the Zend 404 page appears, it doesn't. The default apache Not Found page appears.
I created my app by running in terminal:
php composer.phar create-project --repository-url="http://packages.zendframework.com" zendframework/skeleton-application:dev-master /var/www/zf2-tutorial
.. this created all the files in the desired folder (/var/www/zf2-tutorial).
I then created the file /etc/apache2/sites-enabled/zf2-tutorial with the following:
<VirtualHost *:80>
ServerName zf2-tutorial.localhost
DocumentRoot /var/www/zf2-tutorial/public
SetEnv APPLICATION_ENV "development"
<Directory /var/www/zf2-tutorial/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I updated my /etc/hosts file with:
127.0.0.1 zf2-tutorial.localhost localhost
I restarted apache
sudo service apache2 restart
.. and by this point I should be able to see the Zend welcome page so I can proceed with the rest of the tutorial but nothing.
By the way, I'm using Ubuntu 12.04, Apache/2.4.9 (Ubuntu) and PHP 5.5.14.
Is there anything obvious that I've missed out? I've got a feeling that it has something to do with the mod_rewrites but I'm a little confused which I should be updated and how. Any help would be much appreciated.
Add the
<VirtualHost *:80>
[... same code ....]
</VirtualHost>
in the /etc/apache2/sites-enabled/000-default file and restart the apache2
Update -
If it still doesn't work then try the below command and check -
sudo a2enmod rewrite
sudo service apache2 restart
This will enable the rewrite module if not already is.
After entering the URL in the browser, if the required page is not displayed then check the apache error log file located at /var/log/apache2/error.log
By this, you could get some idea as where its going wrong.
Your problem was in config file name. In directory sites-enabled files should have .conf in the end of name.
Good: zf2-tutorial.conf
Bad: zf2-tutorial

Categories