ubuntu12.04 + nginx + mysql + php(wordpress) + python(pyramid) + uwsgi 配置

1.找些速度快点的更新源。

备份一下原来的sources.list

sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup

然后把sources.list 的内容替换成如下内容

deb http://archive.ubuntu.com/ubuntu/ precise main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ precise-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ precise-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu precise-security main restricted universe multiverse
deb http://archive.canonical.com/ubuntu precise partner
deb http://extras.ubuntu.com/ubuntu precise main

2. 安装Nginx

sudo apt-get update

sudo apt-get install nginx

访问一下你的服务器(http://yourIP),应该可以看到nginx的欢迎界面了。

3. 安装php

sudo apt-get install php5-cli php5-cgi php5-fpm php5-mcrypt php5-mysql php5-curl php5-gd php5-pear

修改nginx的配置

vim /etc/nginx/sites-enabled/default

在server内部添加如下配置

location ~ \.php$ {

fastcgi_split_path_info ^(.+\.php)(/.+)$;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

include fastcgi_params;

}

重启nginx

service nginx restart

新建一个info.php 文件,放在网站根目录下,文件内容如下

<?php phpinfo(); ?>

浏览器访问http://ip/info.ph, 如果出现php信息,说明php成功安装。

4. 安装MySQL

sudo install mysql-server

5.Install phpmyadmin

sudo apt-get install phpmyadmin

会提示你输入一次mysql数据库密码,两次phpmyadmin密码。

安装好之后把phpmyadmin 放到web服务器根目录

cp -r /usr/share/phpmyadmin /var/www/

然后设置nginx 的参数 vi /etc/nginx/sites-enabled/default

加入如下内容

location /phpmyadmin/ {

alias /var/www/phpmyadmin;

index index.php;

}

现在可以用 http://ip/phpmyadmin 来访问你phpmyadmin了。

6. 安装wordpress

cd /var/www/

wget http://wordpress.org/latest.tar.gz

tar zxv -f latest.tar.gz

然后在 /etc/nginx/sites-enables/ 下面新建文件,名字任意,比如wordpress

server

{

listen 80;

server_name your_domain_name_for_wordpress;

index index.html index.htm index.php default.html default.htm default.php;

root /var/www/wordpress;

include /etc/nginx/wordpress.conf;

location ~ \.php$ {

fastcgi_split_path_info ^(.+\.php)(/.+)$;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

include fastcgi_params;

}

location / {

if (-f $request_filename/index.html){

rewrite (.*) $1/index.html break;

}

if (-f $request_filename/index.php){

rewrite (.*) $1/index.php;

}

if (!-f $request_filename){

rewrite (.*) /index.php;

}

}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

{

expires 30d;

}

location ~ .*\.(js|css)?$

{

expires 12h;

}

access_log off;

}

访问你在server_name 那里写的域名,就可以看到wordpress的配置界面了。

7. 安装Pyramid

sudo apt-get install python-dev python-pip libjpeg62-dev

sudo apt-get install build-essential

easy_install virtualenv

cd /home

mkdir pyramid

cd pyramid

virtualenv –no-site-packages env(名字自己取)

cd env
bin/easy_install pyramid

bin/pcreate -s alchemy tutorial(名字自己取)

cd tutorial
../bin/python setup.py develop

修改一下development.ini 的内容

sqlalchemy.url = mysql://root:@localhost/buffer?charset=utf8

安装一点包

sudo apt-get install libmysqld-dev libmysqlclient-dev

安装 MySQL-python

../bin/easy_install MySQL-python

建立数据库

../bin/initialize_project_db development.ini

8. 安装uWSGI

easy_install uwsgi

如果运气不好没成功,安装下面的包试一下。

sudo apt-get install libxml2-dev

9. 配置MySQL

修改 /etc/mysql/my.cnf, 在[mysqld] 标签下添加如下内容:

skip-character-set-client-handshake
collation_server=utf8_unicode_ci
character_set_server=utf8

然后重启mysql

sudo service mysql restart

10. 配置Nginx

修改/etc/nginx/nginx.conf ,下面是一个示例:

user www-data;
worker_processes 16;

error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

worker_rlimit_nofile 20480;
events {
use epoll;
worker_connections 20480;
}
timer_resolution 500ms;

http {
include mime.types;
default_type application/octet-stream;

log_format main ‘$remote_addr $host $remote_user [$time_local] “$request” ‘
‘$status $body_bytes_sent “$http_referer” “$http_user_agent” “$gzip_ratio” “$request_length” “$upstream_response_time” “$request_time”‘;
access_log /var/log/nginx/access.log main;

sendfile on;

keepalive_timeout 60;
tcp_nodelay on;

gzip_disable “MSIE [1-6]\.(?!.*SV1)”;
gzip_buffers 16 8k;
gzip_comp_level 1;
gzip_min_length 0;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}

在 /etc/nginx/sites-available/ 新建一个文件,名字任意比如是 pyramid:

server {
listen 80;
access_log off;

server_name your_domain;

error_log /var/log/nginx/http.error.log;

charset utf-8;
location / {
uwsgi_pass unix:///tmp/uwsgi.sock;
include uwsgi_params;
uwsgi_param SCRIPT_NAME /;
}
}

建立软连接

ln -sf /etc/nginx/sites-available/demo /etc/nginx/sites-enabled/demo

重启nginx

service nginx restart

11. 配置uWSGI

在pyramid项目的 production.ini/development.ini 文件里面添加下面的内容:

[uwsgi]
socket = /tmp/uwsgi.sock
master = true

processes = 4

harakiri = 60
harakiri-verbose = true
limit-post = 65536
post-buffering = 8192

daemonize = ./uwsgi.log
pidfile = ./pid_5000.pid

listen = 256

max-requests = 1000

reload-on-as = 128
reload-on-rss = 96
no-orphans = true

log-slow = true

virtualenv = /home/pyramid/env

启动uwsgi,(可以把此命令加入到 /etc/rc.local,以便开机自动运行):

uwsgi –ini-paste-logged production.ini

看一下uwsgi的状态:

$ ps axu | grep uwsgi

你会看到如下的内容

sunliang 16510 19.0 0.3 96072 30032 ? S 18:06 0:00 uwsgi –ini-paste production.ini
sunliang 16511 0.0 0.3 96072 26972 ? S 18:06 0:00 uwsgi –ini-paste production.ini
sunliang 16512 0.0 0.3 96072 26968 ? S 18:06 0:00 uwsgi –ini-paste production.ini
sunliang 16513 0.0 0.3 96072 26968 ? S 18:06 0:00 uwsgi –ini-paste production.ini
sunliang 16514 0.0 0.3 96072 26968 ? S 18:06 0:00 uwsgi –ini-paste production.ini
sunliang 16521 0.0 0.0 7620 908 pts/0 S+ 18:06 0:00 grep –color=auto uwsgi

1.找些速度快点的更新源。

备份一下原来的sources.list

sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup

然后把sources.list 的内容替换成如下内容

deb http://archive.ubuntu.com/ubuntu/ precise main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ precise-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ precise-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu precise-security main restricted universe multiverse
deb http://archive.canonical.com/ubuntu precise partner
deb http://extras.ubuntu.com/ubuntu precise main

2. 安装Nginx

sudo apt-get update

sudo apt-get install nginx

访问一下你的服务器(http://yourIP),应该可以看到nginx的欢迎界面了。

3. 安装php

sudo apt-get install php5-cli php5-cgi php5-fpm php5-mcrypt php5-mysql php5-curl php5-gd php5-pear

修改nginx的配置

vim /etc/nginx/sites-enabled/default

在server内部添加如下配置

location ~ \.php$ {

fastcgi_split_path_info ^(.+\.php)(/.+)$;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

include fastcgi_params;

}

重启nginx

service nginx restart

新建一个info.php 文件,放在网站根目录下,文件内容如下

<?php phpinfo(); ?>

浏览器访问http://ip/info.ph, 如果出现php信息,说明php成功安装。

4. 安装MySQL

sudo install mysql-server

5.Install phpmyadmin

sudo apt-get install phpmyadmin

会提示你输入一次mysql数据库密码,两次phpmyadmin密码。

安装好之后把phpmyadmin 放到web服务器根目录

cp -r /usr/share/phpmyadmin /var/www/

然后设置nginx 的参数 vi /etc/nginx/sites-enabled/default

加入如下内容

location /phpmyadmin/ {

alias /var/www/phpmyadmin;

index index.php;

}

现在可以用 http://ip/phpmyadmin 来访问你phpmyadmin了。

6. 安装wordpress

cd /var/www/

wget http://wordpress.org/latest.tar.gz

tar zxv -f latest.tar.gz

然后在 /etc/nginx/sites-enables/ 下面新建文件,名字任意,比如wordpress

server

{

listen 80;

server_name your_domain_name_for_wordpress;

index index.html index.htm index.php default.html default.htm default.php;

root /var/www/wordpress;

include /etc/nginx/wordpress.conf;

location ~ \.php$ {

fastcgi_split_path_info ^(.+\.php)(/.+)$;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

include fastcgi_params;

}

location / {

if (-f $request_filename/index.html){

rewrite (.*) $1/index.html break;

}

if (-f $request_filename/index.php){

rewrite (.*) $1/index.php;

}

if (!-f $request_filename){

rewrite (.*) /index.php;

}

}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

{

expires 30d;

}

location ~ .*\.(js|css)?$

{

expires 12h;

}

access_log off;

}

访问你在server_name 那里写的域名,就可以看到wordpress的配置界面了。

7. 安装Pyramid

sudo apt-get install python-dev python-pip libjpeg62-dev

sudo apt-get install build-essential

easy_install virtualenv

cd /home

mkdir pyramid

cd pyramid

virtualenv –no-site-packages env(名字自己取)

cd env
bin/easy_install pyramid

bin/pcreate -s alchemy tutorial(名字自己取)

cd tutorial
../bin/python setup.py develop

修改一下development.ini 的内容

sqlalchemy.url = mysql://root:@localhost/buffer?charset=utf8

安装一点包

sudo apt-get install libmysqld-dev libmysqlclient-dev

安装 MySQL-python

../bin/easy_install MySQL-python

建立数据库

../bin/initialize_project_db development.ini

8. 安装uWSGI

easy_install uwsgi

如果运气不好没成功,安装下面的包试一下。

sudo apt-get install libxml2-dev

9. 配置MySQL

修改 /etc/mysql/my.cnf, 在[mysqld] 标签下添加如下内容:

skip-character-set-client-handshake
collation_server=utf8_unicode_ci
character_set_server=utf8

然后重启mysql

sudo service mysql restart

10. 配置Nginx

修改/etc/nginx/nginx.conf ,下面是一个示例:

user www-data;
worker_processes 16;

error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

worker_rlimit_nofile 20480;
events {
use epoll;
worker_connections 20480;
}
timer_resolution 500ms;

http {
include mime.types;
default_type application/octet-stream;

log_format main ‘$remote_addr $host $remote_user [$time_local] “$request” ‘
‘$status $body_bytes_sent “$http_referer” “$http_user_agent” “$gzip_ratio” “$request_length” “$upstream_response_time” “$request_time”‘;
access_log /var/log/nginx/access.log main;

sendfile on;

keepalive_timeout 60;
tcp_nodelay on;

gzip_disable “MSIE [1-6]\.(?!.*SV1)”;
gzip_buffers 16 8k;
gzip_comp_level 1;
gzip_min_length 0;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}

在 /etc/nginx/sites-available/ 新建一个文件,名字任意比如是 pyramid:

server {
listen 80;
access_log off;

server_name your_domain;

error_log /var/log/nginx/http.error.log;

charset utf-8;
location / {
uwsgi_pass unix:///tmp/uwsgi.sock;
include uwsgi_params;
uwsgi_param SCRIPT_NAME /;
}
}

建立软连接

ln -sf /etc/nginx/sites-available/demo /etc/nginx/sites-enabled/demo

重启nginx

service nginx restart

11. 配置uWSGI

在pyramid项目的 production.ini/development.ini 文件里面添加下面的内容:

[uwsgi]
socket = /tmp/uwsgi.sock
master = true

processes = 4

harakiri = 60
harakiri-verbose = true
limit-post = 65536
post-buffering = 8192

daemonize = ./uwsgi.log
pidfile = ./pid_5000.pid

listen = 256

max-requests = 1000

reload-on-as = 128
reload-on-rss = 96
no-orphans = true

log-slow = true

virtualenv = /home/pyramid/env

启动uwsgi,(可以把此命令加入到 /etc/rc.local,以便开机自动运行):

uwsgi –ini-paste-logged production.ini

看一下uwsgi的状态:

$ ps axu | grep uwsgi

你会看到如下的内容

sunliang 16510 19.0 0.3 96072 30032 ? S 18:06 0:00 uwsgi –ini-paste production.ini
sunliang 16511 0.0 0.3 96072 26972 ? S 18:06 0:00 uwsgi –ini-paste production.ini
sunliang 16512 0.0 0.3 96072 26968 ? S 18:06 0:00 uwsgi –ini-paste production.ini
sunliang 16513 0.0 0.3 96072 26968 ? S 18:06 0:00 uwsgi –ini-paste production.ini
sunliang 16514 0.0 0.3 96072 26968 ? S 18:06 0:00 uwsgi –ini-paste production.ini
sunliang 16521 0.0 0.0 7620 908 pts/0 S+ 18:06 0:00 grep –color=auto uwsgi



你可能感兴趣的:(nginx,PHP,mysql,python,wordpress,ubuntu)