This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

April 29 Webinar: Get Full Control of Cloudflare Enterprise on Cloudways.. Register Now→

How to Create a Blog in Laravel Locally and Deploy It on Cloudways

Updated on December 24, 2025

14 Min Read
Laravel Blog

Key Takeaways

  • Building a Laravel blog involves setting up the database, creating routes, controllers, and Blade templates, and structuring content effectively.
  • Deploying a Laravel application to a live server requires proper file management, environment configuration, and database migration to ensure it runs smoothly.
  • Hosting on Cloudways provides a managed, Laravel-ready environment that handles server setup, security, and performance, letting you focus on building and scaling your application.

Building a blog from scratch is a big project, but Laravel makes it much easier to manage. You don’t have to reinvent the wheel for things like databases or page routing. It’s a solid choice whether you’re making a simple personal site or something much bigger.

In this blog, we’re going to build a Laravel blog from the ground up. I’ll show you how to set up your local environment with Docker, build out the actual post system with Blade templates, and finally push everything to a live Cloudways server. We’ll also look at how to handle controllers and database settings properly so the site stays secure.

By the time we’re done, you’ll have a fully working blog running online. My goal isn’t just to give you code to copy. I want you to see how a professional Laravel app actually fits together so you can keep building on it later.

Let’s get started…

Prerequisites

You’ll need a few things ready before we touch any code. Getting these sorted now will save you a lot of trouble once we’re mid-build.

  • PHP 8.2+: Laravel 10 (and the newer versions) won’t run on old PHP. Check your version first.
  • Composer: This is a must-have for PHP. It handles all the packages and libraries Laravel needs to function.
  • A Database: I’m using MySQL for this, but MariaDB works fine too. This is where all your blog posts will actually live.
  • A Local Setup: You need a way to run the site on your machine. While Docker is great, I’m going to use XAMPP for this guide because it’s a bit more straightforward for beginners.
  • The Terminal: You don’t need to be an expert, but you should be comfortable running basic commands. We’ll be using it for migrations and installing the framework.

Once you’ve got those installed and working, we can move on to actually setting up the project.

Managed Laravel Hosting for Smooth Deployment

Cloudways managed Laravel hosting lets you develop apps easily with optimized servers, built in caching, PHP-FPM, and one-click scaling to ensure your Laravel apps run efficiently.

Setting Up Your Local Development Environment with XAMPP

Before you start building your Laravel blog, you need a working local environment. XAMPP is a great choice for this because it bundles PHP, MySQL, and Apache together, so you don’t have to configure each component separately.

Step 1: Download and Install XAMPP

Go to the XAMPP website and download the version for your operating system. Once downloaded, run the installer and follow the instructions. For most cases, the default settings are fine.

Download and Install XAMPP

Step 2: Start Apache and MySQL

After installing, open the XAMPP control panel. You’ll see options to start Apache and MySQL. Click Start for both. If everything works, Apache will run on port 80 and MySQL on port 3306. These are the default ports Laravel expects.

start Apache and MySQL

Step 3: Verify Your PHP and MySQL Setup

Open your browser and go to http://localhost. You should see the XAMPP welcome page. This confirms Apache is working.

Verify Your PHP and MySQL Setup

To check MySQL, click Admin next to MySQL in the control panel. It will open phpMyAdmin. Here you can create databases, manage tables, and run queries.

click Admin next to MySQL in the control panel

open phpMyAdmin

Step 4: Install Composer

Composer is required to install Laravel and manage its dependencies. Download Composer from getcomposer.org and follow the installation instructions.

Install Composer

After installing, open a terminal or command prompt and run:

composer --version

run composer

You should see the installed Composer version. This means you’re ready to start creating Laravel projects.

Once this is done, your local environment is ready.

Creating a New Laravel Project Locally

Now that your local environment with XAMPP is up and running, it’s time to create the Laravel project itself. By the end of this section, you’ll have a fresh Laravel app ready to build your blog.

Step 1: Create the Laravel Project

Navigate to the folder where you want your project to live. For example, if you want it under C:\xampp\htdocs, run:

cd C:\xampp\htdocs

Now, create a new Laravel project using Composer:

composer create-project laravel/laravel laravel-blog

create a new Laravel project using Composer

Here, laravel-blog is the name of your project folder. Composer will download Laravel and all necessary dependencies. This may take a few minutes depending on your internet speed.

