Prerequisites
You should have your LAMP or LEMP stack up and running and a MySQL or Postgres database created for Craft.
1. Install Composer
If you already have Composer installed, skip to Step 2,
Firstly, let’s update the package database.
sudo apt update
Next, install the required packages
sudo apt install curl php-cli php-mbstring git unzip
You also need the zip extension for PHP. Ensure to replace php7.0
with your own version of PHP. If you don’t know what version you have, run php -version
sudo apt install php7.0-zip
Composer provides an installer, written in PHP. Make sure you’re in your home directory, and retrieve the installer using curl
:
cd ~
Install
curl -sS https://getcomposer.org/installer -o composer-setup.php
To install composer globally, use the following:
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
All settings correct for using Composer
Downloading... Composer (version 1.6.5) successfully installed to: /usr/local/bin/composer Use it: php /usr/local/bin/composer
Once installed, you can check the version
composer -V
Composer version 1.6.5 2018-05-04 11:44:59
2. Install Craft
You should now decide where you want to install Craft. We normally install it in somewhere like /var/www/domain.com/craft
sudo composer create-project craftcms/craft PATH_HERE
We are running Composer with sudo because if the PATH does not already exist, you may get an error [RuntimeException] Could not delete path
. Note that normally you should never run Composer as root for apps you don’t trust.
On success, you should see
______ .______ ___ _______ .___________.
/ || _ \ / \ | ____|| |
| ,----'| |_) | / ^ \ | |__ `---| |----`
| | | / / /_\ \ | __| | |
| `----.| |\ \----./ _____ \ | | | |
\______|| _| `._____/__/ \__\ |__| |__|
A N E W I N S T A L L
______ .___ ___. _______.
/ || \/ | / |
| ,----'| \ / | | (----`
| | | |\/| | \ \
| `----.| | | | .----) |
\______||__| |__| |_______/
Generating a security key... done (UwYczEAKvxkbfdgf5es3h2T4x_yEK)
Welcome to Craft CMS! Run the following command if you want to setup Craft from your terminal:
/var/www/devtest1.com/craft setup
To view the directory structure.
ls -l /var/www/devtest1.com/craft
total 140
-rw-r--r-- 1 root root 1012 May 18 19:26 composer.json
-rw-r--r-- 1 root root 95914 Jun 2 12:00 composer.lock
drwxr-xr-x 3 root root 4096 May 18 19:26 config
-rwxr-xr-x 1 root root 577 May 18 19:26 craft
-rw-r--r-- 1 root root 330 May 18 19:26 craft.bat
-rw-r--r-- 1 root root 1081 May 18 19:26 LICENSE.md
drwxr-xr-x 2 root root 4096 May 18 19:26 modules
-rw-r--r-- 1 root root 1464 May 18 19:26 README.md
drwxr-xr-x 4 root root 4096 Jun 2 12:00 storage
drwxr-xr-x 2 root root 4096 May 18 19:26 templates
drwxr-xr-x 27 root root 4096 Jun 2 12:00 vendor
drwxr-xr-x 3 root root 4096 Jun 2 12:05 web
The “web” directory is the document root. You can change this to whatever you want, for example public_html, etc.
You must update your Apache or Nginx configuration and ensure it is pointing to the correct document root.
3. Configure Craft
Change to the craft directory.
cd /var/www/devtest1.com/craft
Run the Craft setup.
sudo ./craft setup
You will be asked a series of questions next about database details. You can press ENTER
for defaults.
Which database driver are you using? [mysql,pgsql,?]: mysql
Database server name or IP address: [localhost] localhost
Database port: [3306]
Database username: [root]
Database password:
Database name: devtest1_craft
Database table prefix: craft
Testing database credentials... success!
Saving database credentials to your .env file... done
Install Craft now? (yes|no) [yes]:
Username: [admin]
Email: [email protected]
Password:
Confirm:
Site name: DevTest1
Site URL: [@web] devtest1.com
Site language: [en-US]
*** installing Craft
> create table ......
*** installed Craft successfully (time: 3.781s)
You should now be able to access the admin panel at https://devtest1.com/index.php?p=admin
If you are using Nginx, you should add the following location handlers.
# Root directory location handler
location / {
try_files $uri/index.html $uri $uri/ /index.php?$query_string;
}
# Craft-specific location handlers to ensure AdminCP requests route through index.php
location ^~ /admin {
try_files $uri $uri/ /index.php?$query_string;
}
For more information about Nginx configuration, please read here.
Let me know if this helped. Follow me on Twitter, Facebook and YouTube, or 🍊 buy me a smoothie.
Manually installing the whole stack and then installing the craft cms is really time taking. Some craft cms hosting provide pre-configured servers with stack already installed which saves quite a lot of time.