Building a Mac OS X Yosemite 10.10.3 Apache+mysql+django Web Development environment

Source: Internet
Author: User
Tags new set hosting install django mysql command line pip install django virtual environment

Preparatory work:

1. Confirm that the version number of Mac OS X is 10.10.3;

2.mac OS X Yosemite Pre-installed Apache, Python, so there is no need to download the package;

Enter Python under the shell to view the version:

Python 2.7.6 (default, Sep  9, 15:04:36) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on Darwintype "help "," copyright "," credits "or" license "for more information.

Enter apachectl-v under the shell to view the pre-installed Apache version:

Server version:apache/2.4.10 (Unix) server built:   Jan  8 2015 20:48:33

Alternatively, you can start the Apache server with a command:

sudo apachectl start
You can restart the Apache server by following the command:

sudo apachectl restart
The Apache server can be shut down with the following command:

sudo apachectl stop

3. Install Django and install directly via PIP:

sudo pip install django==1.8

4. Install MySQL:

Download the MySQL DMG installation package from the official website.

5. Configure MySQL:

By default, the installation directory for MySQL is:/usr/local/mysql/bin/mysql and/usr/local/mysql/bin/mysqladmin, please/usr/local/mysql/bin/the path Add the path to the shell, and later in the shell you can enter commands directly into MySQL and mysqladmin into the MySQL command line or manage it.

After successful installation, turn on MySQL service in System Preferences MySQL.

The first installation of MySQL is accessed by the root user, and no password, so you must set a password, enter the command to set the password:

sudo mysqladmin-u root-p password Youpassword
Then log in to MySQL:

@worm?  ~  mysql-u root-penter password:welcome to the MySQL monitor.  Commands End With; or \g.your MySQL connection ID is 51Server version:5.6.24 mysql Community Server (GPL) Copyright (c) +, Oracle an d/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names trademarks of their respectiveowners. Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.mysql>
That means the configuration is successful!

5. Install MYSQLDB, i.e. install Mysql-python

First, we recommend how to install PIP:

@worm?  ~  sudo pip install Mysql-python

If there are errors, a similar error should appear: "Mysql_config not Found" error. This must be manually installed.

Download the mysql-python1.2.5 on the PyPI, unzip the package, locate the Site.cfg file in the installation package file and open it, and remove the comment from the following sentence:

# The path to Mysql_config. # Only with this if mysql_config are not on your PATH, or you have some weird # setup that requires it. # mysql_config =/usr/local/bin/mysql_config
and modified to:

Mysql_config =/usr/local/mysql/bin/mysql_config

The right side of the equals sign is actually your MySQL installation path.

Final execution Command:

Python setup.py Install

After the installation is complete, import the MySQLdb times error in the Python command line:

Reason:image not found.

At this point, the terminal executes the following command, actually adding two linked files:

$ sudo ln-s/usr/local/mysql/lib/libmysqlclient.18.dylib/usr/lib/libmysqlclient.18-s/usr/local/mysql/lib /usr/local/mysql/lib/mysql
MYSQLDB installation is complete!

6. Installation Configuration Mod_wsgi:

For MDO_WSGI installation and configuration PyPI have a very detailed description, here just pick up the important paste here:

Installation of Mod_wsgi can now is performed in one of the ways.

The first-to installing MOD_WSGI is the traditional-to-have been used in the past, where it's installed as a mod Ule directly into your Apache installation.

The second and newest-on-the-installing MOD_WSGI is-to-install it as a Python package into your Python installation.

This new to installing MOD_WSGI would compile not only the Apache module for Mod_wsgi, but would also install a set of P Ython modules and an admin script for running up Apache directly from the command line with an auto generated configuratio N.

This later mechanism for running up Apache, which are referred to as the Mod_wsgi Express version, provides a much simpler The getting starting with hosting your Python Web application.

In particular, the new installation method makes it very easy-to-use APACHE/MOD_WSGI in a development environment without The need to perform any Apache configuration yourself.

If you is running MacOS X, the Apache server and required developer files for compiling Mod_wsgi is already present.

Installation into Python

To install the Mod_wsgi Express version directly into your Python installation from within the source directory of the MO D_WSGI Package can run:

Python setup.py Install

This would compile Mod_wsgi and install the resulting package into your Python installation.

If wishing to install a official release direct from PyPi, you can instead run:

Pip Install Mod_wsgi

If you wish to use a version of Apache which are installed into a non standard location, you can set and export the APX S environment variable to the location of the Apacheapxs script for your Apache installation before Performi ng the installation.

Note that nothing would be copied to your Apache installation at the this point. As a result, you don't need to run this as the root user unless installing it into a site wide Python installation rather than a Python virtual environment.