Composer will download Laravel and all necessary dependencies

Once it finishes, you should see a folder named laravel-blog with all Laravel files inside.

you should see a folder named laravel-blog with all Laravel files inside

Step 2: Configure the Environment File

Inside your project folder, there is a file called .env. This file contains important settings for your application, including database credentials.

Open .env in a text editor and find these lines:

DB_CONNECTION=mysql

DB_HOST=127.0.0.1

DB_PORT=3306

DB_DATABASE=laravel

DB_USERNAME=root

DB_PASSWORD=

Since we’re using XAMPP, leave DB_USERNAME as root and DB_PASSWORD blank. Change DB_DATABASE to something like laravel_blog (we’ll create this database next). Also, in my .env file, DB_CONNECTION is sqlite. We’ll need to change the .env file to use MySQL instead of SQLite.

One final check: make sure to delete the # at the start of each line. Save the file, and Laravel will now connect to your MySQL database.

Here is the overall revised code block:

DB_CONNECTION=mysql

DB_HOST=127.0.0.1

DB_PORT=3306

DB_DATABASE=laravel_blog

DB_USERNAME=root

DB_PASSWORD=

Next we’ll create the database in phpmyadmin.

Step 3: Create the Database

Open phpMyAdmin by going to http://localhost/phpmyadmin. Click Databases, enter laravel_blog as the database name and change latin1_swedish_ci to utf8mb4_general_ci.

Why?

  • utf8mb4 supports all Unicode characters, including emojis and special symbols.
  • latin1 is more limited and can cause problems if your blog posts include non-English characters.

Click Create when done.

Create the Database

Our database is now ready for Laravel.

database is ready

Step 4: Run Laravel Migrations

Before running the server, you need to create the default Laravel tables (including sessions, users, and others) in your database. Run this command in your project folder:

php artisan migrate

This step ensures Laravel has all the tables it needs to run properly and prevents errors like “Table sessions doesn’t exist.”

php artisan migrate

Step 5: Test the Laravel Project

Go back to your terminal and navigate to the project folder if you aren’t already there:

cd C:\xampp\htdocs\laravel-blog

Run the built-in Laravel server:

php artisan serve

php artisan serve command run

You’ll see a message with a URL, usually http://127.0.0.1:8000. Open it in your browser. If everything went well, you’ll see the Laravel welcome page. This confirms that your Laravel project is working locally.

Laravel welcome page

At this point, you have:

  • Installed Laravel and all dependencies.
  • Configured your environment file for MySQL.
  • Created a local database.
  • Confirmed your project runs with php artisan serve.

Next, we’ll move on to creating the posts table and controllers, which will let us store and display blog posts dynamically. This is where your blog starts to take shape.

Step 6: Create the Posts Table

So far, you’ve installed Laravel, configured your .env file for MySQL, created the database, and run migrations for the default tables. Your project runs locally, and now it’s time to build the core of your blog: the posts.

We’ll start by creating the posts table in the database, which will store all your blog posts.

  1. Open your terminal and make a new model with a migration:
php artisan make:model Post -m

Open your terminal and make a new model with a migration

  • Post is the name of the model.
  • -m also creates a migration file for the posts table.
  • This gives you a model to work with in code and a migration file to define the table structure.
  1. Open the migration file in database/migrations/. Inside the up() method, define the columns for your posts:

Inside the up() method, define the columns for your posts

public function up(): void

{

Schema::create('posts', function (Blueprint $table) {

$table->id();

$table->string('title');

$table->text('body');

$table->timestamps();

});

}

code snippet

  • id() – the primary key.
  • title – the post title.
  • body – the main content.
  • timestamps() – automatically creates created_at and updated_at columns.
  1. Run the migration to create the table:

php artisan migrate

Now your posts table exists in the laravel_blog database and is ready to store posts.

Step 7: Create the Post Controller

Next, we need a controller to handle all actions for posts, like showing, creating, and storing them.

  1. Generate the controller:
php artisan make:controller PostController

This creates app/Http/Controllers/PostController.php.

Generate the controller

  1. Open the file and add the following methods:
<?php

namespace App\Http\Controllers;

use App\Models\Post;

use Illuminate\Http\Request;

class PostController extends Controller

