Ubuntu server 安装与配置lnmp并安装wordpress

Ubuntu 10.04.1 LTS下安装与配置LNMP环境,所谓的LNMP就是Linux+Nginx+Mysql+PHP.

1.首先安装nginx

root@lnmp:/home/windonly# apt-get install nginx
root@lnmp:/home/windonly# service nginx start

目前官方源提供的版本是:0.7.65,通过访问80端口可以测试是否安装成功。

2.安装MySql

通过执行apt-get install mysql-server命令后自动下载mysql,然后安装提示配置好mysql root密码。

 

3.安装PHP5+php5-fpm

由于目前的官方的源里面没有php5-fpm的包,我们需要下载源代码编译,后面Google发现已经有人提供了镜像源,该镜像源需要验证KEY,不过我们可以无视它继续安装。

在 /etc/apt/sources.list 中加入
deb http://ppa.launchpad.net/jdub/devel/ubuntu maverick main
deb http://ppa.launchpad.net/brianmercer/php/ubuntu lucid main
deb-src http://ppa.launchpad.net/brianmercer/php/ubuntu lucid main

然后执行:
apt-get update

然后安装 php5-fpm
apt-get install php5-fpm 
service php5-fpm start

修改nginx配置文件来完成配置:

root@lnmp:/home/windonly# vi /etc/nginx/sites-enabled/default 

server {
        listen   80 ;
        listen   [::]:80 default ipv6only=on;   ## enable for ipv6
        server_name  localhost;

        #access_log  /var/log/nginx/localhost.access.log;

        index index.php index.htm index.html;
        root /var/www;
        expires 7d;
        location ~ \.php$ {
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param APPLICATION_ENV production;
                include fcgi.conf;
                expires off;
        }
}

再配置fcgi.conf:
root@lnmp:/home/windonly# vi /etc/nginx/fcgi.conf 

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx;

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

完成之后通过:
root@lnmp:/home/windonly# nginx -t
the configuration file /etc/nginx/nginx.conf syntax is ok
configuration file /etc/nginx/nginx.conf test is successful

来测试配置文件是否正确。
最后通过 service nginx reload 重启nginx

通过:
vi /var/www/index.php

然后访问这个页面来测试是否配置成功了。
4.配置PHP和MySql

通过 apt-get install php5-mysql 安装PHP访问MySql模块,需要重启下php5-fpm使其生效。

5.安装Wordpress

首先现在最新版本的wordpress: wget http://cn.wordpress.org/wordpress-3.0.1-zh_CN.zip 并解压(如果服务器上没装unzip就通过apt-get install unzip安装),先创建数据库:

mysql> create database myblog;
Query OK, 1 row affected (0.00 sec)

mysql> create user 'myblog'@'localhost' identified by 'myblog';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all on myblog.* to 'myblog'@'localhost';
Query OK, 0 rows affected (0.00 sec)

然后就可以通过web页面安装与配置wordpress了。

6.如何实现Wordpress静态链接
windonly@linux:~$ sudo vi /etc/nginx/sites-enabled/default 

加入以下配置:

location / {
        index index.html index.php;
        if (-d $request_filename){
                rewrite ^/(.*)([^/])$ $1$2/ permanent;
        }
        if (-f $request_filename/index.php){
                rewrite (.*) $1/wordpress/index.php;
        }
        if (!-f $request_filename){
                rewrite (.*) /wordpress/index.php;
        }
}

然后重启nginx既可。

7.结束语

至此整个LNMP配置已经完成,虽然网上有很多一键包,但是只有通过自己手工配置一次才能熟悉整个配置流程,方便后期维护和优化。一直很纠结要不要去买一个VPS,每年1600的费用也是一笔相当大的开销啊。

 

#安装 eAccelerator
wget http://bart.eaccelerator.net/source/0.9.6.1/eaccelerator-0.9.6.1.tar.bz2
tar xvjf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1
cp control.php /var/www/control.php
sudo chown www:www /var/www/control.php
sudo phpize
sudo ./configure –enable-eaccelerator=shared
sudo make
sudo make install
sudo vi /etc/php5/fpm/php.ini

extension_dir = “/usr/lib/php5/20090626+lfs/”
extension = eaccelerator.so
eaccelerator.shm_size=”16″
eaccelerator.cache_dir=”/tmp/eaccelerator”
eaccelerator.enable=”1″
eaccelerator.optimizer=”1″
eaccelerator.check_mtime=”1″
eaccelerator.debug=”0″
eaccelerator.filter=””
eaccelerator.shm_max=”0″
eaccelerator.shm_ttl=”0″
eaccelerator.shm_prune_period=”0″
eaccelerator.shm_only=”0″
eaccelerator.compress=”1″
eaccelerator.compress_level=”9″
eaccelerator.allowed_admin_path=”/var/www/control.php”

#配置文件目录
/etc/nginx/nginx.conf
/etc/nginx/sites-enabled/default
/etc/php5/fpm/php.ini
/etc/php5/fpm/pool.d/www.conf

CC BY-NC-SA 4.0 Ubuntu server 安装与配置lnmp并安装wordpress by 桔子小窝 is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

发表回复

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据