Mac OSX deploys the Django project above Apache+mysql+mod_wsgi

Source: Internet
Author: User
Tags install homebrew django website web hosting phpmyadmin

1. Install Xcode command line tools

First, compiling MySQL and homebrew requires the use of Xcode command line tools, so first install command line tools;

If you have Xcode installed, just "Preferences ... > Downloads", then click the command line tools install button;

If you don't have Xcode, go to https://developer.apple.com/downloads, search command line Tools to download the installation

2, install homebrew (need to use homebrew installation Mod_wsgi), in the Command line window input

" $ (curl-fsskl raw.github.com/mxcl/homebrew/go) "

3. Configure Apache

Apache is installed by default in Mac OSX, OSX 10.10 installs the Apache version is 2.4, open terminal input

sudo apachectl start

Open Browser inputhttp://localhost/,你能看到‘It Works’

3.1 Enable mod_php

Enable mod_php in Apache

cd/etc/apache2sudovi httpd.conf

Do not comment on this line (remove the previous # #)

# LoadModule Php5_module libexec/apache2/libphp5.so

Copy Php.ini.default to php.ini, give php.ini Write permission after copy

cd/etc/sudocp Php.ini.default php.ini
sudo chmod +w php.ini
sudo vi php.ini

In the php.ini file, change the MySQL Unix socket (Note that if you install MARIADB by homebrew The default is/tmp/mysql.sock) (there should be three places).

Xxx.default_socket=/tmp/mysql.sock

Test Apache configuration OK, restart Apache

Apachectl configtest sudo apachectl graceful

If the servername issue is displayed at this point, open/etc/apache2/httpd.conf, locate servername, and set it to localhost

3.2 Configuring a virtual Host

We're going to configure the virtual host on Apache, which will provide a framework for managing multiple websites on your Mac. I usually put the document root directory in ~/sites/,

We will create the document root directory for our website under Sites ~/sites/mysite.com, only the static content of the Django app site is placed under ~/sites/mysite.com, the Django project

Put it in ~/documents/mysite.

cd/etc/apache2sudovi httpd.conf

Do not comment on this line

#Include/private/etc/apache2/extra/httpd-vhosts.conf

Test Apache Configuration OK

Apachectl Configtest

The result should be

Warning:documentroot [/usr/docs/dummy-host.example.com] does not existwarning:documentroot [/usr/docs/ dummy-host2.example.com] does not existsyntax OK

All of the above is OK, we will configure the virtual host configuration file

sudo VI

Replace the contents of the httpd-vhosts.conf file with the following, a good template for the virtual host configuration file

include/private/etc/apache2/extra/vhosts//private/etc/apache2/extra/vhosts/dev.mysite.com.conf

For each new website, there is a corresponding Apache configuration file. Our Django website is going to be in http://dev.mysite.com and we will manage this site on Apache web hosting files

If we want to manage other websites, we just need to add the following line

include/private/etc/apache2/extra/vhosts//private/etc/apache2/extra/vhosts//private/etc/ apache2/extra/vhosts//private/etc/apache2/extra/vhosts/dev.mysite5.com.conf

Create a virtual host configuration file for localhost

sudo mkdir -p/etc/apache2/extra/vhosts//etc/apache2/extra/vhosts/sudovi

Paste the following content into localhost.conf, save

<virtualhost *: the>DocumentRoot"/users/xx/sites/localhost"ServerName localhost errorlog"/users/xx/sites/logs/localhost-error_log"Customlog"/users/xx/sites/logs/localhost-access_log"Common<directory"/users/xx/sites/localhost">Require All granted</Directory></VirtualHost>

Create a virtual host file for dev.mysite.com

cd/etc/apache2/extra/vhosts/sudovi

Paste the following content into dev.mysite.com.conf, save

<virtualhost *: the>DocumentRoot"/users/xx/sites/mysite.com"ServerName dev.mysite.com errorlog"/users/xx/sites/logs/mysite.com-error_log"Customlog"/users/xx/sites/logs/mysite.com-access_log"Common<directory"/users/xx/sites/mysite.com">Require All granted</Directory></VirtualHost>

Creating the root directory for logs and virtual hosts

mkdir -P  ~/sites/logs/mkdir -P  ~/sites/localhost/mkdir -P  ~/sites/mysite.com/

Test Apache for OK

Apachectl Configtestsyntax OK

Restart Apache

sudo apachectl graceful

Finally, in the browser input http://dev.mysite.com, test the site, before you open/etc/hosts:

sudo VI /etc/hosts

Increase row

Open terminal, detect configuration file

Ping dev.mysite.com

The result should be:

It is better to add a index.html below the ~/sites/mysite.com/, in the browser input http://dev.mysite.com , you can check the log file is normal

3.3. Install MySQL (MariaDB)

Does not specify, the reference website provides the installation step Https://mariadb.com/blog/installing-mariadb-10010-mac-os-x-homebrew

3.4, Installation phpMyAdmin

Download the latest version of phpMyAdmin, unzip it in the directory below

/users/xx/sites/localhost/phpmyadmin

In the browser input http://localhost/phpmyadmin, login with root, password for the above database set password, open the Users tab, select ' Add user '

Create a user project password for project, select 'create database with same name and grant all privileges ', and then ' ADD user '

In this way, we have the database for our Django project ready.

5, Installation Virtualenv

.......... (Updated Tomorrow) .....

Mac OSX deploys Django Project Apache+mysql+mod_wsgi

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.