How to make composer packages global - composer-php

After creating a few duplicate snipe it installations I think it's better to move installed composer packages to a global location (so I won't have to download/install them each time I create a new snipe it instance). How and where should I put these ? Already moved composer to /usr/local/bin . Ultimate goal is to remove the packages from the vendor subfolders and load them from global location. What would need to be changed in the snipe it folders ?
Thanks
Running Ubuntu server 20.04
What I did was:
copy site1 to site2
create db for site2
add extra ip in apache ports.conf to listen on
add ip in netplan yaml file
create new ssl key for extra ip
created conf for site2 in sites-available + a2ensite
modified .env for url app key en db settings
My main problem is that php artisan key:generate throws an error when in root of site2. Was able to generate app key with echo "base64:$(openssl rand -base64 32)" and site2 works as it shoulds for now.

Related

How to run laravel websockets in laragon?

How to run laravel websockets in laragon?
when run command to start websockets
php artisan websockets:serve
it's not working because
https://imgur.com/ODkZC8d
and its still suck there
https://imgur.com/6lzEOGX
this is error on browser
WebSocket connection to 'wss://nextlevelbot.test:6001/app/mykey?protocol=7&client=js&version=6.0.2&flash=false' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
It was my problem in SSL certifacates
I solve this problem by create SSL certificates for nextlevelbot.test and add them in folder in this path
C:\laragon\etc\ssl\nextlevelbot.test
and add path SSL certificates in .env file
LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT =C:\laragon\etc\ssl\nextlevelbot.test\server.crt
LARAVEL_WEBSOCKETS_SSL_LOCAL_PK =C:\laragon\etc\ssl\nextlevelbot.test\server.key
and edit path SSL certificates in config file for my project in this path
C:\laragon\etc\nginx\sites-enabled\auto.nextlevelbot.test.conf
ssl_certificate "C:/laragon/etc/ssl/nextlevelbot.test/server.crt";
ssl_certificate_key "C:/laragon/etc/ssl/nextlevelbot.test/server.key";
and restart nginx server in laragon
and run command composer dumpautoload
after that run command php artisan websockets:serve
after that work good :)
Generate certificates for domain
I generate certificates by this scripts
https://gist.github.com/mindscms/721cf0968ddbbff5bad0c0b359d918e6
https://gist.github.com/mindscms/a7f3e7db0b6c7bfaaab56522ebed9042
1 - Download two files make-cert.bat and cert-template.conf from link above
2 - Create folder cert in C:\laragon\bin\apache\YOUR_VIRSION_APACHE
in my case C:\laragon\bin\apache\httpd-2.4.35-win64-VC15\cert
3 - Put two file make-cert.bat and cert-template.conf in folder cert
4 - Run file make-cert.bat and answer the questions to generate certificates
5 - After finished script creates a folder with the name domain likenextlevelbot.test
C:\laragon\bin\apache\httpd-2.4.35-win64-VC15\cert\nextlevelbot.test
6 - Inside this folder two files server.crt and server.key
That was helpful but not the exact reason
as this is a local cert, it needs permission
The easiest way ( oh its quirky )
Copy the failing wss link
i.e. wss://example.test:3031/app/?protocol=7&client=js&version=4.3.1&flash=false
and replace the wss:// with https://
i.e.
https://example.test:3031/app/?protocol=7&client=js&version=4.3.1&flash=false
Open the link on another tab of same browser and accept the certification on ssl prompt
try the websockets dashboard now, refresh and voila!
By the way, if you make any change to your nginx config for domain in laragon, you should remove the auto. prefix to avoid future auto overwrite by laragon

How to run a Laravel project that is downloaded from a cPanel?

