Visting a laravel project with localhost via apache - php

I have just installed a laravel project into my Home/public_html folder. I gave it a name, let's call it laravel for this purpose. So the template installed to Home/public_html/laravel and then I ran a composer install. I got a database password error. I fixed that, ran it again, and all went well. I then created a migration, a controller, and a view. I tried to navigate to it via localhost/laravel/public/events (events is my created view) I get a 404. I remembered I needed a config file in etc/apache2/sites-available I created the config file with this structure:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /home/user/public_html/laravel/public/
<Directory /home/user/public_html/laravel/public/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/laravel-error.log
CustomLog ${APACHE_LOG_DIR}/laravel-access.log combined
</VirtualHost>
I then created a symlink into the sites-enabled folder. That didn't help.
I then navigated to localhost/laravel and it just gives me the directory structure.
What have I missed? What have I done wrong?
I have another folder inside public_html with its own config file that works perfectly (it points to home/user/public_html/. It also has a symlink. Is there something in each project that tell the project which config to use? Do they just work? My knowledge of this really stops here. Basically, I've exhausted what I know. What am I missing/doing wrong?
Oh and I have restarted apache as well. - a couple of times through the steps I just detailed.

Exposing the Laravel instalation to the web server is never a good idea. Since you can access the file listing of the laravel folder, I believe your document root is set to /home/user/public_html.
Better approach to solve this problem will be as follows.
Keep entire laravel installation outside public_html directory. Let's assume inside /home/user/development
You may need to add following to the apache configuration below DocumentRoot.
Alias /laravel /home/user/development/laravel/public
Add following Directory Configuration
<Directory /home/user/development/laravel/public/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Add following to .htaccess file in /home/user/development/laravel/public/ below RewriteEngine rule.
RewriteBase /laravel
Restart the apache2 server, your site should be available on localhost/laravel. Make sure there are no folder named laravel inside the public_html folder.

Related

How do you configure Symfony 4 to route alongside other XAMPP (Apache) projects?

I'm brand new to Symfony, so this question will undoubtedly come across as noobish. How do you get Symfony to work with XAMPP? I've read the Symfony documentation for configuring Apache, but can't make heads or tails of it.
XAMPP projects are stored in a single /htdocs directory. Each project has its own subfolder and is accessible via the following URL: http://localhost/project_folder. At least, that's how I've been doing it.
My problem is this: Symfony is different in that its root directory is not front-facing. In other words, to actually access a Symfony 4 site, you need to navigate to the /public directory. However, as my local XAMPP (i.e. Apache) server is configured to use a single DocumentRoot (/xampp/htdocs), my Symfony project is inaccessible unless I manually append /public to the URL.
What I want: http://localhost/symfony_project_folder
What I have: http://localhost/symfony_project_folder/public
I do not want to set up an entirely separate local server for a single web application, nor do I want to deal with an entirely different URL structure than what is used by my other projects.
How do I configure Symfony 4 or Apache to properly route to /public in this environment?
Thank you for your help.
Hi there indeed when you create a new symfony project you need to change the document root of the domain in public folder. A good way to work with symfony would be to use docker which helps you out keep projects separated and you can use phpdocker.io to generate a docker configuration very fast to start working with docker.
Anyway here is an example from symfony manual on how to setup a vhost.
<VirtualHost *:80>
ServerName domain.tld
ServerAlias www.domain.tld
DocumentRoot /var/www/project/public
<Directory /var/www/project/public>
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
# uncomment the following lines if you install assets as symlinks
# or run into problems when compiling LESS/Sass/CoffeeScript assets
# <Directory /var/www/project>
# Options FollowSymlinks
# </Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>
You can read more about web server configuration here

How can I start a laravel project outside of "htdocs" folder in xampp?

Is it a way to start a Laravel project in another folder? For example:
instead of C:/xampp/htdocs
to D:/projects/web/project1
So after I download Laravel with composer to my D:/projects/web/project1 folder I want to reach it as: http://project1.local in my browser.
I added 127.0.0.1 project1.local to my hosts but it only opens xampp in the browser.
Suggestions, ideas?
You need to indicate to xampp that your site will be sited outside the documentroot folder (where all the sites in your server are located).
In your httpd.conf file add these lines, which will allow to you to access the site via http://localhost/laravel.project:
Alias /laravel.project "D:/projects/web/project1/public"
<Directory "D:/projects/web/project1/public">
Options FollowSymlinks
AllowOverride none
Require all granted
</Directory>
If you want to get access directly, via a uri like http://laravel.project, you must create a VirtualHost.

XAMPP localhost returns object not found after installing Laravel

After much faffing about I got laravel to work with XAMPP. However, I can't seem to access directories in the htdocs folder via localhost now. Attempt to access a file returns Object not found! along with The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.
The changes I made to get laravel working seems like a blur now. The only thing I remember doing is editing the hosts file to enable the virtual host to work by adding 127.0.0.1 laravel.dev in the hosts file (using a mac btw). I also added a virtual host to the httpd-vhost.conf file.
I did undo the above changes but it didn't make a difference.
Any thoughts on whats gone wrong?
Thanks.
Dispelling Confusion
Just thought I'd clarify what my experience is. Before installing laravel 4 I could access all my projects with localhost/someProjectName but now it fails.
I'm trying to identify what change caused this behaviour. Btw, I have no problems accessing my laravel project (my mapping allows me access to it via laravel.dev)
Look into your /etc/httpd.conf file and see if you have Virtual hosts activated.
If so, check your etc/extra/httpd-vhosts.conf file. You might have set up a VirtualHost already.
EDIT: I have found that once you turn on Virtual Hosts, XAMPP needs a default VirtualHost for your basic htdocs files
Try adding a default VirtualHost (at the bottom of the file) like so:
<VirtualHost *:80>
ServerName localhost
DocumentRoot "/Applications/XAMPP/htdocs"
<Directory "/Applications/XAMPP/htdocs">
Options Indexes FollowSymLinks Includes execCGI
AllowOverride All
Order Allow,Deny
Allow From All
</Directory>
</VirtualHost>
It sounds to me like it is a problem with the way your directories are configured. Be sure to create a Virtual Host (if you're using Apache) that points to the public folder within your application directory.
For example, if your Laravel project is under /Applications/XAMPP/htdocs/Laravel then set up a Virtual Host like this:
<VirtualHost *:80>
DocumentRoot /Applications/XAMPP/htdocs/Laravel/public
# Other directives here
</VirtualHost>
Additionaly, if you're working with PHP >= 5.4, SSH into the application folder and run
./artisan serve
(Be sure that your PHP executable is in your PATH variable). Then go localhost:8000 and you should have your application running.
Running this command runs the PHP built-in webserver and saves you the trouble of configuring virtual hosts.
In your Apache's http.conf, find the DocumentRoot line and add the subdirectory /public on the end.
Once that is done and you've restarted Apache, you'll be able to access everything which is contained within your htdocs/public folder (including subdirectories of that folder), along with any routes you've defined in Laravel.
Laravel is designed to be set up this way as to protect the code and files by not having them in the folder which is served out to the web.
I have same issue and found that there are miss configuration in vhost. So that's are correct configuration.
in etc/extra/httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "D:/xampp/htdocs/laravel-master/public"
ServerName laravel.local
ErrorLog "logs/laravel-master-error.log"
<Directory D:/xampp/htdocs/laravel-master/public>
AllowOverride All
Order Allow,Deny
Allow From All
</Directory>
</VirtualHost>
In the hosts file
127.0.0.1 laravel.local
I don't know if you're running L4 or L3. However, launch CLI and
$ cd ./path/to/project
Then for L4:
$ php artisan serve
For L3:
$ php -S localhost:8000 -t public
Now you can go to localhost:8000 and see your application.
You're having problem because the object really doesn't exist in your htdocs directory. You don't have to append xampp after localhost or 127.0.0.1 because xampp will treat it as an object or a folder under htdocs.
if you want to access your blog, make sure you have a blog folder under htdocs and put in your URL localhost/blog

VIrtualHost Options returns an index of the site folder

I am not sure why this is happening as I am not very knowledgeable when it comes to Apache. Below is a copy of my VirtualHost.
If this gives any extra help as to how to get it to work, I am trying to run a CakePHP site. I know the site itself has no issues as I have another location I manage the code from and can get it running locally through Apache there.
<virtualhost *:80>
DocumentRoot "C:/sites/sitename"
ServerName dev.sitename.com
ErrorLog "logs/sitename.com-error.log"
CustomLog "logs/sitename.com-access.log" common
<directory "C:/sites/sitename">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order Allow,Deny
Allow from all
</directory>
</virtualhost>
I am running this on Apache 2.0 and Win7sp1
UPDATE
I never found the real solution using the route I was on. I downloaded a fresh copy of WAMP and was soon able to get everything up and running, no problem.
In order to prevent apache from showing the directory listing, you need to disable indexes. Also, it's best to disable MultiViews as that will enable content-negotiating, which may produce unwanted side-effects
Change the options to;
Options -Indexes FollowSymLinks
Then, check that the .htaccess file is present inside your webroot (C:/Sites/Sitename), as that file is used to enable mod_rewrite
Additional pointers/hints
First of all, make sure that the DocumentRoot is pointing to the right directory of your application;
The standard directory structure of CakePHP looks like this;
app
/Config
/Controllers
/Views
......
/webroot
lib
/Cale
plugins
The DocumentRoot should point to your `app/webroot' directory, which contains all 'public' files.
Change the paths/directories in your virtual host to that directory and restart Apache.
If you're still getting a 403 error, change the URL you're visiting in your browser to this;
http://mywebsite.com/index.php
If this does work, check if the .htaccess file is present in that directory and mod_rewrite is installed in your Apache.
According to the answer from "thaJetzah" (sorry, can't comment yet:) )
403 Forbidden is better than having the index of the folder, because now you can see the logs/sitename.com-error.log log and hopefully it tells you, why it gives 403.
Just to make sure: The index.php is in the folder "C:/sites/sitename"?
If you can't isolate the error like this, it would be great to post here the output of the error.log when you try to access the page and it gives you 403.
Check this If you are running Ubuntu.

How to configure symfony when using apache

Please help, how do I configure apache (wamp) in windows when I want to use symfony as my php framework, I followed the guide(pdf) from the symfony site. But I end up with this when I access http://127.0.0.1:8080/:
But I end up with this, when I try to access http://localhost/sfproject/web/frontend_dev.php
What is the correct url to access when I want to start using symfony?
I installed symfony on:
C:\dev\sfproject\lib\vendor\symfony
And the projects are in:
D:\Programs\wamp\www\sfproject
I added the lines below on my httpd.conf.
I've done it by left clicking the wampserver tray icon->apache->httpd.conf
I got the code below from the pdf file, and just modify it to match the directory.
#Be sure to only have this line once in your configuration
NameVirtualHost 127.0.0.1:8080
#This is the configuration for your project
Listen 127.0.0.1:8080
<VirtualHost 127.0.0.1:8080>
DocumentRoot "D:\Programs\wamp\www\sfproject\web"
DirectoryIndex index.php
<Directory "D:\Programs\wamp\www\sfproject\web">
AllowOverride All
Allow from All
</Directory>
Alias /sf C:\dev\sfproject\lib\vendor\symfony\data\web\sf
<Directory "C:\dev\sfproject\lib\vendor\symfony\data\web\sf">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
I also didn't install symfony using svn. I just copy pasted the downloaded symfony 1.4.zip. Then extracted the contents. It basically looks like this:
Please don't limit your answer to my question, I've just started installing symfony today. So if you have something to tell to a beginner like me, then please do, thanks.
You are getting the correct page! Just missing CSS/Images.
This bit in your config looks wrong:
Alias /sf C:\dev\sfproject\lib\vendor\symfony\data\web\sf
<Directory "C:\dev\sfproject\lib\vendor\symfony\data\web\sf">
Those two directories should match whats in your DocumentRoot i think...
Try
Alias /sf D:\Programs\wamp\www\sfproject\lib\vendor\symfony\data\web\sf
<Directory "D:\Programs\wamp\www\sfproject\lib\vendor\symfony\data\web\sf">
Alternatively:
Copy lib/vendor/symfony/data/web/sf to your web/ folder so that there is a web/sf folder with the same contents as the lib/vendor/symfony/data/web/sf one.

Categories