Laravel installation & configuration 5.2 - php

Im new to laravel.I've downloaded the laravel 5.2 Via Composer Create-Project.
composer create-project --prefer-dist laravel/laravel blog "5.2.*"
Im using xampp
When i run the project in my chrome browser http://localhost/blog/,
`
Hope help & support

copy .htaccess from the public directory and paste it in the root directory
rename the server.php at the root directory to index.php
visit http://localhost/blog/

I think you can try this:
First open terminal/cmd and write you project full path.
After that run php artisan serve command and it will start the server and give you a url like (http://127.0.0.1:8000).Open the URL in browser. You can see your project running.
Hope this help you

You need to create virtual host for your project.
<VirtualHost laravel.dev:80>
DocumentRoot "C:\xampp\htdocs\laravel\public"
ServerAdmin laravel.dev
<Directory "C:\xampp\htdocs\blog">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
For more information check this guide.

Related

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.

What is wrong in the deploy of this Laravel application? Need I an effective domain instead the vhost used on my local environment?

I am pretty new in PHP and moreover in Laravel and I am pretty desperate trying to deploy a Laravel 5.4 application that works fine on my local environment on my Linux remote server.
So I think that it is something related to virtual host configuration or something like this (maybe also something related to the .htaccess file)
In my local environment (I am using XAMPP on Windows) I have setted this virtual host into the C:\xampp\apache\conf\extra\httpd-vhosts.conf file:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/HotelRegistration/public"
ServerName laravel.dev
</VirtualHost>
So opening the laravel.dev URL I obtain the standard Laravel homepage (I have yet not replaced it with a landing page).
Then if I open this URL: http://laravel.dev/registration
I obtain the user registration page developed by me, this because I have this route into my web.php file into my project:
Route::resource('/registration', 'RegistrationController');
Then into my RegistrationController.php there is this method showing the resources/views/registration/index.blade.php view
public function index(){
return view('/registration/index');
}
All works fine.
Now I have uploaded this Laravel website into my remote Linux server, into this folder: /var/www/html/HotelRegistration
But now my problem is that in this remote environment I have not virtual host (correct me if I am doing wrong assertion: from what I have understand the virtual host is used on the local environment to simulate a domain that Laravel need to point to the public folder, is it this reasoning correct?)
Anyway, this is the URL of the public folder of my deployed web site on my remote server:
http://89.36.211.48/HotelRegistration/public/
As you can see opening it the Laravel landing page is correctly shown, the problem is that I can access to the previous registration page, the only way that I have found is to open this URL:
http://89.36.211.48/HotelRegistration/public/index.php/registration
but it is pretty horrible and above all when the registration form is submitted it is generated a POST request toward this URL http://89.36.211.48/registration that end into a 404 Not Found error.
So I think that it depend by the fact that in this remote server I can't use a virtual host that simulate a domain (as I have on my local environment), but I am not sure about it.
What can I do to solve the situation? Do you think that using a effective domain (something like: www.myregistration.com) that points to this directory of my remote server http://89.36.211.48/HotelRegistration/public/ I can solve this problem?
You need to configure your domain in your server and need to reconfigure the apache. I'm considering you are having apache2 server so here you can do:
Step 1 Go to the apache2 folder cd /etc/apache2
Step 2 You can see sites-available folder go inside it cd sites-available
Step 3 Make a new file name it laravel.dev.conf
Step 4 Write down the following sudo nano laravel.dev.conf
Step 5 Write down the following option:
<VirtualHost *:80>
ServerAdmin webmaster#laravel.dev
ServerName laravel.dev
ServerAlias www.laravel.dev
DocumentRoot /var/www/html/laravel.dev/public/
ErrorLog /var/www/html/laravel.dev/logs/error.log
CustomLog /var/www/html/laravel.dev/logs/access.log combined
<Directory /var/www/html/laravel.dev/public/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
Step 6 Now go to this folder/create a new one cd /var/www/html/laravel.dev
Step 7 Copy/Install your laravel application here.
Step 8 Now you can enable your site by typing sudo a2ensite laravel.dev.conf
Step 9 Now restart the apache2 sudo service apache2 restart
Now you can have proper access to your domain. Hope this helps.
Since you are using XAMPP
Add the following into your VirtualHost Directive:
<Directory "LINUX PATH TO /HotelRegistration/public">
AllowOverride All
</Directory>
Your final VirtualHost Directive should look like:
<VirtualHost *:80>
DocumentRoot "LINUX PATH TO /HotelRegistration/public"
ServerName 89.36.211.48
<Directory "LINUX PATH TO /HotelRegistration/public">
AllowOverride All
</Directory>
</VirtualHost>
After the configuration changes, restart Apache then you are good to go.

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 do install Laravel

The help has a load of different options. I tried:
composer global require "laravel/installer=~1.1"
which returns:
[RuntimeException]
Not enough arguments.
And then there is a load of articles referencing the windows installer located at:
http://laravel.com/laravel.phar
Which says:
"Whoops, looks like something went wrong."
I'm not sure what else to try? Am I missing something?
This should have worked, maybe the tilde needs escaping on your shell (\~), or you could try one of the other formats accepted by the command :
Usage:
require [--dev] [--prefer-source] [--prefer-dist] [--no-progress] [--no-update] [--update-no-dev] [--update-with-dependencies] [packages1] ... [packagesN]
Arguments:
packages Required package with a version constraint, e.g. foo/bar:1.0.0 or foo/bar=1.0.0 or "foo/bar 1.0.0"
Here u can see the installation instructions:
http://laravel.com/docs/4.2/installation
It comes down to this:
Install composer
Download laravel
Put it in the www folder of wamp so you have www/laravel-master
Right click in the root of laravel-master and select composer install
Ready to go
I assumed u use WAMP, if u use something else, put laravel in the map where all your projects are located.
If you are using MAMP, this youtube video will help. It did help me, although I admit in the end it's not as clear as I want it to be.
Anyways, I made my own notes just in case i have to do it again.
a. add MAMP's PHP to PATH VARIABLE in .bash_profile
export PATH=/Applications/MAMP/bin/php/php5.5.10/bin:$PATH
maybe not necessary step if you have an updated php with mcrypt, I just chose to use MAMP's php
b. install Composer
go to http://www.getcomposer.org/ ->getting started ->globally copy and execute 2 commands,
at the terminal…
cd ~
curl -sS https:/?getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
c. install Laravel at MAMP/htdocs folder using composer,
at the terminal…
cd /Applications/MAMP/htdocs
composer create-project laravel/laravel neji --prefer-dist
**where neji is the name of your website/project
d. edit /private/etc/hosts
sudo nano /private/etc/hosts
add 127.0.0.1 neji
e. using any textEditor edit /Applications/MAMP/conf/apache/httpd.conf
uncomment by removing the # before include… on the virtual hosts, see below where...
# Virtual Hosts
#Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
becomes...
# Virtual Hosts
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
f. using any textEditor edit /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
add the following text at the bottom
# I am not sure about this since DocumentRoot does not points to the public folder
# but I still added it and it's working, maybe someone will clarify this part
<VirtualHost *:80>
ServerAdmin localhost
DocumentRoot "/Applications/MAMP/htdocs"
ServerName localhost
ServerAlias www.localhost
# ErrorLog "logs/dummy-host.example.com-error_log"
# CustomLog "logs/dummy-host.example.com-access_log" common
</VirtualHost>
# this one, I think is the code that makes it work bec the DocumentRoot points to public folder
<VirtualHost *:80>
ServerAdmin neji.dev
DocumentRoot "/Applications/MAMP/htdocs/neji/public/"
ServerName neji.dev
ServerAlias www.neji
# ErrorLog "logs/dummy-host.example.com-error_log"
# CustomLog "logs/dummy-host.example.com-access_log" common
</VirtualHost>
** 2 things to note
1. set ServerName to your projectName(neji.dev)
2. set DocumentRoot to the public folder
g. open your project using your fav browser
neji.dev/
**don’t forget the / at the end
You should see the laravel welcome page.
Then after a few days switch to VM :)

Dynamic subdomain with .htaccess (centOS)

I have a dedicated server, on which I'm running several project. Lets say this is example.ro.
The server is running CentOS 6.
I've created a unix user 'dev' and a subdomain: dev.example.ro.
Lets say that I want to work on a project called 'cpl', and I have to test it live on this server (it is a php project).
I would like to use the subdomain dev.cpl.example.ro, and on the filesystem it would be under /home/dev/public_html/cpl folder.
How should I modify my .htaccess in the public_html folder in order to dynamically use subdomains?
I don't think you need to edit the .htaccess file to achieve this. But you have to create a separate site in Apache server. To demonstrate I am using am ubuntu lamp server but I think you can do the same on your CentOS.
Create a virtual site in Apache
sudo nano -w /etc/apache2/sites-available/example.conf
paste the following into the file and make necessary changes
<VirtualHost *:80>
ServerName cpl.example.ro
ServerAlias *.cpl.example.ro
DocumentRoot /home/dev/public_html/cpl
<Directory />
#Options FollowSymLinks
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Save the file. After that you need to enable the newly site.
sudo a2ensite example
service apache2 restart
Edit the host file to resolve the dev.cpl.example.ro
sudo nano -w /etc/hosts
add the following line to the end and save the file
127.0.0.1 dev.cpl.example.ro

Categories