Jump to content

heirloom

Members
  • Posts

    20
  • Joined

Posts posted by heirloom

  1. Nice, it's good to know that I can run flask from the web root. That's not what I'm asking though. I want to keep flask in the subdirectory. But the routes of my app don't take into account that subdirectory so I need a way to append '/flask/' to all routes without actually having to change them one by one in the code.

  2. I have an app with static paths like this:

    import sys
    import platform
    
    from flask import Flask, __version__
    app = Flask(__name__)
    
    @app.route("/")
    def hello():
        return """
            Hello World!<br><br>
            <a href="/info/">System Information</a>
        """
    
    @app.route("/info/")
    def info():
        return f"""
            Platform: {platform.platform()}<br>
            Python version {sys.version}<br>
            Flask version: {__version__}
        """
    
    if __name__ == "__main__":
        app.run()

    But when I use it in heliohost the links have to be prefixed with '/flask/'. Is there a way to do this without having to change all the links in the application?

  3. In the WSGIScriptAlias the alias should be '/' or else all links inside the application will have to include '/flask/path' and changing all the links in the application is not easy unless you've made them relative to a specific url that you can easily change. This has be done for heliohost anyway.

     

    This problem has an answer in Path configuration problem with mod_wsgi - WSGIScriptAlias

     

    The way in which the Tommy server is configured is probably using the technique explained there.

  4. Actually the installed mod_wsgi was using Python 2.7. So I need a way to install the correct version of mod_wsgi.

     

    After installing the correct version of mod_wsgi I no longer have to include the location of the packages. mod_wsgi is now using the default Python3 which is 3.6.8. I couldn't get it to run with 3.7.4, even when installing it with --enable-shared it gave 'Error while loading shared libraries' unless I specified the location of the packages in the code like:

    import site
    
    site.addsitedir('/usr/local/lib/python3.7/site-packages')
    site.addsitedir('/usr/local/lib64/python3.7/site-packages')

    Install mod_wsgi 4.6.7 with python 3.7.4 in CentOs 7

  5. I've had some trouble configuring the 'flask' folder. I don't know why I've had to include the location of the python packages in the wsgi file. Or else it said:

    Exception occurred processing WSGI script '/var/www/flask/myapp.wsgi'.
    Traceback (most recent call last):
        File "/var/www/flask/myapp.wsgi", line 6, in <module>
            from myapp import app as application
        File "/var/www/flask/myapp/__init__.py", line 1, in <module>
            from flask import Flask
    ImportError: No module named flask

    Also although I've installed python 3.7.4 I had to end up using the default Python 3, which is 3.6.8, because I didn't know how to use pip without installing the default. And I couldn't install mod_wsgi from source because it gave me an error, that was something like: 'apxs command not found'. Probably I forgot some dependency.

     

    Here I write all the commands I used to deploy flask apps with apache in centos in a similar way as how the Tommy server does it:

    # VirtualBox guest additions

    sudo yum install -y epel-release centos-release-scl

    sudo yum update -y

    sudo yum install -y make gcc kernel-headers kernel-devel perl dkms bzip2

    # Devices -> Insert Guest Additions CD image and run it

    sudo reboot

    sudo yum install -y dconf-editor

    bash <(curl -s https://raw.githubusercontent.com/ajr-dev/post-install-script/master/install/settings/gnome.sh)

     

    # Install apache

    sudo yum install -y httpd httpd-devel python3 python3-pip python3-devel

    sudo systemctl start httpd

    sudo systemctl enable httpd

     

    # Install mod_wsgi 4.6.7

    wget -q "https://github.com/GrahamDumpleton/mod_wsgi/archive/4.6.7.tar.gz"

    tar -xzf '4.6.7.tar.gz'

    rm '4.6.7.tar.gz'

    cd 'mod_wsgi-4.6.7'

    ./configure --with-python=/usr/local/bin/python3

    make

    sudo make install

     

    # Add this to `/etc/httpd/conf/httpd.conf`

    # LoadModule wsgi_module modules/mod_wsgi.so

    apachectl restart

    sudo cat /var/log/httpd/error_log

    # If all is okay, you should see a line of the form:

    # Apache/2.4.6 (CentOS) mod_wsgi/4.6.7 Python/3.6 configured

     

    cd ..

    sudo rm -rf 'mod_wsgi-4.6.7'

    apachectl restart

    # Flask Deploy with Apache on CentOS

    sudo pip3 install flask==1.1.1
    cd /var/www

    sudo mkdir flask

    cd flask

    sudo mkdir website

     

    sudo vi __init__.py

    from flask import Flask
    app = Flask(__name__)
    

    sudo vi main.py

    import sys
    import platform
    
    from website import app
    
    def linux_distribution():
        try:
            return platform.linux_distribution()
        except:
            return "N/A"
    
    @app.route("/")
    def hello():
        return """
            Hello World!<br><br>
            <a href="/flask/info/">System Information</a><br>
        """
    
    @app.route("/info/")
    def info():
        return f"""
            Python version: {sys.version}<br>
            dist: {platform.dist()}<br>
            linux_distribution: {linux_distribution()}<br>
            system: {platform.system()}<br>
            machine: {platform.machine()}<br>
            platform: {platform.platform()}<br>
            uname: {platform.uname()}<br>
        """"
    
    if __name__ == "__main__":
        app.run(debug=True)

    sudo vi website.wsgi

    import sys
    sys.path.insert(0, '/var/www/flask')
    
    from website import main, app as application

    cd /etc/httpd/conf/

    sudo cp httpd.conf httpd.conf.bak

    sudo vi httpd.conf

    Insert:

    <VirtualHost *:80>
        ServerName localhost
        WSGIScriptAlias /flask /var/www/flask/website.wsgi
        <Directory /var/www/flask>
            Require all granted
        </Directory>
    </VirtualHost>

    apachectl restart

     

    # Get IP

    hostname -I

     

    # When visiting 'http://my_host_ip/flask' you should see 'Hello World!'

    # If you are getting an error you can see it by doing

    sudo cat /var/log/httpd/error_log

  6. I'm having trouble debugging the code from a github repository that works on my machine, but I can't make it work on the server. So I would like to make a virtual machine with the same os and applications to be able to debug the code. I'm doing a flask website. What are the applications that Tommy has installed to deal with flask? Which os? How to install wsgi?

  7. Nevermind I see that I already imported the modules when I imported the code.
     

     

    Terminal access is not available on HelioHost, however, an admin can install the required Node.js modules for you. Make a separate post requesting the installation of the modules.

    That's not the case with Node.js.

     

    @filmegoo: You need to download the modules locally using NPM and then compress the node_modules folder to a zip file and upload it to your Node.js folder. After that, extract the file.

  8. I just want to check a script I want to run to make sure it's ok. I want to cd to the flask folder and then run 'python3 dev.py build' so the script that I've made is:

    `cronjob1.sh` in `$HOME/cronjobs` folder with execute permissions.

    #!/bin/bash
    
    cd "$HOME/public_html/flask/"
    /usr/bin/python3.7 dev.py build
    
    

    And then the cronjob would be:

    $HOME/cronjobs/cronjob1.sh > $HOME/logs/`date +\%Y\%m\%d\%H\%M\%S`-cron.log 2>&1

    dev.py will install pip requirements and npm modules for the project that I've uploaded to work. You think it's ok like that?

  9. Yesterday I tried signing up in a server and when in the password selection page it didn't let me press next to finish. It happened in Tommy, Ricky and Johnny. I used the same username, domain and password for all three:

    name: heirloom

    domain: heirloom.heliohost.org

     

    I didn't receive any error so I don't know what the problem might be. Thank you.

  10. Edit: Sorry I didn't see my previous post had been escalated I thought it had dissappeared. You can delete this one. I don't think I can delete it.

     

    I'd like to reuse the domain I used in a previous account which has been backed up and taken offline due to extended maintenance. I've already asked in discord and when I tried to login again with the new email activation, I received the same message about the account being backed up. sohamb03 from discord told me to ask here for the domain to be released. I've already downloaded the backup server.

     

    I want either to use the same domain in another account or better yet use the same domain with the same account, I don't mind if I have to sign up again if you have to delete it.

     

    username: heirloom

    server: Johnny

    domain: heirloom.heliohost.org

  11. I need a step by step tutorial on how to run a Python script as cron job with all the things that have to be done in preparation and all the paths with a example script. I'd like the script to work in a directory different than the public one if possible. /home/heirloom/database/main.py.The first line of the python file is #!/usr/bin/env python. Is it correct? And the permissions 755. Where do I see that I actually have python in johnny? Also when I write the cron job for a specific hour the time would be UTC?

     

    Try to use this script as an example so I can see if the script actually worked:

     

    /home/username/hello.py

    #!/usr/bin/python
    with open('hello.text','w+') as f:
        f.write('Hello server!')
    cron job to execute the script at 9:15 UTC. It didn't work in my case, I created it at 9:13.

    15 9 * * *  cd /home/username ; /usr/bin/python hello.py
    Do I need a cron job to run the script? I've read perl scripts can be executed by clicking on them.

    In this web http://www.heliohost.org/classic/features/languages/python what does 'output a Content-type header before anything else' mean. I'm not creating a web with python I just want to print 'Hello' in a file. I've found a tutorial that explains how to run scripts via cron jobs.

     

    I followed this tutorial which is exactly the kind of tutorial that there should be in the heliohost wiki. But everything worked fine till the part when it explains how to execute the script in another directory. The problem with executing my script in a public directory is that anyone could be updating the database and I only want to update it once a month because of the overhead. In the tutorial it says:

     

    If you would like to run the Python file not in the cgi-bin folder (in public_html or any other directory), it is necessary to add the following code to the .htaccess file in the same directory where the Python script is placed:

     

    Options +ExecCGI

    AddHandler cgi-script .py

    But it doesn't say how to do that. And cPanel doesn't allow me to choose the directory in which to add the handler. Here it says that I have to add the following to httpd.conf (in my case would be):

    <Directory /home/heirloom/database />
      Options +ExecCGI
      AddHandler cgi-script .py
      Order allow,deny
      Allow from all
    </Directory>
    
    But I can't change that file so if an admin could add that to the httpd.conf file. I'd also need around 10 cron jobs a day for testing and when I know how to use it I'm good with one every month.

    Server: johnny

    User: heirloom

×
×
  • Create New...