Linux server, laravel problem with configuration - php

currently I am setting up a new server based on linux, installed apache2, MySQL, phpmyadmin and etc.
Installed my Laravel project with git, and all seems to be working well except some request that are made to the server.
Currently my folder structure for /var/www/ is:
-/var/www
--- /home
--- /laravel
When the user accesses the server through http://server.xxxxxxx.com/ is redirected to /home where there is a landing page, basically a face for the web-app.
When the user goes to http://server.xxxxxxx.com/erp/, he is redirected to the /laravel/public directory.
All loads well, the application is running perfectly, but AJAX request fail everywhere.
Every AJAX request ends with an error. For example:
The requested URL /pie-data was not found on this server
I have tried all the things I could find for this URL problem in the net, but nothing really seemed to have helped. One thing that helped, was to edit the apache config, where I had made an Alias for "/" to redirect to /var/www/laravel/public folder. But this is not a solution for me, because, that way I cannot access phpmyadmin.
Routes in my web.php file:
Route::get('/', 'DashboardController#index');
Route::get('/dashboard', 'DashboardController#index')->name('dashboard');
Route::get('/set-warehouse', 'DashboardController#setWarehouse');
Route::get('/pie-data', 'DashboardController#getDonutData');
Route::get('/mechanics-load', 'DashboardController#mechanicsWorkLoad');
Route::get('/monthly-load', 'DashboardController#monthlyLoad');
Route::get('/change-date-mechanics', 'DashboardController#changeMechanicsWorkLoad');
One of the AJAX requests:
$.ajax({
url: '/pie-data',
method: 'GET',
success: function (data) {
if (data.type === 'success') {
pieChart.Doughnut(data.data, pieOptions);
$('canvas[id="pieChart"]').empty().after(data.legend);
}
},
});
000-default.conf file:
<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 server.xxxxxxx.com
ServerAdmin somemail#gmail.com
DocumentRoot /var/www/home/
# 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
Alias /erp "/var/www/laravel/public/"
<Directory "/var/www/laravel/public/">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
The .htaccess file is standard for Laravel 5.8, it is not changed at all.
When the user is in http://server.xxxxxxx.com/erp/dashboard, 4 or more AJAX calls are made, but not to http://server.xxxxxxx.com/erp/pie-chart (which will return a JSON for the plugin), but are made to http://server.xxxxxxx.com/pie-chart. Is there any way to fix this functionality, without changing the folder structure? Thank you in advance for the replies!

Your ajax request is attempting to GET /pie-data, more specifically (/var/www/home/pie-data) when it looks like you want /erp/pie-data

Related

Laravel Site in Folder of Another Laravel Site .htaccess?

I'm trying to find the best way to go about this so I'd appreciate any help. I've got a primary Laravel site in my /var/www/html folder. This pretty much handles everything but I need to add another project for a specific task and would like to add it under /var/www/html/wrettin. At the moment, I don't have anything in the base folder's .htaccess as it is all pretty much handled through the default.conf file of the Apache2 server.
Here is the conf file:
<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#me
DocumentRoot /var/www/html/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
<Directory /var/www/html/public/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
What would be the appropriate configuration in order to keep all paths going to the primary application while forcing those that go to the wrettin path to be redirected to the new application?
I'd appreciate any and all help! Thanks!

First time working with Apache, can't seem to setup two sites

