Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

DanielJohan's avatar

Laravel Deployment

Hello

I just deployed my first laravel site. I am doing so on digital ocean on a droplet with nginx.

I am encountering a problem. The styling is all of a sudden messed up. In local development it was styled correctly, but online its messed up. I am using Tailwind but also normal CSS classes.

Does anyone know what that could be. I did run npm run build before launch.

Thanks in advance

0 likes
19 replies
Hiccups's avatar

Have you checked if the custom or normal style.css file is imported correctly?

1 like
Ben Taylor's avatar

Are the styles messed up in your local development after the build? The build step purges out any tailwind classes that it thinks aren't used in you app.

1 like
iamgeorge's avatar

@danieljohan

Hello, use this commands before make zip for deploy

  1. php artisan clear-compiled
  2. php artisan route:clear
  3. php artisan config:clear
  4. php artisan view:clear
  5. php artisan cache:clear
  6. php artisan optimize

[!TIP] You can also write this code in routes/web.php and then access to these commands from browser after deployed... for examp. domain.com/clearservices it will run first command

// Clear Compiled Services:
Route::get('/clearservices', function() {
    Artisan::call('clear-compiled');
    return 'Application services has been cleared';
});

// Application Route Clear:
Route::get('/routeclear', function() {
    Artisan::call('route:clear');
    return 'Application optimized';
});

// Clear Config Files:
Route::get('/configclear', function() {
    Artisan::call('config:clear');
    return 'Application optimized';
});

// Clear View Files:
Route::get('/viewclear', function() {
    Artisan::call('view:clear');
    return 'Application optimized';
});

// Clear application cache:
Route::get('/clearcache', function() {
    Artisan::call('cache:clear');
    return 'Application cache has been cleared';
});

// Application optimize:
Route::get('/optimize', function() {
    Artisan::call('optimize');
    return 'Application optimized';
});

// CACHING------ 

// Clear application cache:
Route::get('/clearcache', function() {
    Artisan::call('cache:clear');
    return 'Application cache has been cleared';
});

//Clear route cache:
Route::get('/routecache', function() {
    Artisan::call('route:cache');
    return 'Routes cache has been cleared';
});

//Clear config cache:
Route::get('/configcache', function() {
    Artisan::call('config:cache');
    return 'Config cache has been cleared';
});
1 like
JussiMannisto's avatar
Level 50

@iamgeorge @danieljohan Never do this. Public endpoints that anyone can call to control the application cache is a horrible idea.

Hello, use this command before make zip for deploy

You should use a version control system like git, not zips. Host the code in an online repository and deploy changes from there. GitHub is the most popular platform for this.

1 like
iamgeorge's avatar

@JussiMannisto Once the deployment is finished, the endpoints can be removed from web.php. Regarding version control systems like Git, I can say that using a zip file for deployment isn’t necessarily a bad idea, depending on whether the deployment process is done correctly.

Snapey's avatar

@iamgeorge can you hear yourself? How do you remove the routes without re-deploying? Unless you are suggesting editing the files on the server (shudders)?

1 like
JussiMannisto's avatar

@iamgeorge

Regarding version control systems like Git, I can say that using a zip file for deployment isn’t necessarily a bad idea, depending on whether the deployment process is done correctly.

If you don't use any version control and use zips to deploy code changes, it's safe to say you're not doing it "correctly." There's a reason why everyone uses version control.

1 like
iamgeorge's avatar

@Snapey yes that's exactly what I meant, editing one file on the server is not Armageddon ))

iamgeorge's avatar

@JussiMannisto If I have finished the local development process 100%, then it's okay to deploy without version control. I would say that version control is not mandatory; it depends on the type of website. There are also reasons why you might choose not to use version control. and one more editing one file after deploying on the server is not Armageddon

iamgeorge's avatar

@Snapey Yes, I agree with you this is sometimes really "hard way", but in this case, the problem is that the styling is messed up after deployment. I’ve had a tough time with styling issues on different hosting platforms. Preparing the app before deployment sometimes doesn’t work, and after deployment, it often requires running some additional commands. A quick solution is to add those commands temporarily and then remove them afterward. I understand the benefits of version control, but this is just about correcting styling, not making general changes to the whole website. I am still learning, and I don’t think I can ever say that I know everything. However, based on my experience, this approach works well. Thank you also for sharing your experience.

martinbean's avatar

I would say that version control is not mandatory

@iamgeorge You‘re just trolling now…

2 likes
iamgeorge's avatar

@martinbean listening to me, I have no time for this/you, that's all... I know, now you understand me well, have a nice day.

martinbean's avatar

@iamgeorge No, I imagine you don’t have time. I imagine you have busy day ahead preparing a folder for uploading, and then running Artisan commands via URLs instead of deploying automatically via a CI pipeline from a source repository 🙃

1 like
Snapey's avatar

Open the browser development tools, network tab, and refresh the page. Any missing assets will be in red.

A possible cause is not hosting your site correctly. When you open your page is the path the same (apart from the domain) or do you have to add aditional folder(s) ?

Ben Taylor's avatar

If you are building your js and CSS files locally then pushing them to your git repository, make sure that the build directory is not in the .gitignore file

1 like
DanielJohan's avatar

Hello Guys,

Thank you very much. All responses are highly appreciated.

Well, I did use git with bitbucket, I didn't know though that I could use it to even pull on my droplet, thanks @jussimannisto

So I configured it with ssh and stuff, I pulled it on my droplet, it took me a matter of seconds, while with FileZilla I was waiting 10 minutes. This is awesome stuff. So now its up and running. then With a few commands from @iamgeorge like clear-compile and stuff and know it runs nicely!!

Awesome stuff ... Thanks again guys!

1 like

Please or to participate in this conversation.