# pip3 install virtualenv<\/pre>\nOnce the virtual environment is installed, you can proceed with creating the Wagtail virtual environment. We’re naming it ‘wagtailvenv’, but you can call it whatever you like.<\/p>\n
# su - rh\r\n$ virtualenv wagtailvenv\r\n<\/pre>\nThe command will create a virtual environment in \/home\/rh\/wagtailvenv<\/code>.<\/p>\n<\/span>Step 4: Install Wagtail in virtualenv<\/span><\/h2>\nWhile we are still logged in as the “rh” user, we are now going to install Wagtail onto the virtual environment that we created earlier:<\/p>\n
$ source ~\/wagtailvenv\/bin\/activate<\/pre>\nAs you can see onscreen, your SSH terminal prompt has changed to the virtual environment prompt:<\/p>\n
<\/p>\n
You are now in the virtual environment – let’s proceed with the Wagtail installation.<\/p>\n
(wagtailvenv) rh@rose:~$ pip install wagtail<\/pre>\nPay attention to the command – even if we are using Python 3 while in the Python virtual environment, please use the ‘pip’ command instead of ‘pip3’. This is because the virtual environment tool is always named pip, regardless of the Python version we use.<\/p>\n
<\/span>Step 5: Create a Wagtail project<\/span><\/h2>\nWagtail has now been installed under the “rh” user. Now, let’s create an example project:<\/p>\n
(wagtailvenv) rh@rose:~$:~$ cd ~\r\n(wagtailvenv) rh@rose:~$:~$ wagtail start newproject\r\n<\/pre>\nThe command will create a project named “newproject”, and this will also create a “newproject” directory in \/home\/rh\/<\/code>.
\nNext, run the following commands to start the new project.<\/p>\n(wagtailvenv) rh@rose:~$:~$ cd newproject\r\n(wagtailvenv) rh@rose:~$:~$ python manage.py migrate\r\n(wagtailvenv) rh@rose:~$:~$ python manage.py createsuperuser\r\n(wagtailvenv) rh@rose:~$:~$ python manage.py runserver 0.0.0.0:8000\r\n<\/pre>\nWhen creating the superuser, you will be asked for a password and email address – please provide the credentials.<\/p>\n
Now, open your favorite web browser and navigate to your IP_address:8000. In this example, we installed Wagtail on 192.168.1.231 so we need to go to http:\/\/192.168.1.231:8000<\/code>\u00a0in order to see the web interface. Here’s what it looks like:<\/p>\n<\/p>\n
You can reach the Wagtail administration page at http:\/\/192.168.1.231:8000\/admin<\/code> – use the credentials you chose when creating the Wagtail superuser in the previous step.<\/p>\n<\/p>\n
<\/span>Step 6: Install Gunicorn<\/span><\/h2>\nTo manage the Wagtail application better, we need to install Gunicorn. Gunicorn is a python “Web Server Gateway Interface” (WGSI) HTTP server. It is a pre-fork worker model, ported from Ruby’s Unicorn project. The Gunicorn server is broadly compatible with a number of web frameworks, can be simply implemented, is light on server resources, and is fairly fast. Install it by running these commands:<\/p>\n
(wagtailvenv) rh@rose:~$ pip install gunicorn\r\n(wagtailvenv) rh@rose:~$ cd ~\/newproject\r\n(wagtailvenv) rh@rose:~$ python manage.py collectstatic\r\n(wagtailvenv) rh@rose:~$ deactivate\r\n(wagtailvenv) rh@rose:~$ exit<\/pre>\nWhat we’ll be doing now is making Gunicorn a system service, that way we can start and stop it at will using ‘systemctl’. Now, create this file using your preferred text editor and make sure that the contents of your configuration file match the contents of this example. Of course, don’t forget to change the username to the name of your admin account:<\/p>\n
# nano \/etc\/systemd\/system\/gunicorn.service<\/pre>\n[Unit]\r\nDescription=gunicorn daemon\r\nAfter=network.target\r\n\r\n[Service]\r\nUser=rh\r\nGroup=www-data\r\nWorkingDirectory=\/home\/rh\/newproject\r\nExecStart=\/home\/rh\/wagtailvenv\/bin\/gunicorn --access-logfile - --workers 3 --bind unix:\/home\/rh\/newproject.sock newproject.wsgi:application\r\n\r\n[Install]\r\nWantedBy=multi-user.target<\/pre>\nAfter the changes have been made, save and exit the file, then reload all daemons so that the new configuration file is acknowledged:<\/p>\n
# systemctl daemon-reload<\/pre>\nNow, we can start\/stop\/restart the Wagtail application using the systemctl command:<\/p>\n
# systemctl start gunicorn<\/pre>\nIf you want to run it on boot, we’ll need to enable it:<\/p>\n
# systemctl enable gunicorn<\/pre>\n