First time setting up an Apache2 server with Ubuntu 16.04 LTS Server. I got one site working which I was quite happy with.
Now I want to create a 2nd site on the same server and access them via internalIP/site1 and internalIP/site2
I created the directory for the 2nd site: /var/www/html/site2 and created a .conf file named 001-default.conf in /etc/apache2/sites-available/and then and put in:
<VirtualHost *:80>
DocumentRoot "/var/www/html/site2/"
ServerName site2
</VirtualHost>
Then used sudo a2ensite site2 to enable it.
The .conf file in sites/available of my site1 is /etc/apache2/sites-available/000-default.conf and looks like this:
<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
ServerName support
ServerAlias support
DocumentRoot /var/www/html/osticket/
# 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
Now the weird (to me) thing is that whenever I go to my internal IP of the server I instantly land on Site1. Maybe I changed some configuration related to this but I can't recall...I know I had to go to InternalIP/osticket (name of site1) to access it before. I can't manage to access site2 by internalIP/site2 or anything like that. I get a 404 not found error.
Keep in mind this is my first time and im trying my best to learn and provide enough information, thanks so much.
Now the weird (to me) thing is that whenever I go to my internal IP of the server I instantly land on Site1.
This is normal. The default site is the one defined first. If you don't access the site via a hostname that the server knows about, you get the first one.
I can't manage to access site2 by internalIP/site2
That's because /var/www/html/osticket/site2 doesn't exist.
You need to access http://site2/ instead of http://192.168.1.123/site2/
You are using Virtual Name Hosting. You need to use the Name.
(I made up an IP address for the sake of example).

Slim 2.6.2 render() Only Works for Index.html

