Mac OS X Yosemite 10.10.3 apache+mysql+django web开发环境的

准备工作:

1.确认mac os x 的版本号为10.10.3;

2.mac os x yosemite预装了apache、python,因此无需下载该包;

在shell下输入python即可查看版本:

Python 2.7.6 (default, Sep 9 2014, 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.

在shell下输入apachectl -v可查看预装的apache的版本:

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

另外,可以通过一下命令启动apache的服务器:

sudo apachectl start可以通过一下命令重启apache服务器:sudo apachectl restart可以通过以下命令关闭apache服务器:sudo apachectl stop

3.安装django,直接通过pip安装:

sudo pip install Django==1.8

4.安装mysql:

从官网下载mysql的dmg安装包安装即可。

5.配置mysql:

默认情况下,mysql的安装目录为:/usr/local/mysql/bin/mysql和/usr/local/mysql/bin/mysqladmin,请将路径/usr/local/mysql/bin/加入到shell的路径下,以后在shell中可以直接输入命令mysql和mysqladmin进入mysql命令行或对其进行管理。

安装成功后在系统偏好设置的mysql中开启mysql服务。

第一次安装的mysql均以root用户访问,且没有密码,因此必须设置密码,先输入命令设置密码:

sudo mysqladmin -u root -p password youpassword然后登陆到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) 2000, 2015, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>即表示配置成功!

5.安装MySQLdb,即安装mysql-python

首先推荐pip的安装方式:

@worm ~ sudo pip install MySQL-python

如果有报错,应该会出现类似的错误:”mysql_config not found“的错误。此时必须手动安装。

在pypi上下载MySQL-python1.2.5,解压该包,在安装包文件中找到site.cfg文件并打开,将下面这句的注释去掉:

# The path to mysql_config.# Only use this if mysql_config is not on your PATH, or you have some weird# setup that requires it.# mysql_config = /usr/local/bin/mysql_config并修改为:mysql_config = /usr/local/mysql/bin/mysql_config

等号右边实际上是你的mysql的安装路径。

最后执行命令:

python setup.py install

安装完成后,在python命令行下import MySQLdb时报错:

Reason: image not found。

此时,在终端执行下面命令,实际上添加两个链接文件:

$ sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib$ sudo ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysqlMySQLdb安装完成!

6.安装配置mod_wsgi:

对于mdo_wsgi的安装与配置pypi上有很详细的说明,,这里只是捡重要的粘贴在这里:

Installation of mod_wsgi can now be performed in one of two ways.

The first way of installing mod_wsgi is the traditional way that has been used in the past, where it is installed as a module directly into your Apache installation.

The second and newest way of installing mod_wsgi is to install it as a Python package into your Python installation.

This new way of installing mod_wsgi will compile not only the Apache module for mod_wsgi, but will also install a set of Python modules and an admin script for running up Apache directly from the command line with an auto generated configuration.

This later mechanism for running up Apache, which is referred to as the mod_wsgi express version, provides a much simpler way of 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 are running MacOS X, the Apache server and required developer files for compiling mod_wsgi are already present.

Installation into Python

To install the mod_wsgi express version directly into your Python installation, from within the source directory of the mod_wsgi package you can run:

python setup.py install

This will compile mod_wsgi and install the resulting package into your Python installation.

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

pip install mod_wsgi

If you wish to use a version of Apache which is installed into a non standard location, you can set and export theAPXSenvironment variable to the location of the Apacheapxsscript for your Apache installation before performing the installation.

Note that nothing will be copied into your Apache installation at this point. As a result, you do not 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 that the installation was successful, run themod_wsgi-expressscript with thestart-servercommand:

mod_wsgi-express start-server

This will start up Apache/mod_wsgi on port 8000. You can then verify that the installation worked by pointing your browser at:

:8000/

When started in this way, the Apache web server will stay in the foreground. To stop the Apache server, use CTRL-C.

For a simple WSGI application contained in a WSGI script file calledwsgi.py, in the current directory, you can now run:

mod_wsgi-express start-server wsgi.py

This instance of the Apache web server will be completely independent of, and will not interfere with any existing instance of Apache you may have running on port 80.

开始的时侯,我们就知道,总会有终结。

Mac OS X Yosemite 10.10.3 apache+mysql+django web开发环境的

相关文章:

你感兴趣的文章:

标签云: