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 darwin
Type "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 -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 51
Server 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 its
affiliates. Other names may be trademarks of their respective
owners.

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/mysql

MySQLdb安装完成!

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 the APXS environment variable to the location of the Apacheapxs script 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 the mod_wsgi-express script with the start-server command:

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:

http://localhost: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 called wsgi.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.

If you already have 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 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 make it easier for users to run up Apache on non privileged ports, especially during the development of a Python web application. If you want to be able to run Apache using mod_wsgi
express on a privileged port such as the standard port 80 used by HTTP servers, then you will need to run mod_wsgi-express as root. In doing this, you will need to perform additional steps.

The first thing you must do is supply the --user and --group options to say what user and group your Python web application
should run as. Most Linux distrbutions will pre define a special user for Apache to run as, so you can use that. Alternatively you can use any 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 will be fine so long as you are using a process supervisor which expects the started process to remain in the foreground and not daemonize.

If however you are directly integrating into the system init scripts where separate start and stop commands are expected, with the executing process expected to be daemonized, then a different process is required to setup mod_wsgi
express.

In this case, instead of simply using the start-server command to mod_wsgi-express you should use setup-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 this command, it will not actually startup Apache. All it will do is create the set of configuration files and startup script to be run.

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

Having 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 you supplied to setup-server will effectively be cached with the resulting 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 is possible that running up Apache as root using mod_wsgi express may fail on systems where SELinux extensions are enabled. This is because the SELinux profile may not match what
is being expected for the way that Apache is being started, or alternatively, the locations that Apache has been specified as being allowed to access, don’t match where the directory specified using the --server-root directory
was placed. You may therefore need to configure SELinux or move the directory used with --server-root to an allowed location.

Using mod_wsgi express with Django

To use the mod_wsgi express version with Django, after having 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 you first collect up any Django static file assets into 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 have any code changes automatically reloaded, then you can use the --reload-on-changes option.

python manage.py runmodwsgi --reload-on-changes

If wanting to have Apache started as root in order to listen on port 80, instead of using mod_wsgi-express setup-server as
described above, use the --setup-onlyoption to the runmodwsgi management command.

python manage.py runmodwsgi --setup-only --port=80     --user www-data --group www-data     --server-root=/etc/mod_wsgi-express-80
时间: 2024-10-05 05:31:56

Mac OS X Yosemite 10.10.3 apache+mysql+django web开发环境的搭建的相关文章

mac系统中搭建apache+mysql+php的开发环境,安装mysql后,登录报错:mac ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

php新手在mac系统中搭建apache+mysql+php的开发环境(按照这篇博客来操作的:http://my.oschina.net/joanfen/blog/171109?fromerr=xvCsafCe),在安装配置mysql完毕后,登录mysql,报错:mac ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO),折腾很久,终于解决,随手记录下,备忘. 解决方法: 第一步:如

mac OS X Yosemite (10.10.5) 下 安装vim 7.4笔记

摘要 前言 需求与mac OS X 自带vim版本的冲突 默认Python解释器问题 并非Mac自带python的 homebrew 1. 前言 本文为自己作死折腾的问题记录 2. 需求与mac OS X 自带vim版本的冲突 - 为什么用vim Emacs因为上手时候因为无关于Emacs的其他原因留下了很不好的回忆,现在也不是必须,不想学(_(:з」∠)_),Sublime Text 2/3在Build Python程序的时候,自带的console,输出很容易出问题,希望放在terminal下

centos+apache+python34+django+mod_wsgi 开发环境搭建

写给自己,linux运维路.动手趟一遍 linux:centos7.3+apache+python3.4+django+mod_wsgi+sambawindows: eclipse pycharm sublime 最近一直在学习python,虽说在windows下开发比较方便,但一般情况下,最终会把程序放到linux环境去布暑运行.so...直接搭建一个linux+windows的开发环境 ---------------------- python3.4安装 #先安装epel源(aliyun)

启用Mac(OS X Yosemite)自带的apache

刚用Mac的时候配置过一次Mac自带的apache,主要是平常自己用mackdown写文档,装成html文件放到apache下方便自己和同事阅读.后来升级各种东西,估计是升级OS X导致apache不能用了,又折腾了一天才弄好(apache小白伤不起啊),现在整理出来方便以后再发生类似事情能快点搞定. apache默认安装路径是 /etc/apache2/ . apache默认host路径是 /Library/WebServer/Documents . apache默认用户的路径是 ~/Site

MAC OS X Yosemite的PyQt4配置记录 by tsy

声明: 1)本报告由博客园bitpeach撰写,版权所有,免费转载,请注明出处,并请勿作商业用途. 2)若本文档内有侵权文字或图片等内容,请联系作者bitpeach删除相应部分. 3)本文档内容涉及Mac OS X Yosemite的PyQt4配置. 4)仅仅作为参考用途,抛砖引玉,不作为证据证明用途,请自行取舍,核实引用. 0目录 1.1参考文献 主要是汇总一下,我参考阅读的一些文献.以此为坚实基础,进行实践.这些参考博客或文章是非常宝贵的经验记录. 1.2环境 需要准备些什么 1.3过程步骤