I'm currently learning about the Slim framework over at TeamTreehouse.com, and ran into an issue that I haven't been able to resolve.
At this point in the project, we have installed Slim via Composer and setup .htaccess and index.php files in our document root (which on my computer is /home/daniel/src/public_html/treehouse/build_websites_php/).
In a templates folder we have index.html and contact.html. Here is the layout of the folders.
DocumentRoot (/home/daniel/src/public_html/treehouse/build_websites_php/)
index.php
.htaccess
composer.json
composer.lock
vendor/
templates/
index.html
contact.html
In index.php, I instantiate a new Slim object:
$app = new \Slim\Slim();
And then call the get() method and then call render() to render the index.html and contact.html pages when the url is localhost/treehouse/build_websites/ and localhost/treehouse/build_websites/contact, respectively.
$app->get('/', function () use($app) {
$app->render('index.html');
});
$app->get('/contact', function () use($app) {
$app->render('contact.html');
});
Then run the app:
$app->run();
My index.html page shows up fine, but I get a 404 error (not through Slim, just the server's default) when I try and visit the /contact url. Here are some specs from my system:
Ubuntu 16.04.1 LTS
Apache 2.4.18
Slim 2.6.2
PHP 7.0.8
Anything in my /home/daniel/src/public_html/ directory can be accessed by Apache, as I've run PHP scripts from in there for the past year.
I've tried the suggestions from here (and restarted the server after each update to conf.d or other files) and have had no luck.
Any help would be greatly appreciated, I've only been using PHP/Ubuntu/Apache for about a year, so I'm probably missing something obvious!
Here is the index.php file:
<?php
require 'vendor/autoload.php';
$app = new \Slim\Slim();
$app->get('/', function () use($app) {
/* When using render(), the url localhost/treehouse/build_websites_php/ to
gets you the home page. */
$app->render('index.html');
});
/* This SHOULD bring up the contact page at url
localhost/treehouse/build_websites_php/contact, but it doesn't! */
$app->get('/contact', function () use($app) {
$app->render('contact.html');
});
$app->run();
?>
Here is the .htacess file:
RewriteEngine On
# Some hosts may require you to use the `RewriteBase` directive.
# If you need to use the `RewriteBase` directive, it should be the
# absolute physical path to the directory that contains this htaccess file.
#
# RewriteBase /home/daniel/src/public_html/treehouse/build_websites_php/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
And here are various conf.d files for Apache:
/etc/apache2/apache2.conf
# Sets the default security model of the Apache2 HTTPD server. It does
# not allow access to the root filesystem outside of /usr/share and /var/www.
# The former is used by web applications packaged in Debian,
# the latter may be used for local directories served by the web server. If
# your system is serving content from a sub-directory in /srv you must allow
# access here, or in any related virtual host.
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /home/daniel/src/public_html>
Order allow,deny
Allow from all
Require all granted
</Directory>
I tried adding AllowOverride All as suggested here to the last directive and then I wasn't able to access PHP files from the server at all and got a 500 error instead of a 404 error.
/etc/apache2/sites-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
# 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
/etc/apache2/sites-available/mysite.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 /home/daniel/src/public_html
# 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
OK wow I finally figured it out thanks to Mika pointing me in the right direction. It turns out, my /etc/apache2/sites-available/mysite.conf file needed the following directive:
<Directory /home/daniel/src/public_html >
AllowOverride All
</Directory>
I had tried adding that directive to /etc/apache2/apache2.conf in addition to the other directives like so:
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /home/daniel/src/public_html>
Order allow,deny
Allow from all
Require all granted
AllowOverride All #THIS DIDN'T WORK
</Directory>
But the AllowOverride All from above through a 500 error from the server. Apparently, it had to be by itself in the /etc/apache2/sites-available/mysite.conf file, who knew!
I also ran sudo a2enmod rewrite && sudo /etc/init.d/apache2 restart to make sure the mod_rewrite was loaded after discovering this error message (thanks to Mika for pointing out to check the log files!):
[Sun Nov 13 10:37:51.054347 2016] [core:alert] [pid 10979] [client ::1:51900] /home/daniel/src/public_html /treehouse/build_websites_php/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
I did that before adding the AllowOverride All directive, so I'm not sure if it played a part in solving the problem, but I figured I would document it for any interested.
These sites had valuable information on how to finally solve the issue:
1 - solved mod_rewrite issue
2 - solved where to place the AllowOverride All directive
3 - Slim troubleshooting for .htaccess
It looks like your Apache settings do not allow the .htaccess file to override any settings. Add something like the following to apache2.conf.
<Directory /home/daniel/src/public_html>
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>

Laravel project on ubuntu server :HTTP ERROR 500

My laravel project works fine in development machine, but when i uploaded to ubuntu server i will get HTTP ERROR 500.
Here is things i've done.
1.Uploaded the entire contents of <laravel_project> folder into the var\www\html folder.
when i try to access domain.com i will get the list of directories instead of home page,when entering on public folder i will get HTTP ERROR 500 error.
Also how can get the index page without accessing the public folder (ie i need to enter to my site while entering domain.com ) .
There can be multiple cases
Please check you can storage write permission to storage folder
You need to define path to public in your apache configuration to be able to open without public
Server does not meet the minimum requirements of Laravel
Please try above and let me know
You have to change Document root directory in apache configure file.
File Location in Ubuntu Server is :
1) $ cd /etc/apache2/sites-available 2) $ gedit 000-default.conf
Find the default Directory Root and modify it with your project_directory / public_directory.
i.e. DocumentRoot /var/www/html/project_dir/public/
See this code for referance :
<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/project_dir/public_dir
# 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
After edit this file. Reload apache server once.
sudo service apache2 reload

apache virtual host with laravel 5 "Internal error 500"

I want to learn laravel, and recently installed a fresh copy laravel on an amazon ec2 instance through composer composer create-project laravel/laravel laravel-app with apache2, and php installed. I configure the conf.d file to change the document root to laravel-folder/public, when i try to go to the public ip address it show a server 500 error.
<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.
#elastic IP address
ServerName 42.66.33.52
ServerAdmin webmaster#localhost
DocumentRoot laravel-app/public
<Directory laravel-app/public>
DirectoryIndex index.php
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride All
Order allow,deny
Allow from 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
LogLevel warn
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
I've tried chmod 777 to the entire laravel folder and changed the url in app.php to 42.66.33.52, and it still showing the same error. I'm new to laravel, and I hope someone can point me to the right direction. I've host other PHP website from this server without using laravel framework and it is function normally.
You should chmod -R 775 on /storage folder and all files in it.
as #Alexey Mezenin said, you should change the chmod of storage and all files inside by -R, and also don't forget to do the same with the bootstrap/cache folder. Check that on "Directory Permissions" in the official laravel documentation installation :
https://laravel.com/docs/5.3/installation
hope that help ;) Regards.

Categories