Category Archives: laravel

Why is "/public" still in the URL?

I have a folder structure like this:

.cpanel/ 
public_html/ 
public_ftp/ 
..

and a laravel project inside the public_html directory like this:

app/
bootstrap/
public/
vendor/
composer.json
artisan
..

The problem was that when I entered the url like www.example.com, it would redirect to www.example.com/public. I found a rewrite rule that allowed me to put in www.example.com and it would just show public/index.php without the "/public" part:

 RewriteEngine on 
 RewriteCond %{HTTP_HOST} ^(www.)?example.com$ 
 RewriteCond %{REQUEST_URI} !^/subfolder/ 
 RewriteCond %{REQUEST_FILENAME} !-f 
 RewriteCond %{REQUEST_FILENAME} !-d 
 RewriteRule ^(.*)$ /subfolder/$1 
 RewriteCond %{HTTP_HOST} ^(www.)?example.com$ 
 RewriteRule ^(/)?$ subfolder/index.php [L] 

It worked for the index page, but when I try to go to any of the routes, "/public" shows back up in the URL.

Why does this rewrite rule work for the index page and not for any of the routes? What rewrite rule will work for all of the pages to remove "/public" from the URL?

429 HTTP error during development on Xampp

I have read quite a bit about the 429 error and i understand why it occurs and what protection it provides, the problem is that i am working on an application and i am using xampp as my development server and this error has now occurred for the second time, it is really annoying as it halts my development process, the first time it occurred i had to wait for like 14 hours and this time around the retry-after header indicated that the rate limit will reset after 4 days. I have'nt been able to find an solution so far but there must be a workaround to this as it makes no sense to have this rate limiting feature on while working on a development server.

Any help would be appreciated. Thanx

A screenshot of the response.

Laravel 5.6 – permission denied on logs/laravel.log ubuntu xenial 16.04

Have visited topics on this before to no avail - struggling to get rid of a permissions error "Failed to open stream" on logs/laravel.log, the only thing that works at the moment is setting directory permissions to 777, that of course in a live server production environment is extremely bad practice.

I've followed practically every tutorial, like this one for example is the most recent I've come across:

https://vijayasankarn.wordpress.com/2017/02/04/securely-setting-file-permissions-for-laravel-framework/

and this

https://www.howtoforge.com/tutorial/install-laravel-on-ubuntu-for-apache/

Generally speaking, some checks I've carried out include checking ownership/groups by running

ps aux | egrep '(apache|httpd)'

which returns the following results

root      6723  0.0  0.4  77944  4880 ?        Ss   14:53   0:00 /usr/sbin/apache2 -k start
www-data  6726  0.0  0.6 432716  6708 ?        Sl   14:53   0:00 /usr/sbin/apache2 -k start
www-data  6727  0.0  0.6 432772  6696 ?        Sl   14:53   0:00 /usr/sbin/apache2 -k start
ubuntu    6874  0.0  0.0  12948   948 pts/0    S+   15:07   0:00 grep -E --color=auto (apache|httpd)

So I know my server is owned by www-data - even performing sudo chgrp changes such as ubuntu:www-data had no effect.

I had the same problem in local environment. On production, my blade template is practically rendered as raw text content as opposed to displaying the Laravel error page - assuming it's because the bootstrap/cache (which I've also modified permissions and ownership for) is being unable to be written to/partially written to.

I've also noted that a lot of tutorials mention bootstrap/cache being within the /storage folder but in newer Laravel versions this seems to have moved to /project-directory/bootstrap as opposed to /project-directory/storage/bootstrap etc.

I'm running Ubuntu Xenial 16.04 on an Amazon AWS instance.

Any help would be thoroughly appreciated.

how to go from http to https, certificate already installed and https is working

if someone directly enters www.myapp.com the browser will take them to http://www.myapp.com

myapp is configured to work with https so if we enter manually https://www.myapp.com then there are no problems laravel generates https urls correctly?

how do I get browser to go to https when user just enters www.myapp.com instead of browser taking them to the http?

Where is the most elegant place to make this happen?

Authorization header missing

I'm using Laravel Passport OAUTH 2.0 in my apps, and for that, I need to pass Authorization header in my requests.

It's working perfectly when using it locally, I can communicate between apps, I can use Postman to call a URL.

In production, I do passport:install, user:create, user:scope, etc. I use that token accordingly.

