Laravel Deployment all routes except / show 404 - .htaccess

TLDR
I'm deploying a Laravel application to Directadmin with deployer's recipe. Getting 404 on all routes except /.
What I've tried
Manual Deploy
Initially I created the storage link Laravel requires between app/storage/public and public/storage
ln -sfn /home/myuser/domains/example.com/laravel/storage/app/public/ /home/myuser/domains/example.com/laravel/public/storage
For security I've placed the source files outside of public_html and created symlinks for the contents of public into public_html
/home/myuser/domains/example.com/laravel/
ln -s home/myuser/domains/example.com/laravel/public/* home/myuser/domains/example.com/public_html/
This kept leading me to all sorts of crazy errors during runtime like Whitescreens and route issues even though the deployment cleared cache and routes and followed Laravel deployment steps.
Deployer Script
Switched to Deployer's Laravel recipe and symlinked the each file and folder in current to public_html so I can have subdomains on the same domain. This worked the first 2 deployments round after some coaxing with permissions.
Then had route cache issues causing a symphony closure error. Which I solved by clearing routes and restarting the httpd server.
Next deployment all routes except / show 404.
What I've done this deployment
Reset permissions
npm run prod
php artisan route:clear
php artisan cache:clear
Checked .htaccess
restart httpd
Read most questions on Stackoverflow on 404's and routes [1] [2] which suggest clearing route cache and checking order of routes and typo's in route files.
One thing to note I'm deploying code that works in Dev on Linux PHP8. So there's no issues with the routes files. Deploying to the same Linux distro and same version of PHP.
Most of these steps are part of the deployment script anyway. But somehow Laravel finds a way to break on each deployment (even when it's scripted). Laravel is so temperamental!!
Anyone have an idea what else could be wrong?
[404 Routes Question][1]
[Another 404 Routes question with htaccess][2]
[Laravel Api routes does not work][3]
[1]: https://stackoverflow.com/questions/14160202/laravel-debugging-404-routes
[2]: https://stackoverflow.com/questions/24147460/laravel-all-routes-except-return-404
[3]: https://stackoverflow.com/questions/57400525/laravel-api-routes-doesnt-works-404

Related

Install drupal project with drupal in a subdirectory

My customer a has production environment with the following folder structure:
- www
|- maresmuseum
where I only have access to these two empty folders, being the "maresmuseum" the public_folder.
I've deployed my Drupal 9 site with composer, like the project-recommended way does, you know: placing the index.php along many other core related folders & files in "maresmuseum" folder, and /vendor, /tmp and many other private stuff in the "www" folder.
As a result, I can access my website through a url like this: https://example.com/maresmuseum (I'm quite sure my customer has a .htaccess rule somewhere to accomplish that, don't you?)
Given this production scenario, and having in mind I work with DDEV on local, I want to install this site on my local machine so I can access it with a url like this: https://example.local/maresmuseum.
Of course, all inner pages of this site must follow this url pattern, something like this:
https://example.local/maresmuseum/about-us
https://example.local/maresmuseum/contact, etc..
How should I configure DDEV to accomplish that?
Thanks in advance.
I'm sure there are many ways to do this. Here's one way to do it using nginx configuration changes.
I used https://blog.rebootr.nl/drupal-8-in-a-subdirectory-with-nginx/
ddev config --composer-root=maresmuseum --project-type=drupal9 --webserver-type=nginx-fpm --docroot=maresmuseum/web --create-docroot --web-working-dir=/var/www/html/maresmuseum (This sets up to put composer.json in maresmuseum)
Install Drupal 9: ddev composer create drupal/recommended-project --no-install
ddev composer require drush/drush
Install project, or load db, or whatever, maybe ddev exec vendor/bin/drush si -y demo_umami --account-pass=admin
Edit the .ddev/nginx_full/nginx-site.conf to remove the #ddev-generated and replace the location stanza, example in https://gist.github.com/rfay/5248e5f75bf3e27d84965bfdfc69c240#file-nginx-site-conf
Edit the maresmuseum/sites/default/settings.php to add the stanza suggested in the article to the bottom, example in https://gist.github.com/rfay/5248e5f75bf3e27d84965bfdfc69c240#file-settings-php
ddev restart && ddev launch /maresmuseum
https://<project>.ddev.site/maresmuseum will work fine (as it will without the directory).
I had some trouble with browser cache, so you'll want to pay attention to that.

Only seeing Index of/ at domain even though index.js is present in the pubic_html directory

I've been driving myself a little mad trying to deploy this node.js and express app
I'm hosting on bluehost, so therefor, deploying via cpanel -
Currently:
Git repo cloned and deployed head commit success
Node app registered in app manager and Npm dependencies have been successfully ensured.
I after cd'ing into my repository directory in cpanel terminal I ran
/opt/cpanel/ea-nodejs10/bin/node app.js
and it was confirmed that
Server running at http://127.0.0.1:3000
Then after logging into whm root I ran
curl http://127.0.0.1:3000
And am returned with my index.ejs file , which seems like a good sign.
However, when I go to my domain -- deltadesigns.co
All you can see is :
Index of /
Name Last modified Size Description
DeltaDesigns22/ 2021-02-27 06:23 -
cgi-bin/ 2021-02-19 03:00 -
DeltaDesigns22 is the repo with all of required files and folders, public, views, app.js cpanel.yml etc.
I can't figure out why it's not working, feel like I'm so close but am just missing something! All help is appreciated!

How to host a Gatsby+Node.js project on a shared hosting?

I have a project in gatsby which uses Node.js/express for backend with MySQL.
Now, I know that all I have to do is gatsby build and that will create the static html/css/js files for me in the project/public folder and I can paste all of them in public_html folder and that will work(it is working), but Im confused about the database thing:
My issue is that in the gatsby-config.js when I change the mySql connection from localhost to the hosted db settings such as:
(The commented one is the hosted db configurations)
If I run gatsby develop while uncommenting the code. It says No such DB Error(obviously). So How can I configure the db settings here and also in the gatsby-node.js file to connect the db with the project?
I know this might sound like a dumb question but please help as I'm confused about what to do next.
Thanks.
Okay! Spent a lot of time on this. Hope it will help others.
Static Gatsby site
If you're trying to host a static gatsby site on any shared hosting. By static, I mean just plain gatsby styled pages,
You can do as the gatsby doc says:
Run :       gatsby build        or        npm run build.
According to gatsby:
Gatsby will perform an optimized production build for your site, generating static HTML and per-route JavaScript code bundles.
After this : try npm run serve.
According to gatsby :
Gatsby starts a local HTML server for testing your built site. Remember to build your site using gatsby build before using this command.
serve will test your build files(newly created files in yourprojectroot/public dir)
This will run your project(using the build files) on a test server(localhost:9000) to basically test your build files.
Test this localhost:9000, If everything is working good. You can go to your remote cPanel and paste all your build files into the public_html folder.
Head over to your domain and you're good to go.
Gatsby with MySQL and Node/express
If you are trying to host your gatsby site which works a little with node and mysql as well and you are a newbie in hosting like me, Here's what you'll want to do:
Try both the points mentioned above. (Build your static files and try serve)
Setup your db on the remote as well with the same name dbname, username and password as your local one.
Two extra things:
Now, what you are going to do is to run both the node and gatsby(webpack) servers on the same port (say 8001). So we are going to use only the node server and serve all our gatsby files(build files) as static content to node server.
In your node file, add:
app.use(express.static(path.join(__dirname, 'public')));
app.get('/*', function(req,res) {
res.sendFile(path.join(__dirname,'public/index.html'));
});
As you are going to run all your gatsby pages through index.html the last get('/*'... (above) will take care of all the pages request. Change the path public according to your remote folder structure
Add the build files along with the node(server connection) file in the public_html folder on remote.
Next add or change your .htaccess file (in the remote) to :
RewriteEngine On
RewriteRule ^$ http://127.0.0.1:8001/ [P,L]
RewriteRule ^(.*)$ http://127.0.0.1:8001/$1 [P,L]
So when you run your node file through the server's terminal, instead of yourdomainname.com:8001 the above mentioned .htaccess will redirect it to yourdomainame.com only
All done.
Your public_html now should contain the build files,a node/express conn file and .htaccess file.
Now, just go to your terminal. cd into public_html and run node yournodefilename.
You can head over to your domain now.
Note : You can use pm2 package to keep your node server always running.
Hope it helps somebody.
You should use environment variables to switch between configurations (locally and production). Environment files are files that store sensitive data such as API keys, tokens, etc, so they must be ignored and untracked to avoid pushing critical data to a public repository.
By default, Gatsby uses .env.development and env.production respectively for gasby develop and gatsby build commands, of course, you can override this behaviour but, assuming the default configuration, you should add the following snippet to your gatsby-config.js:
require("dotenv").config({
path: `.env.${process.env.NODE_ENV}`,
})
Then, you need to create a .env.development and .env.production in the root of your project with the following content:
DB_HOST:yourHost
DB_USER:yourUserName
DB_PASSWORD:yourPassword
DB_NAME:youDatabaseName
Of course, each file should have different variables if you want to switch between databases or configurations.
Add them to your gatsby-config.js:
connectionDetails:{
host: process.env.DB_HOST
user: process.env.DB_USER
password: process.env.DB_PASSWORD
database: process.env.DB_NAME
}
The final step is to add, in your host, the environment file in order to make them accessible by Gatsby. S3 by Amazon allows to configure them but I guess that it's a common configuration for the hostings.

Folder structure to deploy app on EC2 instance

I am setting up a new React app on EC2 instance (ubuntu). I have installed nodeJS and npm and I am able to build my app successfully.
Issue is my code is in /var/www/html folder and my site example.com is pointed to this folder.
when I run
npm run build
It builds a folder under /html like /html/build now my app runs on example.com/build. Resources for these files comes from example.com/static/style.css etc but they actually reside under example.com/build/static
I can edit asset-manifest.json and change the path but thats not appropriate solution as I need to get rid of /build folder for production
I am not super familiar with deployments to EC2 but this looks like you just need to either copy the entire contents of your app inside var/www/html, or you need to tell apache or nginx to look to the right folder (in this case /build)
For example, with apache you probably have a file inside /etc/apache2/sites-enabled/ that is pointing to /var/www/html, you could change that to /var/www/html/build and restart apache.
You can check this for examples on how to write these configurations https://gist.github.com/rambabusaravanan/578df6d2486a32c3e7dc50a4201adca4

Deploying Angular 6 app to linux shared hosting (Apache server)

Not trying to duplicate the existing questions on "Deploying Angular apps"
I am trying to deploy an Angular 6 app to shared hosting on go daddy.
I see a blank page after i upload the files to public folder
I have tried the following troubleshooting steps
1. https://angular.io/guide/deployment#production-servers
2. https://github.com/mgechev/angular-seed/wiki/Deploying-prod-build-to-Apache-2
3. Unable to deploy Angular 5 using dist folder in WAMP server
4. I have tried changing the path on <base href="./">
5. Used the ng build --prod command to create the files in dist folder and uploaded them aas it is to the public www folder then created the .htaccess folder and rewritten rule as per angular docs
Any suggestions or help is greatly appreciated.
Thanks in advance.
Nothing seems to solve the problem.
Has anyone deployed an angular2+ app on godaddy shared linux hosting (apache server) ?
It was an issue with the routing.
I was routing using localhost as route URL.
It had nothing to do with the server setup

Resources