SOLVED: My machine didn't have MySQL installed and was having a hard time installing it and I still do.
I recently downloaded a Laravel project from cPanel and I wish to work on it. But when I try to run the project I get "500 server error".
After searching on Google, I tried the following steps
composer update --no-scripts
php artisan key:generate
php artisan migrate
This does not seem to be doing anything. How do I run the project on my local machine that I downloaded from the cPanel?
You may want to see what that error is in the log file:
Log file location:
/storage/logs/laravel.log`
The laravel.log file mentioned above may have a date with it on the name.
The 500 error is because the stack trace is turned off in the .env file with APP_DEBUG=falsewhich may be by design since it's on a live server.
Download the files in "public_html" folder and project folder(in my case it is "LMS" folder - refer screenshot).
Export the database from phpmyadmin in cPanel which is used in Laravel project
Go inside the Project folder(in my case LMS folder) and delete all the content inside the "public" folder. Then you will have an empty public folder inside your project folder(LMS folder)
Now copy and paste all the content inside "public_html" folder that is downloaded from cPanel into the previously emptied "public" folder inside the project folder(LMS)
Import the exported database to locally created database
Change following lines in index.php file which is inside the local "public" folder
These two lines
require __DIR__.'/../LMS/vendor/autoload.php';
$app = require_once __DIR__.'/../LMS/bootstrap/app.php';
into these two
require __DIR__.'/../vendor/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
Notice that we have removed the "LMS" in the paths
Go to the .env file in the project root and change these settings that matches to your local environment
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=lms_trends_new
DB_USERNAME=root
DB_PASSWORD=root
//Only for MAMP users
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
Run following commands
$ php artisan config:cache
$ composer dump-autoload
Finally run your project with following command
php artisan serve
First , Download the database from cpanel which is used in laravel project .
Then follow any one step below .
Upload the database in your localhost mysql .
then Change your env files as per your local system .
Install composer using following command .
composer install
Then update the compsoser From your composer.json file .
Composer update
composer dump-autoload
Now run php artisan serve
If you find any difficult in the first step , follow the second one.
Install new laravel project using following command .
`composer global require laravel/installer`
Create new project Laravel
`laravel new projectname`
Then just copy paste the directories app/ , Resources, /Public , /config .
Do not touch anything inside config/config.php
Just change the database name and username, password in .env file ..
Then run
php artisan serve
If you still cant able to do it , comment here

How to remove "public/index.php" on server?

I m newly working on laravel.
I created laravel project named as "blog" on localhost and for removing public/index.php, I followed following process :
cut and pasted .htaccess from public/ folder to root i.e. blog
Renamed the server.php to index.php
Then I created a test api in api.php route and echoed "Hello World".
Now when I go to project path from my localhost server like:
localhost/Blog/api/test then its work properly.
But when I run same on a server like 192.101.111.555,like :
192.101.111.555/Blog/api/test then it showing NOT FOUND.
I am not getting how can I resolve this. And why its working fine on localhost but not working on server ?
You rename server.php but not recommend. This file copy then rename
Yes, if you have done those settings you will not be able to properly access on the localhost by running php artisan serve. So for this, you can install xampp and do the virtual host settings. Check more info at
How to enable Virtual Host on Xampp for Laravel?.
On the benefit of this is that you don't have to run the php artisan serve command again and again.

Hosting laravel project , doesn't read env file

**I can't move files to '/' path and in htdocs this project don't read env file if i set key in app.php then can't load sql parameters from env , how to set?**
Sorry for my eng
You need to run the following command in order to create the correct encryption keys:
php artisan key:generate
This will fix your 'The only supported chiphers are AES-128-CBC ...' error.
You also need to edit your virtual host to make your the public directory the DocumentRoot cause now you are listing your application root and that is not good!

How to run laravel 5.0 project on localhost without use php artisan serve

I have created a laravel 5.0 project with php artisan serve, now i need to know how to run laravel 5.0 project run without start php artisan serve, i have already browse lot of websites no one help me..
You need to change "server.php" to "index.php" then copy ".htaccess" from public to root directory.
See: https://stackoverflow.com/a/30053989/3948755
Laravel sever Folder is "public". There is an index.php so you can run you project from there.
Suppose if you using UbuntuOS then you have to create your local server in public directory. Suppose your folder name is laravel_test then go in that directory and run some thing like this
php -S localhost:8000 -t public
If you using windows then access public folder from URL.
localhost/laravel/public
Actually it's bad practise to access folder from URL but for local its good. You also can go with host entry. Just make sure that your target folder is "public" directory.
Normally you would have WAMP/XAMPP installed. You can access Laravel project like below
localhost/laravel/public
But this is not recommended. You should create Virtual host for example
laravel.local that pints to server-root/laravel/public.
this is how you create virtual host.
Or even better go for a Laravel Homestead .
How is your .htaccess file configured?
Try with localhost/laravel/public/index.php
Use http://localhost/projectName/public
It will be work. but in case if you have another Route and you can not access that Route and get the error like " Page Not Found " then please use the following command
sudo a2enmod rewrite
Now open the http://localhost/projectName/public/yourRoute
This is a little late but still applicable, what I like to do (using ubuntu 14.x+) is put my laravel project (let's say Project1) in my var directory, so it would be in /var/Project1, then symlink the public folder to somewhere in /var/www(+/html depending on apache version).
Symlink can be done something like this:
ln -s /var/Project1/public /var/www/html
This keeps your internal files off the grid so to speak, this is untested so if I've missed anything just comment and I will amend this post.
EDIT:
Obviously if your http root is /var/www/html you can put your project in /var/www/Project1
If you have access to xampp or wampp on your operating system you can more or less configure your virtual host like in the instruction below:
https://bestin-it.com/creating-virtualhost-on-your-local-computer-to-start-simple-index-php/
This instruction shows how to run it locally on your PC, but it works generally the same on any hosting portals. In most case in payed portals you have any web panels to configure your public folder that reference to /public folder in laravel folder's structure.

Resources