https://craftcms.com/guides/developers-new-to-craft
Know: Twig (templating) and Yii (php framework).
Overview: Setup Local environment, install Composer and then use Composer to install Craft. You can also download and install manually but Craft also uses Composer to install plugins so you may as well try this method.
- Create site in Local
- Take note of the Remote port displayed in Local > Your site > Database. Also the DB creds will be user: root, pass: root, name: local as with all Local installs
- Right-click your Local site
open site ssh
cd /app
rm -r public
apt-get update && apt-get install -y curl unzip
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
composer create-project craftcms/craft /app
/app/craft setup
The database should look something like this:
root@6b52ccf77eb7:/app/craft# ./craft setup
Which database driver are you using? [mysql,pgsql,?]: mysql
Database server name or IP address: [127.0.0.1]
Database port: [3306] 4022
Database username: [root]
Database password:
Database name: local
Database table prefix: craft_
Testing database credentials ... failed: SQLSTATE[HY000] [2002] Connection refused
Database server name or IP address: [127.0.0.1] localhost
Database port: [4022]
Database username: [root]
Database password:
Database name: [local]
Database table prefix (type "none" for none): [craft_]
Testing database credentials ... success!
Saving database credentials to your .env file ... done
Install Craft now? (yes|no) [yes]:yes
- I recommend you name your public folder the same as it is in your production environment, then configure Local to be the same. Example,
public_html
: - Rename web to public_html:
mv /app/web /app/public_html
(you can now exit termnal/ssh) - Edit
/app/conf/apache/000-default.conf
or/etc/apache2/sites-enabled/000-default.conf
- Replace all (two) instances of
/app/public
with/app/public_html
- Right-click your Local site and restart the site
Now you can view the site, and access the admin from {{ site_url }}/admin.
https://www.eaglepeakweb.com/blog/install-craft-cms-3-lando-docker
This was the only way I could get it running on my Macbook Pro 2011. Local and other Docker solutions did not work.
- Delete your installation of Docker 🤷♂️|
brew cask install lando
- Run Docker - wait until the Whale menubar icon stops animating
- Make a folder and
lando init
- Edit the .lando.yml:
name: craft3blog
recipe: lamp
config:
webroot: web
php: '7.2'
database: mariadb:10.2
lando start
lando composer create-project craftcms/craft temp
mv temp/* .
- move filesmv boop/.* .
- move dot filesrm -rf boop
- enter db creds in
.env
using info fromlando info
- edit
.lando.yml
name: craft3blog
recipe: lamp
config:
webroot: web
php: '7.2'
database: mariadb:10.2
services:
database:
type: mariadb:10.2
portforward: 3311
creds:
user: homestead
password: secret
database: craft3blog
lando destroy
lando start
- install by visting
http://{{ yoursite }}/admin/install
https://www.cloudways.com/blog/install-craft-cms-on-cloud/
Edit config/general.php and add siteUrls to each of the environments. Eg. 'dev => [ 'devMode' => true, 'siteUrl' => 'https://mylocal.dev' ]'
https://nystudio107.com/blog/setting-up-a-craft-cms-3-project#deploying-craft-cms
https://craftcms.com/guides/craft-storage-gitignore
https://craftcms.com/guides/duplicating-a-craft-site https://craftcms.stackexchange.com/questions/13982/migration-of-craft-cms-from-one-host-to-another
- ./web is the public_html folder - it doesn't need to be named web, just be set to public and viewable
- needs Composer to install/update plugins
- Craft doesn't use defined templates (eg. archive.php, single.php, search.php) - these are defined by you by creating sections and their corresponing twig templates
- no menus system - you should create your own menu system by using Sections and Fields (Structures are good because you can arrange them in a tree hierachy)
https://craftcms.com/guides/creating-an-archive-page-for-entries
https://docs.craftcms.com/v3/dev/examples/search-form.html
By default Structures are set to use site_url/{slug}
. To make them nested set the slug of the Structure to {entry.last().uri}/{parent.uri}/{slug}
- title
- link
- type
Wordpress | Craft |
---|---|
posts | entries |
{{ post.field }} | {{ entry.field }} |
custom post types | sections |
/wp-content/plugins | /vendor - devs say that this should be in your .gitignore 🤷♂️ |
acf-json | project.yaml - will save your fields, sections, more... |
- Sections can be
- Singles - single use, unique 'posts'. eg. Home, Contact
- Channels - streams of similar 'posts'. eg. Blog
- Structures - nested/tree 'posts' eg, I use this for Pages
- twig is used in Craft from the ground up
- no php - if you need php you can write a plugin or module
- more configuration is needed over WP which more better out of the box
- setting Sections is done in the admin - not great for delevelopment in teams (means you have to share databases)
- no Menu management or functions - you can use Structures or plugins
- there is no Rich Text or WYSIWYG field - use Redactor plugin
- Commerce is $199 for simple transactions (donations), $999 for full store functionality (cart)
- inserting a link is different from linking to an internal page (entries)
- is free
- no field layouts (width, tabs)
- there is no repeater field - use Super Table plugin
- the Matrix field is like Flexible Content but you cannot nest - use the Neo plugin ($) to nest fields
- Super Table can contain a Matrix field: Matrix > Super Table > Matrix
- a url field has no facility to link to pages on a site you have to let the user choose between a raw url or a page relationship - use Typed Link Field
- much more strict
- instead of
{% if items %}
use{% if items is defined %}
- instead of
{% for item in post.blocks %}
use{% set items = entry.blocks %}
then{% for item in items.all() %}
- Redactor: wysiwyg field
- Super Table: adds a repeater field of fields or
- Neo ($/yr): nested matrix fields, reuse fields
- Typed Link Field: allows users to create links to any Craft entries, assets etc or urls, emails, telephone links
- Wheelform: you can let it output the form for you are you can write custom walker to output each field
- Wordsmith: add QOL twig filters like widow prevention, split name into first name/last name, smart quotes, other markdown engines, more...
- Craft Commerce ($$$)
- Can't login?
- sudo chmod -R 777 storage
- sudo chmod 777 {web}/cpresources
- turn off ad blockers
- caching? https://nystudio107.com/blog/static-caching-with-craft-cms
- Permisions: https://github.com/nystudio107/craft-scripts