{

// Show all posts

public function index()

{

$posts = Post::all();

return view('posts.index', compact('posts'));

}

// Show a single post

public function show(Post $post)

{

return view('posts.show', compact('post'));

}

// Show form to create a post

public function create()

{

return view('posts.create');

}

// Save a new post

public function store(Request $request)

{

$request->validate([

'title' => 'required|max:255',

'body' => 'required',

]);

Post::create($request->all());

return redirect()->route('posts.index');

}

}

Here’s what each method does:

  • index() – lists all posts.
  • show() – displays a single post.
  • create() – shows the form to add a new post.
  • store() – saves the post to the database.
  1. Open the Post model app/Models/Post.php and allow mass assignment by adding:
protected $fillable = ['title', 'body'];

Open the Post model appModelsPost.php and allow mass assignment

This is required for Post::create($request->all()) to work.

Step 8: Set Up Routes

Finally, let’s connect our controller to URLs in the browser. Open routes/web.php and add:

Set Up Routes

use App\Http\Controllers\PostController;

Route::get('/posts', [PostController::class, 'index'])->name('posts.index');

Route::get('/posts/create', [PostController::class, 'create'])->name('posts.create');

Route::post('/posts', [PostController::class, 'store'])->name('posts.store');

Route::get('/posts/{post}', [PostController::class, 'show'])->name('posts.show');

Your file should look like this:

Your file should look like this

Now your routes are linked to the controller methods and ready to handle requests.

At this point:

  • The posts table exists in the database.
  • The Post model is ready to interact with the table.
  • The PostController handles listing, showing, creating, and storing posts.
  • Routes are set up so you can access posts in the browser.

Next, we’ll create Blade templates so your blog posts actually show on the front end and you can add new posts through a form.

Step 9: Create Blade Templates for Your Blog

By now, you have your database, posts table, Post model, controller, and routes all set up. The next step is to make your blog visible on the front end so you can see posts and add new ones.

Laravel uses Blade templates for the front end, and we’ll create a few simple views for that.

First, inside resources/views, create a new folder called posts. This will hold all your templates for blog posts.

create a new folder called posts

In this folder, create three files:

  • index.blade.php
  • show.blade.php
  • create.blade.php

create three files

The index.blade.php file will list all posts. Here’s an example:

<!DOCTYPE html>

<html>

<head>

<title>Laravel Blog</title>

</head>

<body>

<h1>All Blog Posts</h1>

<a href="{{ route('posts.create') }}">Create New Post</a>

@foreach($posts as $post)

<div style="margin-bottom: 20px;">

<h2><a href="{{ route('posts.show', $post) }}">{{ $post->title }}</a></h2>

<p>{{ Str::limit($post->body, 150) }}</p>

</div>

@endforeach

</body>

</html>

This shows all posts with their title and a short snippet. Clicking a title will take you to the individual post page.

The show.blade.php file displays a single post:

<!DOCTYPE html>

<html>

<head>

<title>{{ $post->title }} - Laravel Blog</title>

</head>

<body>

<h1>{{ $post->title }}</h1>

<p>{{ $post->body }}</p>

<a href="{{ route('posts.index') }}">Back to all posts</a>

</body>

</html>

The create.blade.php file provides a form to add a new post:

<!DOCTYPE html>

<html>

<head>

<title>Create New Post - Laravel Blog</title>

</head>

<body>

<h1>Create a New Post</h1>

@if ($errors->any())

<div style="color: red;">

<ul>

@foreach ($errors->all() as $error)

<li>{{ $error }}</li>

@endforeach

</ul>

</div>

@endif

<form action="{{ route('posts.store') }}" method="POST">

@csrf

<div>

<label for="title">Title</label>

<input type="text" name="title" id="title" value="{{ old('title') }}">

</div>

<div>

<label for="body">Body</label>

<textarea name="body" id="body" rows="5">{{ old('body') }}</textarea>

</div>

<button type="submit">Publish Post</button>

</form>

<a href="{{ route('posts.index') }}">Back to all posts</a>

</body>

</html>

This form handles validation errors and preserves the user’s input if something is missing.

After creating these templates, you can now:

  • Visit /posts to see all blog posts.
  • You can create new posts at /posts/create using a form.
  • You can click a post title to view the full post on /posts/{post}.

Our laravel blog is fully dynamic locally, with content stored in the database and displayed using Blade templates.