在Mac OS X Yosemite 10.10.3 中搭建第一个 ASP.NET 5 Web 项目

终于有时间在 Mac 上安装一下 ASP.NET 5,网上有许多教程,但是多数的时间比较早了,版本不是最新,搭着 Build 2015 的春风,我也实践一下 Mac OS X 上的 ASP.NET 5. 经常使用 Windows 8.1,对 Mac 并不太熟悉,也一并把安装中的问题趟一遍. 前几天刚刚更新了 Mac 的操作系统,操作系统版本 Mac OS X Yosemite 10.10.3. 1. 在 Mac OS X 上安装 ASP.NET 5 ASP.NET 5 运行在 DNX 之上,DN

Mac OS X Yosemite安装盘U盘制作

从App Store下载Mac OS X Yosemite安装程序,下载后的安装文件保存在应用程序(/Applications)文件夹中.请注意,此时一定不要直接启动该程序安装 OS X Yosemite,因为一旦安装完后该安装程序会被删除.至少,你应该先做完独立安装介质之后再启动该程序安装. 准备独立安装盘介质:你需要一个容量至少大于 8GB 的移动存储设备,比如 U 盘.移动硬盘或 SD 卡,将其插入 Mac,并启动磁盘工具对该介质执行”抹掉”操作,抹掉前请备份好该介质中的重要数据.盘符名请

Mac OS X Yosemite & Arduino安装CH340 USB转串口驱动

新买的Arduino开发板 USB转串口使用了CH340芯片,在Mac OS X Yosemite上正常安装驱动后,在Arduino IDE的端口没发现相应的设备,使用以下方法后就能使用USB转串口调试和烧录程序.1.安装CH340驱动(驱动下载地址:http://www.wch.cn/download/CH341SER_MAC_ZIP.html)2.打开终端运行以下命令:  sudo nvram boot-args="kext-dev-mode=1"  sudo Reboot

Mac OS X上IntelliJ IDEA 13与Tomcat 8的Java Web开发环境搭建

这标题实在有点拗口,不知道怎么写好,但看了标题也就明白文本的内容.最近几天在折腾这些玩意儿,所以写写总结.除了环境搭建,本文还是一篇入门级的上手教程. 去下载一些东西 JDK安装 Tomcat安装 Tomcat的配置 配置管理员账号 配置Tomcat端口 配置HTTPS 添加web应用 IntelliJ的安装 创建Java Web项目 运行Java Web项目 打成war包 去下载一些东西 老样子,先废话几句,IntelliJ IDEA,这个名字不知道谁想出来的,也真够拗口的,发音大致如此:[i