But everytime I get a 401 Unauthenticated, wheter I use Postman, or try to communicate between app.

I think that's an issue with the Apache server. I looked at other posts and tried to add in my .htaccess :

SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

or

RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

But nothing is working, the Authorization header is always missing.

What could be the reason ?

Apache/PHP/Win memory issues, two different systems + code. Same issue

I've been battling this problem for months now. I have two different systems each with different setups and PHP code but both have exactly the same problem.

My server will throw a 500 error and the logs will be filled with memory allocation issues until a restart of Apache.

System ONE

OS: Windows server 2008

XAMPP: PHP 7.1.9 / Apache 2.4.27

Codebase: A small laravel website nothing fancy

System TWO

OS: Windows server 2016

XAMPP: PHP 7.2.3.0 / Apache 2.4.29

Codebase: Some long running php processes, around 2min.

Apache Errors

VirtualFree() failed: [0x000001e7] Attempt to access invalid address. VirtualAlloc() failed: [0x00000008] Not enough storage is available to process this command. VirtualFree() failed: [0x000001e7] Attempt to access invalid address.

PHP Errors

[Mon May 21 09:27:42.078308 2018] [php7:error] [pid 10236:tid 12736] [client 43.245.8.13:1553] PHP Fatal error: Out of memory (allocated 2097152) (tried to allocate 6626884 bytes) in C:\xampp\htdocs\*\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOStatement.php on line 141, referer: http://m.facebook.com/

[Mon May 21 09:28:12.703338 2018] [php7:error] [pid 10236:tid 12736] [client 122.170.190.70:63513] PHP Fatal error: Out of memory (allocated 73400320) (tried to allocate 4096 bytes) in C:\xampp\htdocs\*\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php on line 294

[Mon May 21 09:28:14.640812 2018] [php7:error] [pid 10236:tid 12736] [client 122.170.190.70:63529] PHP Fatal error: Out of memory (allocated 37748736) (tried to allocate 4096 bytes) in C:\xampp\htdocs\*\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php on line 294

[Mon May 21 09:28:19.218972 2018] [php7:error] [pid 10236:tid 12736] [client 157.49.220.122:64984] PHP Fatal error: Out of memory (allocated 20971520) (tried to allocate 4096 bytes) in C:\xampp\htdocs\*\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Concerns\HasEvents.php on line 161, referer: https://www.facebook.com/

[Mon May 21 09:28:27.125182 2018] [php7:error] [pid 10236:tid 12704] [client 150.143.104.159:12178] PHP Fatal error: Out of memory (allocated 12582912) (tried to allocate 131072 bytes) in C:\xampp\htdocs\*\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOStatement.php on line 141

[Mon May 21 09:28:27.125182 2018] [php7:error] [pid 10236:tid 12704] [client 150.143.104.159:12178] PHP Fatal error: Out of memory (allocated 12582912) (tried to allocate 32768 bytes) in C:\xampp\htdocs\*\vendor\laravel\framework\src\Illuminate\Foundation\Exceptions\Handler.php on line 451

[Mon May 21 09:28:27.125182 2018] [php7:error] [pid 10236:tid 12704] [client 150.143.104.159:12178] PHP Fatal error: Out of memory (allocated 12582912) (tried to allocate 20480 bytes) in Unknown on line 0

What triggers the errors

The errors seem to occur randomly, but not straight away after an Apache restart. As if its hogging memory, however, I have 6GB of 8GB free on the server.

What I've tried so far

Various php.ini memory tweaks, eg memory_limit=1200M and also in script tweaks ini_set('memory_limit', -1);

Apache config tweaks

ThreadStackSize        56*1024*1024
ThreadsPerChild        150
MaxConnectionsPerChild   0
RLimitMEM 99999999999 99999999999999

However, I did notice after the restart it says

AH00118: RLimitMEM not supported on this platform

I've seen these errors scattered around the internet and no one ever seems to find a solution for them. I need PHP on Windows, I'm starting to think I should try IIS.

Are there any other recommendations on Apache config or what else I could try?

Apache/PHP/Win memory issues, two different systems + code. Same issue

I've been battling this problem for months now. I have two different systems each with different setups and PHP code but both have exactly the same problem.

My server will throw a 500 error and the logs will be filled with memory allocation issues until a restart of Apache.

System ONE

OS: Windows server 2008

XAMPP: PHP 7.1.9 / Apache 2.4.27