Here’s a GIF showing our project in action:

laravel blog full dynamic output

Deploying Your Laravel Blog on Cloudways

Up to this point, we’ve built a fully working Laravel blog on our local machine. You’ve set up the database, created the posts table, built controllers, routes, and Blade templates, and confirmed everything works using php artisan serve.

Now it’s time to take that same project and move it to a live server so it’s accessible online. We’ll be using Cloudways for hosting, since it already provides a Laravel-ready environment and removes most of the server setup work.

For this section, I’ll assume you already have a Cloudways account and an active server running.

Step 1: Create a New Laravel App on Cloudways

Start by logging into your Cloudways dashboard.

  • Go to the Applications tab
  • Click Add Application

Add Application in cloudways

When prompted, choose the following options:

  • Application: Laravel
  • Name the app something like laravel-blog
  • Select your existing server

Click Add Application. Cloudways will now set up a fresh Laravel application for you. This usually takes a minute or two.

set up a fresh Laravel application on cloudways

application being added on cloudways

Once it’s ready, open the application from the dashboard and click the Application URL. You’ll see Cloudways’ default page. That’s expected. We’ll replace this with our own project files next.

Cloudways’ default page for laravel app

Step 2: Prepare Your Local Laravel Blog for Upload

Before moving files to the server, we need to clean up the local project.

Go to your local Laravel blog folder and delete:

  • The vendor folder
  • The .env file

clean-up-local-project

We remove vendor because it can be rebuilt on the server using Composer. We remove .env because the server will use different database credentials.

Everything else stays.

At this point, your local folder contains your app code, migrations, controllers, views, and routes, but no environment-specific files.

Step 3: Upload the Project to Cloudways Using SFTP

Now we’ll upload the project files to Cloudways.

  • In the Cloudways dashboard, go to Servers Master Credentials
  • Copy the SFTP details (IP address, username, password, port 22)

cloudways master credentials for server

Open FileZilla and connect using those credentials.

Once connected:

  • On the server side, navigate to:
    /applications/your_app_username/public_html
  • On your local machine, open your Laravel blog folder
  • Upload all files and folders. Keep in mind we have already deleted vendor and .env

move local project file to cloudways server using filezilla

This replaces the default Cloudways files with your Laravel blog code.

Step 4: Move Your Local Database to Cloudways

Your blog relies on the laravel_blog database we created locally, so we need to move that data to the server.

On your local machine:

  • Open http://localhost/phpmyadmin
  • Select the laravel_blog database
  • Click the Export tab
  • Export the database as an SQL file

Export the database as an SQL file

export sql file from phpmyadmin

This SQL file contains your tables, including posts, users, and sessions.

saved sql database for our laravel blog

Now back in Cloudways:

  • Open your Laravel application
  • Click Launch Database Manager

launch database manager in cloudways

  • Go to the Import tab

Go to the Import tab

  • Upload the SQL file you just exported

Upload the SQL file

Once the import finishes, your Cloudways database will match your local setup.

Once the import finishes, your Cloudways database will match your local setup

Step 5: Configure Laravel on the Server

Next, we’ll configure Laravel to run properly in production.

From the Cloudways dashboard, open the SSH Terminal for your server.

From the Cloudways dashboard, open the SSH Terminal for your server

Move into your application directory:

cd applications/your_app_username/public_html

Move into your application directory

Install dependencies:

composer install --no-dev

Now that we’ve installed composer, let’s check if everything worked as expected. Run this command:

php artisan --version

If you can see your laravel version after running the command, this means everything executed perfectly.

check laravel version via ssh in cloudways

At this point, you can go ahead and revisit your app URL. Instead of the default Cloudways page, you should now see the Laravel default page:

Laravel default page on cloudways server

Next, create the environment file Laravel uses for configuration:

cp .env.example .env

Generate the application key:

php artisan key:generate

php artisan keygenerate

Now edit the .env file:

nano .env

Update these values using the database details shown in your Cloudways Application Credentials:

DB_CONNECTION=mysql

DB_HOST=127.0.0.1

DB_PORT=3306

DB_DATABASE=your_db_name

DB_USERNAME=your_db_user

DB_PASSWORD=your_db_password

APP_URL=https://your-app-url

APP_DEBUG=false

Save the file and exit the editor:

  • Ctrl + O
  • Enter
  • Ctrl + X

