How to use Python 3 and Django with Apache?

前端 未结 5 1999
北恋
北恋 2021-02-04 13:27

My goal is to set up Python 3 with Apache. My biggest problem is actually acquiring mod_python.so. For the life of me I found only one site where it could be downloaded (http://

5条回答
  •  甜味超标
    2021-02-04 13:38

    I faced a similar problem and here is how I solved it: To Install LAMP:

       sudo apt-get install lamp-server^
     // then do more from here:
       //https://help.ubuntu.com/community/ApacheMySQLPHP
     // If you will run python services then : 
           apt-get install python-mysqldb 
    //and for python 3 install: 
       sudo apt-get install python3-pip python-dev build-essential
       pip3.4 install mysqlclient  // for mysql       connection 
       sudo apt-get install build-essential python-dev libmysqlclient-dev
    
       pip3 install virtualenvwrapper
       sudo nano ~/.bash_profile
      //Set location of virtualenvs by pasting this in above: 
       export WORKON_HOME=$HOME/.virtualenvs 
       source /usr/local/bin/virtualenvwrapper.sh
    //Reload startup file:
      source ~/.bash_profile
       mkvirtualenv -p /usr/bin/python3 myprojectenv
       workon myprojectenv
    //then you can install packages you want using pip
    //and copy myproject here
    

    To DEPLOY a Django 1.7 App on Ubuntu 14.04 LTS server with python3 and apache:

       sudo apt-get install libapache2-mod-wsgi-py3
     //then configure your apache virtualhosts( here our project is   //myproject    and environment is myprojectenv):
    

    Configure your virtual host in Daemon mode which is recommended:

    
        ServerName yourdomain.com
        ServerAdmin youradmin@yourdomain.com
    
        DocumentRoot /home/user/.virtualenvs/myprojectenv/public_html
    
    
        
    
         
         Require all granted
        
        
    
        ErrorLog /home/user/.virtualenvs/myprojectenv/logs/error.log
        CustomLog /home/user/.virtualenvs/myprojectenv/logs/access.log  combined
        WSGIScriptAlias /  /home/user/.virtualenvs/myprojectenv/myproject/myproject/wsgi.py
    
        WSGIDaemonProcess myproject python- path=/home/user/.virtualenvs/myprojectenv/prisec:/home/user/.virtualenvs/m yprojectenv/lib/python3.4/site-packages
    
        WSGIProcessGroup myproject
        Alias /static /home/user/.virtualenvs/myprojectenv/public_html/static
    
        
         Require all granted
        
         Alias /media
      /home/user/.virtualenvs/myprojectenv/public_html/media
           
         Require all granted
        
    

    Restart Apache . the directories in virtualhost configuration file must exist in the virtual environment created.

提交回复
热议问题