I have apache2 server on Ubuntu 16.04LTS and I have Laravel 5.6 project called book_donation in /var/www/html now when I visit localhost the Laravel welcome screens appear no problem but whenever I click on any url it gives:
Not Found
The requested URL /book_donation/public/login was not found on this
server. Apache/2.4.18 (Ubuntu) Server at 127.0.0.1 Port 80
and here is .htaccess:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
and here is my /etc/apache2/site-available/000-default.conf:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
<Directory "/var/www/html">
AllowOverride all
Require all granted
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
My php version is 7.1 and apache version is 2.4.18, how to solve this?
As stated in the docs, you should configure your web server's document / web root to be the public directory.
Create a new file /etc/apache2/site-available/book_donation.test.conf:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName book_donation.test
ServerAlias www.book_donation.test
DocumentRoot /var/www/html/book_donation/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Edit your /etc/hosts file and add the following:
127.0.1.1 book_donation.test
Then run:
sudo a2ensite book_donation.test.conf
sudo service apache2 restart
Then you should be able to visit book_donation.test and see your site.
I was facing same problem any new route was not working and gave 404 error. Also check php artisan route:list where new route details showing properly but still it was not working. I also tried following command to make it work
php artisan view:clear
php artisan config:clear
php artisan cache:clear
Here are my project details
My DocumentRoot is /var/www/html/project/public. when add new route in web.php, it was nor working and gave 404 error but root route was working fine. Means any new route was working. so I did following changes and it start working.
changed in /etc/apache2/sites-available/project.conf
<Directory /var/www/html/project/public>
**Allowoverride All**
and enable url rewrite by running sudo a2enmod rewrite
restart apache server by running sudo systemctl restart apache2
Related
I have configured httpd in my fedora and I checked everything is true but i get
access forbidden
I have tested everything about .htaccess but still getting access forbidden. also, my laravel folder permissions are correct.
I tested a sample project while installing httpd it worked perfectly with no 'access forbidden' message.
this is my httpd config
<VirtualHost *:80>
ServerName test.com
ServerAlias www.test.com
DocumentRoot /home/myuser/gitlab/register/public
<Directory /home/myuser/gitlab/register/public>
DirectoryIndex index.php
AllowOverride All
Require all granted
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
this is my htaccess in laravel public folder
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
your probably creating the issue by mixing old Apache syntax with new Apache syntax, modern versions of Apache should be something like this...
<VirtualHost *:80>
ServerName test.com
ServerAlias www.test.com
DocumentRoot /home/myuser/gitlab/register/public
<Directory /home/myuser/gitlab/register/public>
DirectoryIndex index.php
AllowOverride All
Require all granted
# Order allow,deny
# Allow from all
</Directory>
</VirtualHost>
I found the problem.
it is because of the
SELinux
ubuntu does not uses SELinux by default but RedHat distributions use it by default. SELinux prevents apache to access the home directory for the sake of security so if you disable or put it to Permissive mode, apache can access your home directory to load the web project. if you do not want to disable SELinux so the correct location for web applications is in /var/www/ folder
so if we change httpd config to
<VirtualHost *:80>
ServerName test.com
ServerAlias www.test.com
DocumentRoot /var/www/gitlab/register/public
<Directory /var/www/gitlab/register/public>
DirectoryIndex index.php
AllowOverride All
Require all granted
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
it works fine
I try my laravel project in apache server
I clone my project
sudo -u www-data git clone ******* laravel
Lunch composer
sudo -u www-data composer install --no-dev --optimize-autoloader
Lunch npm and webpack
sudo -u www-data npm install
sudo -u www-data npm run production
Create .env
sudo -u www-data cp .env.example .env
Generate key
sudo -u www-data php artisan key:generate
sudo -u www-data php artisan config:cache
After clone my project and installed all packages, i configure .htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteBase /laravel/
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
and 000-default.conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/laravel/public
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
Alias /laravel /var/www/html/laravel/public/
<Directory "/var/www/html/laravel/public">
AllowOverride All
allow from all
Options +Indexes
</Directory>
But i have a 500 error when i try to login.
Does anyone have an explanation to this ?
[UPDATE 1]
I forgot to do this :
sudo -u www-data php artisan passport:install
But now all my web routes have this error
[UPDATE 2]
All my web routes have 127.0.0.1:8000. But i'm in production, i shouldn't have this, no ?
[UPDATE 3]
I has installed fruitcake/laravel-cors
sudo composer remove barryvdh/laravel-cors fruitcake/laravel-cors
sudo -u www-data composer require fruitcake/laravel-cors
I allow CORS for all your routes in app/Http/Kernel.php
protected $middleware = [
\Fruitcake\Cors\HandleCors::class,
// ...
]
I reload my Laravel configurations and allow my changes to reflect
sudo -u www-data php artisan config:cache
For mapApiRoutes it's work, but not for mapWebRoutes. How can i fix for mapWebRoutes ?
This:
allow from all
... is Apache 2.2 syntax. In Apache 2.4, use:
Require all granted
Info in the docs.
No need of both Allow and Require i guess, but i am using similar config in all projects and it's working
<Directory /var/www/html/laravel/public>
AllowOverride All
Order Allow,Deny
Allow from all
Require all granted
i was so stupid ...
In my component, l had this
created() {
axios.get('http://127.0.0.1:8000/tasksList')
.then(response => this.tasks = response.data)
.catch(error => console.log(error));
},
BUT, in my .env, i have
APP_URL=http://*****.*****.***:8080
I corrected my component
created() {
axios.get('/tasksList')
.then(response => this.tasks = response.data)
.catch(error => console.log(error));
},
NOW it's work.
been searching for the past 3 days about configuring laravel 5.4 on my linux mint 18.2 system running apache 2.4 . when apache server starts and i manually type in localhost in the browser,it does show up the default home page of laravel , but when i try to access it through live preview in brackets (live preview base url : http://localhost as my laravel project pro lies in /var/www/html/)but it throws internal server error corresponding to the errors in my apache configuration.So here i put forward my .htaccess file , 000-default.conf file in sites-enabled directory of apache2 and apache2.conf files :
One important thing : i got my project folder pro under /var/www/html/
1. 000-default.conf(sites-enabled)
<VirtualHost *:80>
ServerName localhost
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/pro/public
<Directory /var/www/html/pro/public>
Options Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
2. apache2.conf
Mutex file:${APACHE_LOCK_DIR} default
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
Include ports.conf
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
AccessFileName .htaccess
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf
Include /etc/phpmyadmin/apache.conf
3 .htaccess (/var/www/html/pro/public/.htaccess)
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /var/www/html/pro/public/
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
thank you before hand!
Your all routes would be available after index.php, i mean if your route's url is abc, then it will be open as http://localhost/index.php/abc. Now you don't need to change anything in .htacesss file.
Go to your project root and give the read write execute permissions, so that laravel will able to cache the file inside bootstrap/cache directory and able to create your logs file inside storage/logs directory.
sudo chmod -R 777 bootstrap/cache
sudo chmod -R 777 storage/logs
If your project didn't run after that also, then sometimes you need to give this permission also.
sudo chmod -R 777 vendor/ storage/
Run these three commands after that
sudo a2ensite 000-default.conf
sudo a2enmod rewrite
sudo service apache2 restart
your route should be served after localhost.
Hope this will help :)
Try giving read/write permissions to your storage and bootstrap folder in laravel. Also setup virtual hosts if you can. Refer here.
I am running a windows 10 machine with apache 2.4. I am trying to deploy my website to my apache webserver but the routes are not working.
For example, when I go to http://my.domain.com/ I see the website root. But when I try to go to http://my.domain.com/users I get a 404 error.
I am using a virtual host to run my website so it doesn't interfer with mine main domain.
Here are my settings:
React redux routing:
ReactDOM.render(
<Provider store={store}>
<Router history={browserHistory}>
<Route component={App}>
<Route path="/" component={HomePage} />
<Route path="/users" component={UsersPage}/>
<Route path="/user" component={UserPage}>
<Route path="/user/:id" component={UserPage}/>
</Route>
<Route path="*" component={NotFoundPage}/>
</Route>
</Router>
</Provider>,
document.getElementById('app')
);
.htaccess:
RedirectMatch ^/oauth2/redirect/(.*)$ $1
<ifModule mod_rewrite.c>
#######################################################################
# GENERAL #
#######################################################################
# Make apache follow sym links to files
Options +FollowSymLinks
# If somebody opens a folder, hide all files from the resulting folder list
IndexIgnore */*
#######################################################################
# REWRITING #
#######################################################################
# Enable rewriting
RewriteEngine On
RewriteBase /
# If its not HTTPS
# RewriteCond %{HTTPS} off
# Comment out the RewriteCond above, and uncomment the RewriteCond below if you're using a load balancer (e.g. CloudFlare) for SSL
# RewriteCond %{HTTP:X-Forwarded-Proto} !https
# Redirect to the same URL with https://, ignoring all further rules if this one is in effect
# RewriteRule ^(.*) https://%{HTTP_HOST}/$1 [R,L]
# If we get to here, it means we are on https://
# If the file with the specified name in the browser doesn't exist
RewriteCond %{REQUEST_FILENAME} !-f
# and the directory with the specified name in the browser doesn't exist
RewriteCond %{REQUEST_FILENAME} !-d
# and we are not opening the root already (otherwise we get a redirect loop)
RewriteCond %{REQUEST_FILENAME} !\/$
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
# Rewrite all requests to the root
RewriteRule ^(.*) /
</ifModule>
httpd-vhosts.conf
#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
ServerAdmin myemail#nbnet.nb.ca
DocumentRoot "D:/my.domain.com"
ServerName my.domain.com
ServerAlias mystify.homenet.org
ErrorLog "logs/my.domain.com-error.log"
CustomLog "logs/my.domain.com--access.log" common
<Directory "D:/my.domain.com">
Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin myemail#nbnet.nb.ca
DocumentRoot "D:/my.domain.com/lln4"
ServerName lln.domain.com
ErrorLog "logs/lln.domain.com-error.log"
CustomLog "logs/lln.domain.com-access.log" common
<Directory "D:/my.domain.com/lln4">
Options FollowSymLinks
Options All
Include D:/my.domain.com/lln4/.htaccess
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
anyone have any idea why the sub pages of my website arn't working?
after successfully installing XAMP and then typo3 on my Mac, I set up a virtual host to avoid typing long URL when working on TYPO3.
I uncommented the http.conf line dealing with http-vhosts.conf so that I could set up virtual hosts, then I added my virtual host (called typo3dev) in httpd-vhosts.conf and I finally edited my hosts file accordingly.
So far so good, BUT now the issue that I'm having is that while pointing to the BE ( with http://typo3dev/typo3/ ) works just fine (I am able to log in and have fun in there), I cannot see the Frontend:
When pointing my browser to http://typo3dev/ , I get redirected to http://typo3dev/get-started/ where I get a Page Not Found error
Looking at the server error logs in I get that
$[Thu Jun 21 12:39:20 2012] [error] [client 127.0.0.1] File does not exist: /Applications/XAMPP/htdocs/typo3/introductionpackage-4.7.1/get-started
By the way, my hosts file looks like this:
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
127.0.0.1 typo3dev
my httpd-vhosts.conf like that:
NameVirtualHost *:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
DocumentRoot "/Applications/XAMPP/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Applications/XAMPP/htdocs/typo3/introductionpackage-4.7.1"
ServerName typo3dev
</VirtualHost>
Thank you very much in advance for any help/ comment/ advice
Cheers
This looks like a RealURL/Apache configuration problem to me. Make sure that you allow .htaccess in your Apache configuration ...
<VirtualHost *:80>
DocumentRoot "/Applications/XAMPP/htdocs/typo3/introductionpackage-4.7.1"
ServerName typo3dev
<Directory /Applications/XAMPP/htdocs/typo3/introductionpackage-4.7.1>
AllowOverride all
Order allow,deny
allow from all
</Directory>
</VirtualHost>
... or configure the RewriteRules directly in the VirtualHost section.
<VirtualHost *:80>
DocumentRoot "/Applications/XAMPP/htdocs/typo3/introductionpackage-4.7.1"
ServerName typo3dev
<Directory /Applications/XAMPP/htdocs/typo3/introductionpackage-4.7.1>
AllowOverride None
Order allow,deny
allow from all
</Directory>
<Directory /Applications/XAMPP/htdocs/typo3/introductionpackage-4.7.1>
RewriteEngine On
RewriteRule ^/(typo3|typo3temp|typo3conf|t3lib|tslib|fileadmin|uploads|showpic\.php)$ - [L]
RewriteRule ^/(typo3|typo3temp|typo3conf|t3lib|tslib|fileadmin|uploads|showpic\.php)/.*$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]
</Directory>
</VirtualHost>
Remember to reload / restart Apache after making changes to the configuration.
It's seems to me like you have installed the wrong package. Install only the source package because all other package is for demo. Also if you can avoid Apache. It's complicated and bloated. I can recommend lighttpd. It's much easier to configure especially with virtual domains.