Web2Py è un framework Python semplice ma potente per lo sviluppo di applicazioni web. In questo tutorial mostreremo come installare il framework Web2Py su un VPS CentOS 7.
Cominciando dall'inizio. Una volta che hai il VPS, assicurati di aggiornarlo in modo da poter avere il software più recente.
# yum update
Crea la tua directory dell'applicazione. In questo esempio, lavoreremo nella directory /opt ma puoi usare una directory a tua scelta.
# mkdir /opt/web2pyapp # git clone --recursive https://github.com/web2py/web2py.git /opt/web2pyapp
Avremo bisogno di una chiave SSL e di un certificato per poter accedere in seguito all'interfaccia amministrativa. Per motivi di sicurezza, è meglio se li inseriamo in una directory diversa.
# mkdir /opt/web2pyapp_keys # cd /opt/web2pyapp_keys # openssl req -x509 -new -newkey rsa:4096 -days 3652 -nodes -keyout web2pyapp.key -out web2pyapp.crt Generating a 4096 bit RSA private key ......++ .......................................................++ writing new private key to 'web2pyapp.key' ----- You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [XX]:US State or Province Name (full name) []:Missouri Locality Name (eg, city) [Default City]:St. Louis Organization Name (eg, company) [Default Company Ltd]:Web2Py Organizational Unit Name (eg, section) []:Web2Py Common Name (eg, your name or your server's hostname) []:web2py.myvps.com Email Address []: ### Set proper privileges for the ssl certificate cd /opt # chmod 700 web2pyapp_keys # chmod -R 600 web2pyapp_keys/*
Se tutto viene eseguito correttamente in questo passaggio, ecco come dovrebbe il nostro layout in /opt
dovrebbe assomigliare.
# ls -l /opt total 8 drwxr-xr-x 13 root root 4096 Nov 12 11:21 web2pyapp drwx------ 2 root root 4096 Nov 12 11:04 web2pyapp_keys # ls -l /opt/web2pyapp total 1268 -rw-r--r-- 1 root root 214 Nov 12 09:46 ABOUT -rw-r--r-- 1 root root 12965 Nov 12 09:46 anyserver.py drwxr-xr-x 5 root root 4096 Nov 12 10:37 applications -rw-r--r-- 1 root root 747 Nov 12 09:46 appveyor.yml -rw-r--r-- 1 root root 65085 Nov 12 09:46 CHANGELOG drwxr-xr-x 2 root root 4096 Nov 12 10:01 deposit drwxr-xr-x 2 root root 4096 Nov 12 09:46 docs drwxr-xr-x 2 root root 4096 Nov 12 09:46 examples drwxr-xr-x 4 root root 4096 Nov 12 09:46 extras -rw-r--r-- 1 root root 6067 Nov 12 09:46 fabfile.py drwxr-xr-x 5 root root 4096 Nov 12 10:37 gluon drwxr-xr-x 2 root root 4096 Nov 12 09:46 handlers -rw-r--r-- 1 root root 18338 Nov 12 11:21 httpserver.log -rw-r--r-- 1 root root 5727 Nov 12 09:46 LICENSE drwxr-xr-x 2 root root 4096 Nov 12 10:01 logs -rw-r--r-- 1 root root 5684 Nov 12 09:46 Makefile -rw-r--r-- 1 root root 24 Nov 12 09:46 MANIFEST.in -rw------- 1 root root 756 Nov 12 11:10 nohup.out -rw-r--r-- 1 root root 92 Nov 12 11:20 parameters_8000.py -rw-r--r-- 1 root root 3896 Nov 12 09:46 README.markdown drwxr-xr-x 2 root root 4096 Nov 12 09:46 scripts -rw-r--r-- 1 root root 3320 Nov 12 09:46 setup.py drwxr-xr-x 2 root root 4096 Nov 12 09:46 site-packages -rw-r--r-- 1 root root 337 Nov 12 09:46 tox.ini -rw-r--r-- 1 root root 52 Nov 12 09:46 VERSION -rwxr-xr-x 1 root root 900 Nov 12 09:46 web2py.py -rw-r--r-- 1 root root 1089202 Nov 12 10:01 welcome.w2p # ls -l /opt/web2pyapp_keys total 8 -rw------- 1 root root 2057 Nov 12 09:52 web2pyapp.crt -rw------- 1 root root 3272 Nov 12 09:52 web2pyapp.key
Siamo pronti per avviare il nostro server di applicazioni Python ora.
# python /opt/web2pyapp/web2py.py -a 'STRONG-PASSWORD-HERE' -k /opt/web2pyapp_keys/web2pyapp.key -c /opt/web2pyapp_keys/web2pyapp.crt -i 0.0.0.0 -p 8000 web2py Web Framework Created by Massimo Di Pierro, Copyright 2007-2016 Version 2.14.6-stable+timestamp.2016.05.09.19.18.48 Database drivers available: sqlite3, imaplib, pymysql, pg8000 please visit: https://127.0.0.1:8000/ use "kill -SIGTERM 1284" to shutdown the web2py server
IMPORTANTE: Assicurati di inserire la tua password complessa dopo il -a
flag.
Apri un browser web e inserisci https://VPS-IP-ADDRESS:8000/
nella barra di navigazione, dove VPS-IP-ADDRESS è il tuo indirizzo IP VPS.
Accetta l'avviso del certificato e dovrebbe apparire la pagina di benvenuto di Web2Py. Per accedere al back-end di amministrazione, clicca su mysites e inserisci la tua password, quella che hai utilizzato all'avvio del webserver.
Per fermare il server web usa il CTRL+C key
combinazione.
Evitare il terminale aperto per mantenere in vita il server Web2Py
Poiché il servizio Web2Py richiede un terminale aperto per essere attivo, un'opzione che puoi utilizzare se desideri uscire dal terminale e continuare a lavorare, è usare la e commerciale alla fine del comando dopodiché puoi uscire dalla sessione SSH.
# python /opt/web2pyapp/web2py.py -a 'Password01' -k /opt/web2pyapp_keys/web2pyapp.key -c /opt/web2pyapp_keys/web2pyapp.crt -i 0.0.0.0 -p 8000 & [1] 1468
Per arrestare il server, utilizza l'ID processo fornito all'avvio del server:
# kill -9 1468
Tieni presente che in questo modo potresti perdere errori o avvisi importanti che potrebbero essere visualizzati sul server durante lo sviluppo.
Ovviamente, non devi fare nulla di tutto ciò se utilizzi uno dei nostri servizi di hosting VPS Python, nel qual caso puoi semplicemente chiedere ai nostri esperti amministratori Linux di installare Web2Py per te. Sono disponibili 24 ore su 24, 7 giorni su 7 e si prenderanno immediatamente cura della tua richiesta.
PS . Se questo post ti è piaciuto condividilo con i tuoi amici sui social network utilizzando i pulsanti a sinistra o semplicemente lascia una risposta qui sotto. Grazie.