Update the root route so the default Laravel page doesn’t show. We’re doing this so we can see our laravel blog app, not the default laravel page. To do this, open the routes file:

nano routes/web.php

Replace the default root route with:

use App\Http\Controllers\PostController;

Route::get('/', [PostController::class, 'index'])->name('posts.index');

Your final web.php should look like this:

<?php

use Illuminate\Support\Facades\Route;

use App\Http\Controllers\PostController;

// Home route showing blog posts

Route::get('/', [PostController::class, 'index'])->name('home');

// Blog post routes

Route::get('/posts', [PostController::class, 'index'])->name('posts.index');

Route::get('/posts/create', [PostController::class, 'create'])->name('posts.create');

Route::post('/posts', [PostController::class, 'store'])->name('posts.store');

Route::get('/posts/{post}', [PostController::class, 'show'])->name('posts.show');

Save the file, then clear Laravel caches:

php artisan config:clear

php artisan cache:clear

php artisan route:clear

php artisan view:clear

Lastly, Run migrations to set up your database tables:

php artisan migrate

Step 6: Verify Your Laravel Blog Is Live

At this stage, everything should now be in place.

  • Go back to the Cloudways dashboard
  • Open your Application URL

If all steps were followed correctly, you should see your Laravel blog running live, with posts loading from the database just like they did locally.

laravel blog deployed on cloudways server

At this point, we’ve successfully:

  • Built a Laravel blog locally
  • Moved the code and database to Cloudways
  • Configured Laravel for a production environment

Our blog is now live and ready to be shared. Sure we need to make it look visually appealing but I’ll leave that up to you and your creativity.

Why Host Your Laravel App on Cloudways

Cloudways Laravel hosting provides a managed environment tailored for Laravel applications. This means you get a server that’s already configured for optimal PHP performance, database handling, and security.

Key benefits of Laravel hosting offers:

  • Quick deployment: Spin up a Laravel-ready server without spending hours on configuration.
  • Automatic updates and security patches: Keep your app secure without manual intervention.
  • Scalability and performance: Easily upgrade server resources as your application grows.
  • Developer-friendly tools: Access via SSH/SFTP, use staging environments, and manage multiple applications from a single dashboard.

With Cloudways, you can focus on building and improving your Laravel application while the platform handles the infrastructure, security, and performance optimizations.

Wrapping Up!

There you have it. You’ve successfully built a Laravel blog locally, moved all your files and database to Cloudways, configured the environment, and made your blog live online.

By following these steps, you now have a fully functional Laravel application running in a production-ready environment without the hassle of complicated server setups. From here, you can continue customizing your blog, adding new features, and making it visually appealing to your audience.

With Cloudways handling server management, you don’t need to worry about security patches, server optimization, or manual configurations. This allows you to focus entirely on building and growing your application while Cloudways ensures top-notch performance and reliability behind the scenes.

Frequently Asked Questions

Q1. What do I need to create a Laravel blog from scratch?

To create a Laravel blog, you need a local development environment with PHP, Composer, and a database like MySQL. From there, you set up routes, controllers, migrations for posts, and Blade views to display and manage blog content.

Q2. How do I view phpinfo()?

Once your Laravel blog works locally, you upload the project files to the server, import your database, install dependencies with Composer, and configure the .env file for the production environment. After that, your blog should run online the same way it did locally.

Q3. Why does a Laravel blog sometimes show the default welcome page after deployment?

This usually happens when the application routes or public directory are not correctly configured. Ensuring the correct files are uploaded, dependencies are installed, and the root route points to your blog views helps prevent the default Laravel page from appearing instead of your blog.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Abdul Rehman

Abdul is a tech-savvy, coffee-fueled, and creatively driven marketer who loves keeping up with the latest software updates and tech gadgets. He's also a skilled technical writer who can explain complex concepts simply for a broad audience. Abdul enjoys sharing his knowledge of the Cloud industry through user manuals, documentation, and blog posts.

×

Webinar: How to Get 100% Scores on Core Web Vitals

Join Joe Williams & Aleksandar Savkovic on 29th of March, 2021.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Want to Experience the Cloudways Platform in Its Full Glory?

Take a FREE guided tour of Cloudways and see for yourself how easily you can manage your server & apps on the leading cloud-hosting platform.

Start my tour