Laravel virtual server routing doesn't work - php

I have installed newest Laravel on my Apache2. I run in Terminal
php artisan serve --port=8080
And It works. I have sub-pages and everything I need. But I want to have access without run this command.
I have next mylaravel.com.conf file in /etc/apache2/sites-available
<VirtualHost *:80>
ServerName mylaravel.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/mylaravel/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
My Laravel files is of course in /var/www/mylaravel. In this configuration mylaravel.com works, but when I try for simple mylaravel.com/auth/register Apache return
When I used php artisan [...] this works fine. How can I fix it?

I had this same problem a while ago. From here:
If you don't have AllowOverride set to All, your Laravel .htaccess file (/public/.htaccess) won't be able to enable mod_rewrite, and your routes won't work.
Try adding the following to your <VirtualHost> block:
<Directory "/var/www/mylaravel/public">
Options All
AllowOverride All
Allow from all
</Directory>
So all up you'd have:
<VirtualHost *:80>
ServerName mylaravel.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/mylaravel/public
<Directory "/var/www/mylaravel/public">
Options All
AllowOverride All
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

I found something. I added Sadurnias code and run in Terminal
sudo a2enmod rewrite
sudo service apache2 restart
Of course I changed chmod of /var/www to 755.
It's working fine, only when I run mylaravel.com/css FireFox doesn't end this request, but others is fine.

Related

Laravel 7 - server only serving root page

I'm trying to serve a Laravel 7 site on my server, built using a Raspberry Pi and storing the files on an external hard drive.
I cloned my Laravel project from Github, ran composer install and after a bit of fiddling and configuration, the root page loaded. However, the root page is the only route that will load. Neither my own routes nor the auth routes generated by Laravel work. Any attempt to access a different route leads to a 404 error thrown by Apache on my server.
Here is my VirtualHost config file in Apache:
<VirtualHost *:80>
ServerName myurl.tld
ServerAdmin myemail#example.com
DocumentRoot /mnt/external/public_html/MyProject/public
<Directory /mnt/external/public_html/MyProject>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Not sure what is going on here. The same thing happens with projects generated on the server as well as the cloned project.
Permissions on /mnt/external/public_html/MyProject are set to 775 all the way up to external, and the whole path is owned by the www-data user.
Try the below VirtualHost config
<VirtualHost *:80>
ServerName myurl.tld
ServerAdmin myemail#example.com
DocumentRoot /mnt/external/public_html/MyProject/public
<Directory /mnt/external/public_html/MyProject/public>
AllowOverride All
Order Allow,Deny
Allow from all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Restart Apache.

How can I run my Laravel project without cmd command "php artisan serve"?

<VirtualHost *:80>
ServerAdmin webmaster#hujjaj.dev
DocumentRoot "C:\xampp\htdocs\hujjaj_app_new\public"
ServerName hujjaj.dev
ErrorLog "logs/hujjaj.dev-error.log"
CustomLog "logs/hujjaj.dev-access.log" common
I am doing so in my virtual host file and update 127.0.0.1 hujjaj.dev then i restart XAMPP and after that I navigate to localhost/hujjaj.dev but showing 404|Not Found.
Please try the following
<VirtualHost 127.0.0.2:80>
DocumentRoot “D:\laravel-gkb\public”
DirectoryIndex index.php
ServerName laravel-gkb.test
<Directory “D:\laravel-gkb\public”>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Allow from all
Require all granted
</Directory>
</VirtualHost>
Then add the save domain in your hosts file
127.0.0.2 hujjaj.dev
Refer this for more details : link
Yes, There is another way to run laravel project, with following command..
php -S 127.0.0.1:8001 server.php
This will run your application at 127.0.0.1:8001 mentioned address.
Note: laravel default entry point is server.php thats why we mentioned it. other wise it will be index.php

Laravel wrong view path

When i update a view file i get the view file from the old path.
I have a domain that points to an IP (vps) where i have a laravel installation.
lets call this 123.com and when i visit the domain i get the old view path, a path to the folder where i copied the laravel installation from.
This folder is nammed var/www/111.com/
After the copy i put the source in var/www/123.com/
When i acccess 123.com i get view files from var/www/111.com/ instead of var/www/123.com/
My .conf is like this in the sites-available i have restarted apache many times with sudo service apache2 restart no luck.
<VirtualHost *:80>
ServerName 123.com
ServerAlias www.123.com
ServerAdmin 123#123.com
DocumentRoot /var/www/123.com/public_html/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
The direect IP .conf looks like this.
<VirtualHost *:80>
ServerName 111.111.dk
DocumentRoot /var/www/111.111.dk/public/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/111.111.dk/public/>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Is the problem with my conf setup in apache2/vps?
I have removed the .conf file with sudo a2dissite 111.111.dk.conf and restarted with sudo /etc/init.d/apache2 force-reload no luck there.
I have also tried with
php artisan route:clear
php artisan view:clear
No luck there.
Kind regards.
I finaly figured it out, it was my config file in laravel, bootstrap/cache/config.php that had wrong paths.
so i ran php artisan config:cache and after that everything works :)
Thanks for all your help.
Try clearing the caches - via the terminal:
php artisan route:clear
php artisan view:clear

