Elastic Beanstalk environment variables are not reading/loading in Lumen application
I have deploy my lumen application v8.3.0 on Elastic Beanstalk, But I try to load the envoirnment variables frim Elastic Beanstalk properties then array is empty and no variable is loaded. Event I have try to load by using different packages i.e vlucas/phpdotenv and also use $_SERVER,$_ENV and getenv("APP_KEY"). I am stuck to debug this problem either it is AWS side issue or code level.
AWS Elastic Beanstalk
PHP 8.0 running on 64bit Amazon Linux 2/3.3.9
Lumen v8.3
"require": {
"php": "^8.0",
"dusterio/lumen-passport": "^0.3.4",
"elasticsearch/elasticsearch": "6.*",
"illuminate/redis": "^8.79",
"laravel/lumen-framework": "^8.3.1",
"league/flysystem-aws-s3-v3": "^3.0",
"league/fractal": "^0.19.2",
"pearl/lumen-request-validate": "^1.6",
"predis/predis": "^1.1",
"ramsey/uuid": "^4.2",
"tzsk/collage": "^5.1"
},
do you know?
how many words do you know
See also questions close to this topic
-
How to upload a video using ACF in WordPress?
I am still at learning phase in WordPress. I cannot figure out in ACF which field type should I choose to upload a video file and which code should I write to show it at the front-end. Please look into the below code. I am using the_field('') but it isn't working. Can anyone help
<video width="954" height="535" controls class="tm-mb-40"> <source src="video/wheat-field.mp4" type="video/mp4"> Your browser does not support the video tag. </video>
-
delete a table form a database using laravel command
i need to delete a database table using laravel artisan command . not like this command php artisan migrate:rollback --step=5
i need to create like this route or controller code .
Route::get('/clear/database', function () {
Artisan::call('cache:clear'); return redirect('/');
});
. i also try public function dd()
{ Schema::drop('table_name'); }
but it not working . gives me error like this SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (SQL: drop table
table_name
)no foreign key for the table . what should i do ?
thanks in advance!
-
Creating Sticky Navbar with Drop Down Menu HTML
I am creating a HTML web page which contains a sticky navbar with drop down menu. However, when I created one, the dropdown menu does not works in the sticky navbar and so goes vise versa. below is the screenshot of both the result of the two codes.
*image with dropdown menu but without sticky navbar
*image with sticky navbar but without dropdown menu
below is the code for "image with dropdown menu but without sticky navbar"
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font- awesome/4.7.0/css/font-awesome.min.css"> <style> body {margin:0;font-family:Arial} .topnav { overflow: hidden; background-color: #333; } .topnav a { list-style-type: none; float: left; display: block; color: #f2f2f2; text-align: center; padding: 14px 16px; text-decoration: none; font-size: 17px; position: sticky; } .active { background-color: #04AA6D; color: white; } .topnav .icon { display: none; } .dropdown { float: left; overflow: hidden; } .dropdown .dropbtn { font-size: 17px; border: none; outline: none; color: white; padding: 14px 16px; background-color: inherit; font-family: inherit; margin: 0; } .dropdown-content { display: none; position: absolute; background-color: #f9f9f9; min-width: 160px; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); z-index: 1; } .dropdown-content a { float: none; color: black; padding: 12px 16px; text-decoration: none; display: block; text-align: left; } .topnav a:hover, .dropdown:hover .dropbtn { background-color: #555; color: white; } .dropdown-content a:hover { background-color: #ddd; color: black; } .dropdown:hover .dropdown-content { display: block; } @media screen and (max-width: 600px) { .topnav a:not(:first-child), .dropdown .dropbtn { display: none; } .topnav a.icon { float: right; display: block; } } @media screen and (max-width: 600px) { .topnav.responsive {position: relative;} .topnav.responsive .icon { position: absolute; right: 0; top: 0; } .topnav.responsive a { float: none; display: block; text-align: left; } .topnav.responsive .dropdown {float: none;} .topnav.responsive .dropdown-content {position: relative;} .topnav.responsive .dropdown .dropbtn { display: block; width: 100%; text-align: left; } } </style> </head> <body> <div class="header"> <h2>Scroll Down</h2> <p>Scroll down to see the sticky effect.</p> </div> <div class="topnav" id="myTopnav"> <a href="#home" class="active">Home</a> <a href="#news">News</a> <a href="#contact">Contact</a> <div class="dropdown"> <button class="dropbtn">Dropdown <i class="fa fa-caret-down"></i> </button> <div class="dropdown-content"> <a href="#">Link 1</a> <a href="#">Link 2</a> <a href="#">Link 3</a> </div> </div> <a href="#about">About</a> <a href="javascript:void(0);" style="font-size:15px;" class="icon" onclick="myFunction()">☰</a> </div> <div style="padding-left:16px"> <h2>Responsive Topnav with Dropdown</h2> <p>Resize the browser window to see how it works.</p> <p>Hover over the dropdown button to open the dropdown menu.</p> </div> <h3>Sticky Navigation Bar Example</h3> <p>The navbar will <strong>stick</strong> to the top when you reach its scroll position.</p> <p><strong>Note:</strong> Internet Explorer do not support sticky positioning and Safari requires a -webkit- prefix.</p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <script> function myFunction() { var x = document.getElementById("myTopnav"); if (x.className === "topnav") { x.className += " responsive"; } else { x.className = "topnav"; } } </script> </body> </html>
below is the code for "image with sticky navbar but without dropdown menu"
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font- awesome/4.7.0/css/font-awesome.min.css"> <style> body { font-size: 20px; } body {margin:0;} ul { list-style-type: none; margin: 0; padding: 0; overflow: hidden; background-color: #333; position: -webkit-sticky; /* Safari */ position: sticky; top: 0; } li { float: left; } li a { display: block; color: white; text-align: center; padding: 16px 20px; text-decoration: none; } li a:hover { background-color: #111; } /*======================================================================*/ body { background-color:white; } ul { list-style-type: none; margin: 0; padding: 0; overflow: hidden; background-color: #38444d; } li { float: left; } li a, .dropbtn { display: inline-block; color: white; text-align: center; padding: 14px 16px; text-decoration: none; } li a:hover, .dropdown:hover .dropbtn { background-color: red; } li.dropdown { display: inline-block; } .dropdown-content { display: none; position: absolute; background-color: #f9f9f9; min-width: 160px; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); z-index: 1; } .dropdown-content a { color: black; padding: 12px 16px; text-decoration: none; display: block; text-align: left; } .dropdown-content a:hover {background-color: #f1f1f1;} .dropdown:hover .dropdown-content { display: block; } footer { text-align: center; padding: 3px; background-color: DarkSalmon; color: white; } </style> </head> <body> <div class="header"> <h2>Scroll Down</h2> <p>Scroll down to see the sticky effect.</p> </div> <ul> <li><a href="#home">Home</a></li> <li><a href="#news">News</a></li> <li class="dropdown"> <a href="javascript:void(1)" class="dropbtn">Dropdown</a> <div class="dropdown-content"> <a href="#">Link 1</a> <a href="#">Link 2</a> <a href="#">Link 3</a> </div> </li> </ul> <h3>Sticky Navigation Bar Example</h3> <p>The navbar will <strong>stick</strong> to the top when you reach its scroll position.</p> <p><strong>Note:</strong> Internet Explorer do not support sticky positioning and Safari requires a -webkit- prefix.</p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <footer> <p>Author: Hege Refsnes<br> <a href="mailto:hege@example.com">hege@example.com</a></p> </footer> </body> </html>
Please i need some help with this as i am new to html and css.
-
Foreach for Categories
i have this data, I want to loop with categories for each question. Right now all I can do is loop by displaying sequentially for each question (as in the image).what I want to do is loop and group them based on categories_id , if the categories_id changes it will be given a new line.
// 20220507095412 // http://127.0.0.1:8000/user/exams [ { "id": 16, "ujians_id": 11, "questions_id": 3, "mulai": null, "berakhir": null, "durasi": 60, "isAnswer": 0, "created_at": "2022-05-07T02:53:56.000000Z", "updated_at": "2022-05-07T02:53:56.000000Z", "questions": { "id": 3, "title": "2", "question": "<p>Sarana yang sangat masih dalam menyebabkan oposisi dunia yang sering berdampak pada intervensi asing terhadap Indonesia pada era globalisasi sekarang ini adalah...</p>", "img": null, "categories_id": 1, "created_at": "2022-05-07T02:11:41.000000Z", "updated_at": "2022-05-07T02:11:41.000000Z" } }, { "id": 17, "ujians_id": 11, "questions_id": 1, "mulai": null, "berakhir": null, "durasi": 60, "isAnswer": 0, "created_at": "2022-05-07T02:53:56.000000Z", "updated_at": "2022-05-07T02:53:56.000000Z", "questions": { "id": 1, "title": "13", "question": "<p>Wahidin soedirohoesodo memilik peran penting dalam pergerakan kemerdekaan. Antara lain…22234232</p>", "img": null, "categories_id": 1, "created_at": "2022-05-02T10:39:13.000000Z", "updated_at": "2022-05-03T13:28:24.000000Z" } } ]
@php $no=1 @endphp @foreach($dataUjian as $row) @if($row->isAnswer == 0) <button class="btn btn-primary btn-sm" onclick="getUjian({{$row->questions_id}}, {{$row->id}},{{$row->ujians->users_id}})" >{{$no++}}</button> @else <button class="btn btn-danger btn-sm" disabled>{{$no++}}</button> @endif @endforeach
-
Unit testing with get request
I am trying to create a unit test for one of my api.
In the frontend, I send it this way...
params = { participants: JSON.stringify(participants), section: JSON.stringify(section), }; axios.get('/api/list', params)
while in the controller, it receives the params this way...
public function list(Request $request) { $participants = json_decode($request->participants); $section = json_decode($request->section); }
Now, I tried making a unit test out of this. by doing...
$params = [ 'participants' => ['id', 'name', 'rating'], 'section' => ['id', 'code'], ]; $this->get('/api/list'.http_build_query($params))->assertStatus(200) // $this->json('/api/list', $params)->assertStatus(200) // -> also tried this one // $this->getJson('/api/list', $params)->assertStatus(200) // -> also tried this one // $this->call('GET', '/api/list', $params)->assertStatus(200) // -> also tried this one
But none of them works, it always says
TypeError: json_decode(): Argument #1 ($json) must be of type string, array given
.So, the way I built the url and the params must be all wrong,
so my question here is that, what's the correct way of building the url so that it provides a correct url string format and the controller will json_decode the params?
-
Elasticbeanstalk - Nginx "connect() to unix:/run/php-fpm/www.sock failed"
My
x_optimize_php.sh
file is below#!/bin/bash # This file will make sure that will set the max processes and spare processes # according to the details provided by this machine instance. DEFAULT_PROCESS_MEMORY="120" MAX_REQUESTS="500" PROCESS_MAX_MB=$(ps --no-headers -o "rss,cmd" -C php-fpm | awk '{ sum+=$1 } END { printf ("%d\n", sum/NR/1024) }') || $DEFAULT_PROCESS_MEMORY VCPU_CORES=$(($(lscpu | awk '/^CPU\(s\)/{ print $2 }'))) TOTAL_MEMORY_IN_KB=$(free | awk '/^Mem:/{print $2}') USED_MEMORY_IN_KB=$(free | awk '/^Mem:/{print $3}') FREE_MEMORY_IN_KB=$(free | awk '/^Mem:/{print $4}') TOTAL_MEMORY_IN_MB=$(($TOTAL_MEMORY_IN_KB / 1024)) USED_MEMORY_IN_MB=$(($USED_MEMORY_IN_KB / 1024)) FREE_MEMORY_IN_MB=$(($FREE_MEMORY_IN_KB / 1024)) MAX_CHILDREN=$(($FREE_MEMORY_IN_MB / $PROCESS_MAX_MB)) # Optimal would be to have at least 1/4th of the children filled with children waiting to serve requests. START_SERVERS=$(($MAX_CHILDREN / 4)) MIN_SPARE_SERVERS=$(($MAX_CHILDREN / 4)) # Optimal would be to have at most 3/4ths of the children filled with children waiting to serve requests. MAX_SPARE_SERVERS=$(((3 * $MAX_CHILDREN) / 4)) sudo sed -i "s|pm.max_children.*|pm.max_children = $MAX_CHILDREN|g" /etc/php-fpm.d/www.conf sudo sed -i "s|pm.start_servers.*|pm.start_servers = $START_SERVERS|g" /etc/php-fpm.d/www.conf sudo sed -i "s|pm.min_spare_servers.*|pm.min_spare_servers = $MIN_SPARE_SERVERS|g" /etc/php-fpm.d/www.conf sudo sed -i "s|pm.max_spare_servers.*|pm.max_spare_servers = $MAX_SPARE_SERVERS|g" /etc/php-fpm.d/www.conf printf "\npm.max_requests = $MAX_REQUESTS" | sudo tee -a /etc/php-fpm.d/www.conf # Restarting the services afterwards. sudo systemctl restart php-fpm.service sudo systemctl restart nginx.service
And it returns error below, suddenly. My server was working with no errors more than 1 year. And today, It begins to return error like below.
2022/05/06 13:21:54 [error] 4460#4460: *3393 connect() to unix:/run/php-fpm/www.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: #, server: , request: "GET /api/product/blabla HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/www.sock:", host: "blabla"
Whats wrong with it? I've tried everything, restarted server etc. And when I rebuild server, after 2 minutes, It returns error like that.
On monitoring my ebs environment; there looks no 'load'. it uses %5 of cpu. What could be wrong? what should I do?
-
AWS beanstalk Amazon Linux 2 log file permissions
I'm migrated from AL1 to AL2 on AWS Beanstalk. AL2 changed location of my nodejs.log to
/var/log/{{.}}.stdout.log
I resolved this by adding ryslog.config to .ebexetensions:files: "/opt/elasticbeanstalk/config/private/rsyslog.conf.template": mode: "000644" owner: root group: root content: | # This rsyslog file redirects Elastic Beanstalk platform logs. # Logs are initially sent to syslog, but we also want to divide # stdout and stderr into separate log files. template(name="SimpleFormat" type="string" string="%msg%\n") $EscapeControlCharactersOnReceive off {{range .ProcessNames}}if $programname == '{{.}}' then { *.=warning;*.=err;*.=crit;*.=alert;*.=emerg /var/log/nodejs/nodejs.log; SimpleFormat *.=info;*.=notice /var/log/nodejs/nodejs.log; SimpleFormat } {{end}}
Above configuration is working but I have problem with log file permissions. Directory /var/log/nodejs and nodejs.log file are only readable by root (chmod 600), and cloudwatch-agent can't read it. Changing permissions manually do the job, but how can I change the permissions to be created automatically on beanstalk deploy?
-
Add same message and notification to multiple user ids in database without using multiple arrays of data, instead use only the array of user ids
I know that to insert data in mysql, I can utilize 3 different methods for multiple entries, efficient one being:
INSERT INTO TABLE(
COLUMN1,
COLUMN2,
COLUMN3`) VALUES('ID1', 'SAME TITLE', 'SAME MESSAGE'),
('ID2', 'SAME TITLE', 'SAME MESSAGE'),
('ID3', 'SAME TITLE', 'SAME MESSAGE'),
.......
('ID1000000', 'SAME TITLE', 'SAME MESSAGE');
But this query will also take a long time while my other queries will also be executing on the server, where some of my queries take 3-4 seconds to return data on a average online user base of 10000. So, is there a way to write a query in such a way that for all the rows, I don't need to pass the SAME TITLE and SAME MESSAGE and it only needs the array of user ids which I can send in chunks of suppose 10k or 20k at a time, which may reduce the overall data size sent to the RDS.
Please suggest. I may sound hypothetical, as I also have not seen such before, but looking for any optimization possibility to any extent.
-
Lumen unusual return value only when tried in Android (Kotlin)
I have a problem about unusual return in my lumen app version 7.
My teammate who is using kotlin in his android try to execute my api with case task_id and id is correctly inputed, he always got
["success" => false, "message" => "File Bukan Milik Task", "status" => 400]
If he got that response, It shouldn't execute the code below, but the targeted file was deleted and file in my digital ocean space was also deleted so the code below the return was executed. And also, with case task_id and id correctly inputed, the above return was not supposed to be hit. But it was been hit and the below code also hit. In the mean time, every time i tried this api in postman, It worked normally. with output :
return ["success" => true, "message" => "Berhasil Menghapus File", "status" => 200];
This is my deleteFileTask function api code
public function deleteFileTask(Request $request) { try{ $task_id = $request->get('task_id', null); $id = $request->get('id', null); $task = Task::with('attachments')->find($task_id); if($task === null) return ["success" => false, "message" => "Id Task Tidak Ditemukan", "status" => 400]; $search = $task->attachments->search(function ($item) use ($id) { return $item->id == $id; }); if($search === false) return ["success" => false, "message" => "File Bukan Milik Task", "status" => 400]; $fileService = new FileService; $delete_file_response = $fileService->deleteFile($id); if($delete_file_response['success']) return ["success" => true, "message" => "Berhasil Menghapus File", "status" => 200]; else return ["success" => false, "message" => $delete_file_response['message'], "status" => 400]; } catch(Exception $err){ return ["success" => false, "message" => $err, "status" => 400]; } }
This is my deleteFile function in FileService class
public function deleteFile($id) { $file = File::find($id); if($file === null) return ["success" => false, "message" => "File Tidak Ditemukan"]; $set_private = Storage::disk('do')->setVisibility($file->link, 'private'); if(!$set_private) return ["success" => false, "message" => "File Gagal Didelete dari Space"]; $file->delete(); $purge_response = $this->purgeLink($file->link); if(!$purge_response) return ["success" => false, "message" => "Gagal Purge Data"]; return ["success" => true]; }
Anyone know what the cause is?
-
How to generate a user referral link in lumen
I am new to Laravel Lumen and I would like to create a referral link api for my project.
I would like to know is it possible to generate a referral link when an user register an account in lumen ?
After the users registered they can share the referral to their friends/family and whoever clicked on the link it will send them to register.
-
Laravel Loggin send email with monolog NativeMailerHandler
I'm trying to use a laravel logging channel to send an email with the error, but I can't get anything to be sent, I'm trying with monolog and NativeMailerHandler but I still can't send anything, Laravel 8 and php 7.4:
config/logging.php
'driver' => 'monolog', 'handler' =>\Monolog\Handler\NativeMailerHandler::class, 'level' => 'debug', 'with' => [ 'to' => 'to@to.com', 'from' => 'noreplay@from.com', 'subject' => 'test', 'level' => 'debug' ],
Call from a controller
Log::channel('monologmail')->debug('test');
In the .env i have the mails settings:
MAIL_MAILER=smtp MAIL_HOST=smtp.gmail.com MAIL_PORT=465 MAIL_USERNAME=noreplay@from.com MAIL_PASSWORD=password MAIL_ENCRYPTION=ssl MAIL_FROM_ADDRESS=noreplay@from.com
It simply does not send any message, nor does it give any error or anything...