Ubuntu14.04上安装LNMP的过程

Ubuntu14.04上安装LNMP的过程

人就是不能闲下来,最近我又把自己的用wordpress创建的个人博客从DigitalOcean搬到了Vultr上了。

 

sudo apt-get update
sudo apt-get upgrade

sudo vim /etc/apt/sources.list

deb http://mirrors.sohu.com/ubuntu/ precise main restricted universe multiverse
deb http://mirrors.sohu.com/ubuntu/ precise-security main restricted universe multiverse
deb http://mirrors.sohu.com/ubuntu/ precise-updates main restricted universe multiverse
deb http://mirrors.sohu.com/ubuntu/ precise-proposed main restricted universe multiverse
deb http://mirrors.sohu.com/ubuntu/ precise-backports main restricted universe multiverse
deb-src http://mirrors.sohu.com/ubuntu/ precise main restricted universe multiverse
deb-src http://mirrors.sohu.com/ubuntu/ precise-security main restricted universe multiverse
deb-src http://mirrors.sohu.com/ubuntu/ precise-updates main restricted universe multiverse
deb-src http://mirrors.sohu.com/ubuntu/ precise-proposed main restricted universe multiverse
deb-src http://mirrors.sohu.com/ubuntu/ precise-backports main restricted universe multiverse

sudo apt-get install nginx

3安装MySQL

 

apt-get install mysql-server

 

在这个过程过程中会要求您输入MySQL数据库的root密码,请认真填写。

 

4、安装PHP

4.1 安装PHP

sudo apt-get install php5 php5-cli php5-curl php5-fpm php5-intl php5-mcrypt php5-mysqlnd php5-gd

4.2 修改PHP上传文件的大小限制

sudo vim /etc/php5/fpm/php.ini

添加一下三行配置文字

post_max_size = 1024M 
memory_limit = 1024M
upload_max_filesize = 1024M

4.3 配置PHP-FPM

编辑配置文件: vim /etc/php5/fpm/pool.d/www.conf

查找: listen = 127.0.0.1:9000 
替换为: listen = /var/run/php5-fpm.sock

找到:

 

;listen.owner = www-data
;listen.group = www-data
;listen.mode = 0660

去除最前面的分号。

 

 

然后重启PHP-FPM

 

sudo /etc/init.d/php5-fpm restart

 

5 配置安装EduSoho

5.1 下载/解压程序

mkdir /var/www
cd /var/www
wget http://download.edusoho.com/edusoho-VERSION.tar.gz  
tar zxvf edusoho-VERSION.tar.gz
chown www-data:www-data edusoho/ -Rf
rm edusoho-VERSION.tar.gz

注:这里的下载地址可以在http://www.edusoho.com/中可以获取到,VERSION为下载来之后压缩包后面的版本号。

5.2 创建数据库

mysql -uroot -p

然后你需要输入MySQL数据库的root密码。
进入数据库命令行模式后,执行:

CREATE DATABASE `edusoho` DEFAULT CHARACTER SET utf8 ; 
GRANT ALL PRIVILEGES ON `edusoho`.* TO 'esuser'@'localhost' IDENTIFIED BY 'YOUR_PASSWORD';
quit

注: 请将YOUR_PASSWORD修改为你的密码,以上语句创建了名edusohodb为的数据库,和数据库用户esuser,安装EduSoho程序时需要用到。
测试数据库是否创建成功: mysql -uesuser -p –default-character-set=utf8 edusohodb

 

5.3 配置nginx的虚拟主机

sudo vim /etc/nginx/sites-enabled/edusoho

输入以下内容:

server {
    listen 80;

    # [改] 网站的域名
    server_name www.example.com example.com;
    
    #301跳转
    if ($host = 'example.com' ) {        
       rewrite ^/(.*)$ http://www.example.com/$1 permanent;
    }
    
    # 程序的安装路径
    root /var/www/edusoho/web;

    # 日志路径
    access_log /var/log/nginx/example.com.access.log;
    error_log /var/log/nginx/example.com.error.log;

    location / {
        index app.php;
        try_files $uri @rewriteapp;
    }

    location @rewriteapp {
        rewrite ^(.*)$ /app.php/$1 last;
    }

    location ~ ^/udisk {
        internal;
        root /var/www/edusoho/app/data/;
    }

    location ~ ^/(app|app_dev)\.php(/|$) {
        fastcgi_pass   unix:/var/run/php5-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
        fastcgi_param  HTTPS              off;
        fastcgi_param HTTP_X-Sendfile-Type X-Accel-Redirect;
        fastcgi_param HTTP_X-Accel-Mapping /udisk=/var/www/edusoho/app/data/udisk;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 8 128k;
    }

    # 配置设置图片格式文件
    location ~* \.(jpg|jpeg|gif|png|ico|swf)$ {
        # 过期时间为3年
        expires 3y;
        
        # 关闭日志记录
        access_log off;

        # 关闭gzip压缩,减少CPU消耗,因为图片的压缩率不高。
        gzip off;
    }

    # 配置css/js文件
    location ~* \.(css|js)$ {
        access_log off;
        expires 3y;
    }

    # 禁止用户上传目录下所有.php文件的访问,提高安全性
    location ~ ^/files/.*\.(php|php5)$ {
        deny all;
    }

    # 以下配置允许运行.php的程序,方便于其他第三方系统的集成。
    location ~ \.php$ {
        # [改] 请根据实际php-fpm运行的方式修改
        fastcgi_pass   unix:/var/run/php5-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
        fastcgi_param  HTTPS              off;
    }
}

配置文件中的example.com 为您需要指定的域名,为了确保您的域名能被他人访问得到, 您需要将这个域名和您当前的机器IP地址做DNS解析工作。

5.4 重启nginx

sudo /etc/init.d/nginx restart

 

最后一步:
浏览器中打开:http://YOU_DOMAIN 安装,当然这里的YOU_DOMAIN是您的域名。

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注