apache2.conf and httpd.conf

After reading ubuntu AMP community and Apache 2.4 configuration.
I was wondering if there is a way to imitate the same behavior of the http docs used in XAMPP or bitnami stacks but using the default LAMP. Which uses apache 2.4
In XAMP you would assign an extra number to your httpd-vhost.conf like this:
Listen *:9000
<virtualhost *:9000>
ServerName localhost
DocumentRoot "~/xamp/apache2/htdocs/html/app-name/"
</virtualhost>
<Directory "~/xamp/apache2/htdocs/html/app-name/">
Options Indexes FollowSymLinks
AllowOverride all
</Directory>
Then Edit your httpd.conf files like:
//....Some code..... */
<Directory>
AllowOverride all
<Directory />
//...Some code...
and uncomment this line:
//....Some code..... */
# Virtual hosts
include conf/extra/httpd-vhosts.conf
//...Some code...
My question is:
Is there is a way to configure Apache 2.4 just by dropping all my vhost's in one single file, without having to go through the process of configuring etc/apache2/sites-available and then adding names to etc/hosts?
Then completing the process by including some things like above just like Bitnami or Xamp stacks will do so your localhost will be able to serve not only static html files but an entire application's folder.
What works is the following in (for example) your 000-default.conf:
<VirtualHost *:80>
ServerName site1.vm
ServerAdmin webmaster#localhost
DocumentRoot /var/www/site1/web/
ErrorLog ${APACHE_LOG_DIR}/site1_error.log
CustomLog ${APACHE_LOG_DIR}/site1_access.log combined
<Directory /var/www/site1/web/>
Options All
AllowOverride All
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName site2.vm
ServerAdmin webmaster#localhost
DocumentRoot /var/www/site2/web/
ErrorLog ${APACHE_LOG_DIR}/site2_error.log
CustomLog ${APACHE_LOG_DIR}/site2_access.log combined
<Directory /var/www/site2/web/>
Options All
AllowOverride All
</Directory>
</VirtualHost>
This way all you have to do is add the site to the conf file, add the host to your hosts file, and reload apache2 service. Hope that is what you were looking for.

Virtual Host won't run Symfony2

I have Apache2 installed and I have this setup up on my virtual host pointing out to my symfony project.
<VirtualHost *:80>
ServerName topbesterp
ServerAlias www.topbesterp.tld
DocumentRoot /var/www/topbesterp/web/
<Directory /var/www/topbesterp/web/>
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
<Directory /var/www/topbesterp/web/>
Options FollowSymlinks
</Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>
I have added the codes up at the end of the apache2.conf.
And these are the things i added for hosts file
127.0.0.1 localhost
127.0.0.1 topbesterp
Whenever I run http://topbesterp on my browser, I receive a blank page.
But whenever I change the Directory of the virtual host to a project that is non-symfony based, it runs okay. Why?
Assuming that you're on LAMP environment so follow the steps below. If MAC then this.
1.
sudo nano /etc/apache2/sites-available/topbesterp.local.conf
<VirtualHost *:80>
ServerName topbesterp.local
ServerAlias www.topbesterp.local
ServerAdmin admin#topbesterp.local
DocumentRoot /var/www/topbesterp/web
<Directory /var/www/topbesterp/web/>
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/topbesterp.local.error.log
CustomLog ${APACHE_LOG_DIR}/topbesterp.local.access.log combined
</VirtualHost>
2.
sudo a2ensite topbesterp.local.conf
sudo service apache2 restart
3.
sudo nano /etc/hosts
127.0.0.1 topbesterp.local www.topbesterp.local
replace /var/www/topbesterp/web/
for
/var/www/topbesterp/web/app_dev.php
or
/var/www/topbesterp/web/app_dev.php
In fact, you don't specify a directory index in your virtual host, try this to get symfony2 first page (app_dev.php is used in development/app.php in production) :
<VirtualHost *:80>
ServerName topbesterp
ServerAlias www.topbesterp.tld
DocumentRoot /var/www/topbesterp/web
<Directory /var/www/topbesterp/web>
DirectoryIndex app_dev.php
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
<Directory /var/www/topbesterp/web/>
Options FollowSymlinks
</Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>
As per my comment, you would need to check app/logs/dev.log or app/logs/prod.logdepending on what environment you are running your application.
If you see some writing errors in the cache/logs folder, you'd need to set up the proper permissions to the app/cache/* and the app/logs/* folders.
Alternatively, you can add umask(0000); at the beginning of the following files:
app/console
web/app_dev.php
web/app.php
And you'd be good to go.

Categories