Sitemap
Dev Genius

Coding, Tutorials, News, UX, UI and much more related to development

Statamic Installation Guide

4 min readApr 5, 2023

--

If you’re a Laravel developer, and are keeping yourself up-to-date with the latest buzz in the community, then I’m guessing you probably have heard of Statamic. No?? Well, in short, it is a CMS built on and built for Laravel, and that’s all I’ll say for now. Why am I talking about this specific CMS is a topic for future discussion. Let’s get on with installation.

(Note: Until Statamic-4 releases, Statamic-3 only supports up to Laravel 9. For those who’ve already switched to Laravel 10, the wait may be a little longer, and a lot worth it)

There’re two ways to install Statamic. One is a clean local install, and another one is with Laravel. We’ll look at both here.

Local Install

To make things easier, let’s install the Statamic CLI first. It can be installed locally using composer with the following command.

composer global require statamic/cli

Then, start a new Statamic project with the following.

statamic new project_name

You’ll be asked if you want to install a blank site or a Starter Kit. For beginners, it’s better to use a blank site.

It’ll prompt you to setup a super user. This user account will be used for your control panel access, so better you do it.

cd into the app and run php artisan serve and you’re good to go. Use the /cp route to go to your control panel.

Installation with Laravel

Firstly, install Laravel in your preferred directory locally.

//with composer
composer create-project laravel/laravel project-name --prefer-dist

//with laravel installer
laravel new project-name

Then run php artisan config:clear (to ensure the config isn’t cached).

Add "@php artisan statamic:install — ansi" line to the post-autoload-dump in composer.json . Your composer.json should look like this

"scripts": {
"post-autoload-dump": [
"@php artisan package:discover --ansi",
"@php artisan statamic:install --ansi", //add this line
],
}

Install statamic/cms with composer

composer require statamic/cms --with-dependencies

You’ll be asked to use pixelfear/composer-dist-plugin . This allows composer to run an unzip command on the control panel assets. We kindof need to do this as of now, or else we’ll end up having to manually configure a lot to handle assets in/for the system.

Since I’m using Laravel 9 (which by default will have vite configured instead of mix), we might need to run npm run dev to bundle the assets.

Get Manish Basnyat’s stories in your inbox

Join Medium for free to get updates from this writer.

As of today, your home page will load a static home view. On /cp route, you’ll be asked to login to access your cpanel.

Configuring Users

For a large number of users, it’s a good idea to store them in a database instead of the filesystem that statamic ships in with. For this, follow the following steps:

For fresh local app installed with statamic new

  1. Configure database in your .env file
  2. In config/statamic/users.php, change repository to eloquent.
  3. In config/statamic/stache.php, comment out the users store if present.
  4. In config/auth.php, comment out the statamic provider, and uncomment the eloquent provider.
  5. Run the php please auth:migration command to generates the migration for the role and user group pivot tables.
  6. Run php artisan migrate . It may prompt you to install doctrine/dbal package. Do so using composer require doctrine/dbal .
  7. Run command to seed or register your users or perform this manually.

For existing Laravel app with statamic installed

For existing laravel app, statamic will be automatically configured to use the Eloquent driver. We’ll need to perform the following steps.

  1. In config/auth.php add the following inside the passwords array:
'activations' => [
'provider' => 'users',
'table' => 'password_activations',
'expire' => 4320,
'throttle' => 60,
],

2. In config/statamic/users.php change the passwords array to:

'passwords' => [
'resets' => 'resets',
'activations' => 'activations',
],

3. Run Migrations

Once again, before running migrations, you may need to install doctrine/dbal package to have modifications to users table configured with statamic.

php please auth:migration
php artisan migrate

4. Insert users into the users table and access the statamic control panel through php artisan serve in the /cp route.

If you’re using filesystem instead of database, for a small set of users use the following.

Run the make:user command in the terminal as follows:

php please make:user

This will ask you for name, email, password, and prompt you to configure this user as a super user.

This user information is not saved in the database, but in the filesystem. Browse the users folder in the root of the directory, and you’ll find the user account in a .yaml file. Each .yaml file corelates to a user. If you configure more fields for your user to be saved, all those fields along with default ones can be seen in the .yaml file.

So that’s it!!! You’ve successfully installed statamic. There’s a lot you can do with this CMS. It’s super easy to customize and work with. Get yourself familiar with the directory structure and the config files, and we’ll get deeper into it soon.

--

--

Written by Manish Basnyat

I love writing, about tech, about love, about life. And I really enjoy sharing my experience with everything

Published in Dev Genius

Coding, Tutorials, News, UX, UI and much more related to development