How to setup Craft CMS w/ LAMP Stack

Tim Sullivan
Dec 2 · 6 min read

Following pre-reqs needed to setup Craft CMS.

Install MAMP — You will use this to boot up your servers and connect to the database you create and will then be able to run the website locally.

Install Sequel Pro — You will use this application to create the database in a later step.

Installing Composer

Next, we will be installing composer via the command line. Composer is a tool for dependency management in PHP. We will be installing it via command line inside a MAMP directory where I typically setup my local environments and I recommend that you do too for stuff specific to MAMP.

Before installing Composer change your path to cd /Applications/MAMP/htdocs which is where you will create your project directory. For example, mine for this tutorial is called test which is located here /Applications/MAMP/htdocs/test.

Install via the command line by copying and pasting these commands in your terminal. You can also just download the zip file if you’d like.

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'a5c698ffe4b8e849a443b120cd5ba38043260d5c4023dbf93e1558871f1f07f58274fc6f4c93bcfd858c6bd0775cd8d1') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

Be sure to hit enter on the last command if you pasted these into the terminal to remove the composer setup file as we won’t be needing it now that composer is installed. Once successfully installed you should receive a successful message prompt in your terminal. Note, that I installed this in the directory I will have my project in. (You can either install it locally per project I believe or globally. Instructions macOS here. Windows here.)

Note that you should be running Composer 1.3.0 or later. You can find out your installed version by running composer -v in your terminal. Run composer self-update to update if needed.

Create a Craft Project

To create a new Craft project run this command

composer create-project craftcms/craft .

Make sure when you run this command you’re in the root project folder and ensure it is empty or an error will be thrown in your terminal. The path should be /Applications/MAMP/htdocs/yourProjectName.

Composer will take a couple minutes to load everything as you create your new project. Once it’s done you will be shown a success message:

Double check files

Now that your project is all setup via the command line check to make sure you have the proper directory structure(files) in your project.

Your project Directory Structure should look like so:

My projects Directory Structure which is good to go:

If you are missing any of the files for some reason just grab the zip file off the craft site and drag and drop/replace whatever you need into your project folder.

Set the File Permissions

This can be tricky, but not for us. The following files will need permissions in order for Craft to run properly; .env, composer.json, composer.lock, config/license.key, storage/*, vendor/*, and web/cpresources/*

For those of you who could care less about permissions you can apply these permissions to the project. I’m just going to change the projects permissions with chmod 755 <ProjectPath>.

For those of you who do care about permissions here is some brief context as I don’t want permissions to take up a whole portion of this tutorial.

  • If you’re not sure and like to live life on the edge, use 777.

Set a Security Key

We’re going to be using the command line to generate a security key. You could also use a password generator of your choice to generate your key.

In the terminal, make sure you are in your projects root directory and run this command:

./craft setup/security-key

You should see something similar to this:

Create your database

Next you are going to be creating a MySQL database for your Craft project. Before you do start up MAMP and click “Start Servers”.

Then open up Sequel Pro and select the “Socket” tab and sign in with a username and password of root and then click “Connect”. Once logged into Sequel Pro, from the top left menu select Database > Add database and name your database whatever you want with the following settings below:

If you don’t do this you won’t now be able to test your database credentials when you create them or be able to connect because they’re not turned on or created… it would look like this:

We now have an empty database that will be holding all the stuff we need as we approach setting up craft. Go back to your terminal and type ./craft setup and the following to setup your database:

Which database driver are you using? [mysql,pgsql,?]: mysql

Database server name or IP address: [localhost] Press Enter

Database port: [3306] Press Enter

Database username: [root] Press Enter

Database password: root (whatever you want, remember it we’ll need it)

Database name: test_db (whatever you want just make sure it’s the same as the Sequel Pro database name)

Database table prefix: Press Enter

Install Craft now? (yes|no) [yes]: Press Enter

Username: [admin] Press Enter

Email: youemail@email.com

Password: your_password

Confirm: your_password

Site name: Name Your Site

Site URL: http://localhost:8888/yourFolderNameInHtdocs/web/

The path above that says yourFolderNameInHtdocs is the name of your folder that you created in the beginning of the tutorial that is stored in the path /Application/MAMP/htdocs/projectName

Site language: [en-US] Press Enter

Next, craft will install and start creating tables which will be dumped into the database you created in Sequel Pro.

If you check Sequel Pro again you can “Refresh databases” with the shortcut key Command + Shift + R and then you’ll see all the tables generated for you Craft database.

Signing into Craft on Your Browser

We’re almost there! Now that we have setup our database and provided the Site URL we can install the Craft CMS on the Browser for your site. Make sure your MAMP servers are started and your craft database is running to do the following. In your web browser address bar type localhost:8888 and press enter which will navigate you to the root folder of your project.

My project is labeled test so I am going to select test and then select web which will take you here: http://localhost:8888/test/web/

Select “Go to your Contol Panel” and then all you have to do is login with your Craft CMS username and password and vuala!

I hope you all found this tutorial helpful. I’ll be making a YouTube video version of this soon and will be creating a docker container for y’all so you won’t have to do this anymore. If you are interested in design systems and Figma check out my youtube channel as I have a YouTube channel that teaches you how to build a design system from scratch in Figma.

funny gif
funny gif
Shoutout to the Rad Brad!

Thanks to Steve Phillips / @elimisteve

Tim Sullivan

Written by

n00b & UX Design Technologist @ Splunk

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade