CTFd platform construction (file method)

Record the pits you stepped on in the process of building.
There is no cloud server, and I built it in a virtual machine. I used Ubuntu16.04.7LTS to
view the current version of the command: cat /etc/issue
Then I found that my virtual machine can’t connect to the Internet. Try it again. It is NAT mode.
Insert picture description here
Note that it can only be changed by giving it administrator rights.

You can start after connecting to the Internet
1. Upgrade source

sudo apt-get update

An error may be reported when upgrading the source.
Insert picture description here
I forgot to take the screenshot myself. Use the pictures from the online blog.
In this case, the update failed because the US server cannot be connected, and the source server needs to be set to China in the system settings. of.
Insert picture description here
This should be fine. If you happen to encounter the error "Failed to fetch 404 Not Found", please refer to the blog at https://www.cnblogs.com/wangshaowei/p/10994764.html and say It is because every Ubuntu version has an end-of-life cycle (EOL) time. The regular Ubuntu distribution provides 18 months of support, while the LTS (long-term support) version is up to 3 years (server version) and 5 years (desktop) version). When a certain Ubuntu version reaches the end of life cycle, its warehouse can no longer be accessed, and you can no longer get any maintenance updates and security patches from Canonical. If the Ubuntu system you are using has ended its life cycle, you will get the following 404 error from apt-get or aptitude because its warehouse has been abandoned.

The solution is to replace the source in the /etc/apt/sources.list path with the source of the old version of the repository.

2. Install git, because the source code of CTFd and the deployed topic are all transmitted through github

sudo apt install git

3. Install pip

sudo apt install python-pip

There are also some problems when installing pip. If there is an abnormality, you can upgrade pip

sudo python -m pip install --upgrade pip

4. Install Flask, because CTFd is built based on the Flask framework, so you need to install Flask to build CTFd

sudo pip install Flask

5. Download CTFd

sudo git clone https://github.com/isislab/CTFd.git

6. Install CTFd

cd CTFd
sudo ./prepare.sh

After the second command is executed, you may encounter warnings and errors. Here is a step-by-step description of how to solve
Insert picture description here
this problem because of the Python version. Ubuntu comes with versions 2.7 and 3.5 of Python, and version 2 will be available in January 2020. The maintenance is stopped, and future pip versions will drop support for Python 2.7. We need to change the version of 2 to 3.

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150

We can use these two commands to change 2 to 3 and
check it after the change

python --version

This command can see the current version of Pyhton, but it may be inaccurate, because it can be displayed by changing the point, but the environment cannot be changed to 3, and the environment variables are related to the default and
can be determined by viewing the environment. The following command

env python

If the version displayed at this time is 3, then it has been successfully changed.
Next, we need to install its pip for 3, otherwise it will appear
/usr/bin/python3: No module named pip
will also appear such an error.
Insert picture description here
Download and install pip The method is very simple, just download it from the official website in the virtual machine and install it according to the instructions. Note that you should use the sudo command, otherwise the installation will fail if you don't have permission.

There may be such a warning.
Insert picture description here
This should be solved by executing the following command

sudo chown -R root /home/$USERNAME/.cache/pip/
sudo chown -R root /home/$USERNAME/.cache/pip/http/

Then we executed the command to install CTFd and found that it had a new error
Insert picture description here
. After checking the official documentation of pydantic , we found that it was also due to the problem of the Pyhton version. It needs 3.6 and above to be able to support it. Python comes with the highest version. only 3.5, which requires the upgrade
can refer to this blog, the method is very effective, but also how to provide after installation Python3.6 prevent collapse
https://segmentfault.com/a/1190000021838605
attach screenshots to prevent failure
Insert picture description here
if not careful really put Ubuntu crashed and the terminal box could not be opened. You can also refer to this blog
https://blog.csdn.net/DeepWolf/article/details/88800603

This blog also introduces the installation method of Python 3.6 and how to change the environment. You must remember to change the environment, otherwise you will still be unable to succeed.
https://blog.csdn.net/qq_32216809/article/details/86347926

Then execute the command to install CTFd and there should be no problem

7. Run CTFd (to be executed after the command to open the CTFd file (cd CTF))

sudo python serve.py

Visit 127.0.0.1:4000/ in the browser of the virtual machine and you can see your CTFd platform. The
Insert picture description here
disadvantage is that the access speed is very slow... It is still unclear how to solve it. This blog may be able to help.
https://blog.csdn.net/weixin_43880435/article/details/107339592?utm_source=app

If you want it to be accessed on a physical machine, you need to install gunicorn and specify the mapped port.
I tried it but failed. You can try it.

sudo pip install gunicorn
sudo gunicorn --bind 0.0.0.0:8000 -w 1 "CTFd:create_app()"
sudo pip install gunicorn

Regarding the slow speed, you can try this
https://blog.csdn.net/asd413850393/article/details/98123982

Well, the above is the whole process of building this time, I have encountered many problems, next time I try to build it with docker~

Guess you like

Origin blog.csdn.net/AlienEowynWan/article/details/108551745