]> BookStack Code Mirror - website/blob - content/docs/admin/commands.md
323baae1d33757cc1d5c348dcb44745c0022ebe3
[website] / content / docs / admin / commands.md
1 +++
2 title = "Commands"
3 description = "BookStack command-line actions"
4 date = "2017-02-26"
5 type = "admin-doc"
6 +++
7
8 BookStack has some command line actions that can help with maintenance and common operations. There are also many commands available from the underlying Laravel framework. To list all available commands you can simply run `php artisan` from your BookStack install folder. Custom BookStack commands are all under the 'bookstack' namespace.
9
10 Below is a listing of the BookStack specific commands. For any you can provide a `-h` option to list details and options for the command.
11
12 {{<toc>}}
13
14 ### Create an Admin User
15
16 Create a new admin user via the command line. Can offer a good last resort if you ever get locked out the system.
17 Will use the details provided as options otherwise will request them interactively.
18
19 ```bash
20 # Interactive usage
21 php artisan bookstack:create-admin
22
23 # Non-interactive usage example
24 php artisan bookstack:create-admin --email="[email protected]" --name="Bazza" --password="hunter2"
25
26 # Defining "External Authentication ID" instead of password for LDAP/SAML2/OIDC environments
27 php artisan bookstack:create-admin --email="[email protected]" --name="Bazza" --external-auth-id="bbooker"
28 ```
29
30 ### Copy Shelf Permission
31
32 By default shelf permissions will not auto-cascade since a book can be in many shelves.
33 This command will copy the permissions of a shelf to all child books.
34 This can be done for a single shelf or for all shelves in the system:
35
36 ```bash
37 # Run for all shelves
38 php artisan bookstack:copy-shelf-permissions --all
39
40 # Run for a single shelf
41 php artisan bookstack:copy-shelf-permissions --slug=my_shelf_slug
42 ```
43
44 ### Update System URL
45
46 BookStack will store absolute URL paths for some content, such as images, in the database.
47 If you change your base URL for BookStack this can be problematic.
48 This command will essentially run a find & replace operation on all relevant tables in the database.
49 Be sure to take a database backup for running this command.
50
51 ```bash
52 # Searches for <oldUrl> and replaces it with <newUrl>
53 php artisan bookstack:update-url <oldUrl> <newUrl>
54
55 # Example:
56 php artisan bookstack:update-url http://docs.example.com https://demo.bookstackapp.com
57 ```
58
59 ### Reset User MFA Methods
60
61 This will reset/clear any existing multi-factor-authentication methods for the given user. If MFA 
62 is enforced for one of their roles they'll be prompted to reconfigure MFA upon next login.
63
64 ```bash
65 # Via email address:
66 php artisan bookstack:reset-mfa [email protected]
67
68 # Via system ID:
69 php artisan bookstack:reset-mfa --id=5
70 ```
71
72 ### Delete All Activity History
73
74 This will clear all tracked activities in the system. Note: Some areas of the interface rely on this data, including the Audit Log and any "Recent Activity" lists.
75
76 ```bash
77 php artisan bookstack:clear-activity
78 ```
79
80 ### Delete Page Revisions
81
82 By default this deletes all page revisions apart from page update drafts which share the same system.
83 A `-a` flag can be used to also delete these update drafts.
84
85 ```bash
86 # Delete just the page revisions
87 php artisan bookstack:clear-revisions
88
89 # Delete all page revisions from the system including update drafts
90 php artisan bookstack:clear-revisions -a
91 ```
92
93 ### Delete Page Views
94
95 Delete tracked content views from the system. These are primarily used to populate any "Recently Used" lists.
96
97 ```bash
98 php artisan bookstack:clear-views
99 ```
100
101 ### Cleanup Unused Images
102
103 Searches and removes images that are not used in page content.
104 While this can be done in the "Maintenance" section of the interface, running this via the command-line is often safer to avoid timeouts.
105
106 ```bash
107 php artisan bookstack:cleanup-images
108 ```
109
110 ### Regenerate the Search Index
111
112 BookStack uses a custom database-based search index system for efficient
113 querying within the system. The command below re-builds this search index.
114 This does not usually need to be manually ran, but it can be useful if manually inserting pages into the system or to pick-up BookStack indexing changes.
115
116 ```bash
117 php artisan bookstack:regenerate-search
118 ```
119
120 ### Regenerate Access Permissions
121
122 BookStack pre-calculates and stores certain access permissions in the database
123 so that access can be calculated in a performant manner.
124 The below command will regenerate these permissions.
125 This is primarily used in development but can be useful if manually adding content via the database.
126
127 ```bash
128 php artisan bookstack:regenerate-permissions
129 ```
130
131 ### Regenerate Reference Index
132
133 BookStack stores references between content within the system to track how
134 content is interlinked. Such references are generally managed by BookStack
135 upon certain actions, such as when saving a page, but in some cases the 
136 below command may help to re-index these references. 
137 This can be useful upon upgrade of old content, or when manually adding content via the database.
138
139 ```bash
140 php artisan bookstack:regenerate-references
141 ```
142
143 ### Regenerate Comment Content
144
145 Comments are created and stored in Markdown but also rendered to HTML on save.
146 This command will regenerate the stored HTML content for all comments using the original Markdown content.
147
148 ```bash
149 php artisan bookstack:regenerate-comment-content
150 ```
151
152 ### Delete Users
153
154 Delete all users from the system that are not original "admin" or system-level users.
155
156 ```bash
157 php artisan bookstack:delete-users
158 ```
159
160 ### Generate UTF8mb4 SQL Upgrade Commands
161
162 Generates out the SQL which can be used to upgrade the database to UTF8mb4.
163 See [UTF8mb4/Emoji Support](/docs/admin/ut8mb4-support/) for further details.
164
165 ```bash
166 php artisan bookstack:db-utf8mb4
167 ```