Codebase: A small laravel website nothing fancy

System TWO

OS: Windows server 2016

XAMPP: PHP 7.2.3.0 / Apache 2.4.29

Codebase: Some long running php processes, around 2min.

Apache Errors

VirtualFree() failed: [0x000001e7] Attempt to access invalid address. VirtualAlloc() failed: [0x00000008] Not enough storage is available to process this command. VirtualFree() failed: [0x000001e7] Attempt to access invalid address.

PHP Errors

[Mon May 21 09:27:42.078308 2018] [php7:error] [pid 10236:tid 12736] [client 43.245.8.13:1553] PHP Fatal error: Out of memory (allocated 2097152) (tried to allocate 6626884 bytes) in C:\xampp\htdocs\*\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOStatement.php on line 141, referer: http://m.facebook.com/

[Mon May 21 09:28:12.703338 2018] [php7:error] [pid 10236:tid 12736] [client 122.170.190.70:63513] PHP Fatal error: Out of memory (allocated 73400320) (tried to allocate 4096 bytes) in C:\xampp\htdocs\*\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php on line 294

[Mon May 21 09:28:14.640812 2018] [php7:error] [pid 10236:tid 12736] [client 122.170.190.70:63529] PHP Fatal error: Out of memory (allocated 37748736) (tried to allocate 4096 bytes) in C:\xampp\htdocs\*\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php on line 294

[Mon May 21 09:28:19.218972 2018] [php7:error] [pid 10236:tid 12736] [client 157.49.220.122:64984] PHP Fatal error: Out of memory (allocated 20971520) (tried to allocate 4096 bytes) in C:\xampp\htdocs\*\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Concerns\HasEvents.php on line 161, referer: https://www.facebook.com/

[Mon May 21 09:28:27.125182 2018] [php7:error] [pid 10236:tid 12704] [client 150.143.104.159:12178] PHP Fatal error: Out of memory (allocated 12582912) (tried to allocate 131072 bytes) in C:\xampp\htdocs\*\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOStatement.php on line 141

[Mon May 21 09:28:27.125182 2018] [php7:error] [pid 10236:tid 12704] [client 150.143.104.159:12178] PHP Fatal error: Out of memory (allocated 12582912) (tried to allocate 32768 bytes) in C:\xampp\htdocs\*\vendor\laravel\framework\src\Illuminate\Foundation\Exceptions\Handler.php on line 451

[Mon May 21 09:28:27.125182 2018] [php7:error] [pid 10236:tid 12704] [client 150.143.104.159:12178] PHP Fatal error: Out of memory (allocated 12582912) (tried to allocate 20480 bytes) in Unknown on line 0

What triggers the errors

The errors seem to occur randomly, but not straight away after an Apache restart. As if its hogging memory, however, I have 6GB of 8GB free on the server.

What I've tried so far

Various php.ini memory tweaks, eg memory_limit=1200M and also in script tweaks ini_set('memory_limit', -1);

Apache config tweaks

ThreadStackSize        56*1024*1024
ThreadsPerChild        150
MaxConnectionsPerChild   0
RLimitMEM 99999999999 99999999999999

However, I did notice after the restart it says

AH00118: RLimitMEM not supported on this platform

I've seen these errors scattered around the internet and no one ever seems to find a solution for them. I need PHP on Windows, I'm starting to think I should try IIS.

Are there any other recommendations on Apache config or what else I could try?

How to run codeigniter project inside a laravel project

I am currently creating a new application and trying to migrate from codeigniter to laravel, so I need to use the codeigniter session with laravel (which I already figure it out), but session require a project in the same domain. So I want to do something like this

domain.com - Laravel Project

domain.com/design - Codeigniter Project

How can I achieve this? I've been trying over and over but nothing come up to work, I ended up deleting both my apache.conf and .htaccess.

Any help would be appreciated.

Wrong paginate links after deployin Laravel app to shared host

I used ajax to Load pagination content in its frame. Everything was OK in Local host. For example in http://localhost:8000/exampleroute pagination link for comments section , page 2 is: http://localhost:8000/content/page_comments?page=2 and works well.

But in shared host is: https://example.com/content/page_comments?%2Fexampleroute=&page=2 and links not work. I guess the problem is related to .htaccess file. so .htaccess contents here:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
  ErrorDocument 404 /index.php
</IfModule>

What is base problem?