To verify the installation is successful, run the mod_wsgi-express script with the Start-server Co Mmand:

Mod_wsgi-express Start-server

This'll start Apache/mod_wsgi on port 8000. You can then verify, the installation worked by pointing your browser at:

Http://localhost:8000/

When a started in this is the Apache Web server would stay in the foreground. To stop the Apache server and use Ctrl-c.

For a simple WSGI application contained in a WSGI script file called wsgi.py, in the current directory, you can n ow run:

Mod_wsgi-express Start-server wsgi.py

This instance of the Apache Web server would be completely independent of, and would not interfere with any existing instanc E of Apache running on port 80.

If you already has another Web server running on port 8000, you can override the port to be used using the --port option:

Mod_wsgi-express start-server wsgi.py--port 8001

For a complete list of the options you can run:

Mod_wsgi-express Start-server--help

Further information on using the Mod_wsgi Express version see the main MOD_WSGI documentation.

Running Mod_wsgi Express as Root

The primary intention of Mod_wsgi Express is to do it easier for users to run up Apache on non privileged ports, Especia Lly during the development of a Python Web application. If you want to is able to run Apache using Mod_wsgi Express in a privileged port such as the standard port-used by HTTP Servers, then you'll need to run mod_wsgi-express as root. In doing this, you'll need to perform additional steps.

The first thing you must do are supply the --user and --group options to say what user and group your PYT Hon Web application should run as. Most Linux distrbutions would pre define a special user for Apache to run as, so can use this. Alternatively you can use any of the other special user account you have created for running the Python Web application:

Mod_wsgi-express start-server wsgi.py--port=80     --user www-data--group www-data

This approach to running mod_wsgi-express 'll be fine so long as you are using a process supervisor which expect s the started process to remain in the foreground and not daemonize.

If however you is directly integrating into the system init scripts where separate start and stop commands is expected, With the executing process expected to being daemonized, then a different process are required to setup Mod_wsgi Express.

In this case, instead of simply using the start-server command to mod_wsgi-express you should use SE Tup-server:

Mod_wsgi-express setup-server wsgi.py--port=80     --user www-data--group www-data     --server-root=/etc/mod_ Wsgi-express-80

In running the This command, it would not actually startup Apache. All it would do are create the set of configuration files and startup script to be run.

So that these is not created in the default location of a directory under/ tmp, you should use the --server- Root option to specify where they should is placed.

Have created the configuration and startup script, to start the Apache instance you can now run:

/etc/mod_wsgi-express-80/apachectl start

To subsequently stop the Apache instance you can run:

/etc/mod_wsgi-express-80/apachectl stop

You can also restart the Apache instance as necessary using:

/etc/mod_wsgi-express-80/apachectl restart

Using This approach, the original options supplied to Setup-server would effectively be cached with the result ing configuration used each time. If you need to update the set of options, run setup-server again with the new set of options.

Note that even taking all these steps, it's possible that running up Apache as root using Mod_wsgi Express may F Ail on systems where SELinux extensions is enabled. This is because the SELinux profiles may isn't match what's being expected for the the-the-the-same-Apache is being started, or Alte Rnatively, the locations that Apache have been specified as being allowed to access, don ' t match where the directory Specif The IED using the --server-root directory was placed. You could therefore need to configure SELinux or move the directory used with --server-root to a allowed location.

Using Mod_wsgi Express with Django

The Mod_wsgi Express version with Django, after have installed the MOD_WSGI package into your Python installation , edit your Django settings module and addmod_wsgi.server to the list of installed apps.

Installed_apps = (    ' django.contrib.admin ',    ' Django.contrib.auth ',    ' django.contrib.contenttypes ',    ' django.contrib.sessions ',    ' django.contrib.messages ',    ' django.contrib.staticfiles ',    ' mod_ Wsgi.server ',)

To prepare for running of the Mod_wsgi Express version, ensure that's first collect up any Django static file assets int o the directory specified for them in the Django settings file:

Python manage.py collectstatic

You can now run the Apache server with Mod_wsgi hosting your Django application by running:

Python manage.py Runmodwsgi

If working in a development environment and you would like to has any code changes automatically reloaded, then you can u Se the --reload-on-changes option.

Python manage.py Runmodwsgi--reload-on-changes

If wanting to has Apache started as root in order to listen on port, instead of using mod_wsgi-express setup-server as described above, use the --setup-onlyoption to the Runmodwsgi Management Co Mmand.

Python manage.py runmodwsgi--setup-only--port=80     --user www-data--group www-data     --server-root=/etc/mod_ Wsgi-express-80


Building a Mac OS X Yosemite 10.10.3 Apache+mysql+django Web Development environment

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.