LNMP = Linux + Nginx + MySQL + PHP
安装Nginx

执行以下命令即可:

apt-get install nginx

不过源里的版本是0.7.65,不喜欢老旧的玩意,可以尝试编译安装。

编译安装nginx.
1.准备编译环境

apt-get install libpcre3-dev build-essential libssl-dev

在这里 http://nginx.org/en/download.html 能找到nginx的tar球,最新的官方稳定版是
1.2.0.
执行:

cd /opt/
wget http://nginx.org/download/nginx-1.2.0.tar.gz
tar -zxvf nginx-1.2.0.tar.gz
cd /opt/nginx-1.2.0/

configure:

./configure --prefix=/opt/nginx --user=nginx --group=nginx --with-http_ssl_module

configure完成后会输出nginx的一些相关信息,

nginx path prefix: “/opt/nginx”
nginx binary file: “/opt/nginx/sbin/nginx”
nginx configuration prefix: “/opt/nginx/conf”
nginx configuration file: “/opt/nginx/conf/nginx.conf”
nginx pid file: “/opt/nginx/logs/nginx.pid”
nginx error log file: “/opt/nginx/logs/error.log”
nginx http access log file: “/opt/nginx/logs/access.log”
nginx http client request body temporary files: “client_body_temp”
nginx http proxy temporary files: “proxy_temp”
nginx http fastcgi temporary files: “fastcgi_temp”

make,安装,执行:

make
make install

给nginx进程添加用户nginx:

adduser --system --no-create-home --disabled-login --disabled-password --group nginx

下载并安装启动脚本:

wget -O init-deb.sh http://library.linode.com/assets/552-init-deb.sh
mv init-deb.sh /etc/init.d/nginx
chmod +x /etc/init.d/nginx
/usr/sbin/update-rc.d -f nginx defaults

启动一下试试:

/etc/init.d/nginx start

如果输出正常,那nginx就安装成功了。
配置虚拟主机:

如果从源里安装的nginx,那nginx配置文件位于/etc/nginx/sites-enabled
下面是一个虚拟主机的配置实例:

server {
    listen   80;
    server_name www.example.com example.com;
    access_log /srv/www/example.com/logs/access.log;
    error_log /srv/www/example.com/logs/error.log;

location / {
        root   /srv/www/example.com/public_html;
        index  index.html index.htm;
    }
}

注意,配置文件中出现的目录必须存在,nginx并不会自动创建他们,所以,还需要执行:

mkdir -p /srv/www/example.com/public_html
mkdir -p /srv/www/example.com/logs

如果是编译安装的版本,相关路径见上文configure部分,配置文件位于/opt/nginx/conf,可以直接在nginx.conf添加 server段,为了便于管理,还是把虚拟主机独立出来好,修改nginx.conf, 如下在http段添加include部分。

http {
# [...]

include /opt/etc/nginx/sites-enabled/*;

# [...]
}

添加完虚拟主机后,别忘了重启以下nginx服务。

/etc/init.d/nginx restart

删除虚拟主机只需要删除对应的配置文件并重新启动一下下nginx就好。

安装php with fastcgi

执行:

apt-get install php5-cli php5-cgi psmisc spawn-fcgi

执行下面的命令会下载并安装fastcgi的控制脚本:

cd /opt/
wget -O php-fastcgi-deb.sh http://library.linode.com/assets/554-php-fastcgi-deb.sh
mv /opt/php-fastcgi-deb.sh /usr/bin/php-fastcgi
chmod +x /usr/bin/php-fastcgi
wget -O init-php-fastcgi-deb.sh http://library.linode.com/assets/553-init-php-fastcgi-deb.sh
mv /opt/init-php-fastcgi-deb.sh /etc/init.d/php-fastcgi
chmod +x /etc/init.d/php-fastcgi
/etc/init.d/php-fastcgi start
update-rc.d php-fastcgi defaults

然后在虚拟主机的配置文件里面添加php支持,示例如下:

server {
    server_name www.example.com example.com;
    access_log /srv/www/example.com/logs/access.log;
    error_log /srv/www/example.com/logs/error.log;
    root /srv/www/example.com/public_html;

location / {
        index index.html index.htm index.php;
    }

location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /srv/www/example.com/public_html$fastcgi_script_name;
    }
}

最后重启一下nginx服务:

/etc/init.d/nginx restart

安装MySQL:

执行:

apt-get install mysql-server php5-mysql

安装过程中会要求输入数据库的初始密码,

还可以执行一下:

mysql_secure_installation

禁用root的远程登录即可。

如果需要重新设置MySQL的密码,执行:

dpkg-reconfigure mysql-server-5.0

最后重启一下fastcgi:

/etc/init.d/php-fastcgi restart

至此LNMP安装完成。
本文翻译自Linode的Library文章:http://library.linode.com/lemp-guides/ubuntu-10.04-lucid#sph_id7
文中的操作系统是Ubuntu 10.04,你可以访问上面的连接获取更多信息。个人更推荐一键傻瓜安装包:

在ubuntu上搭建LNMP服务器相关推荐

  1. Ubuntu上搭建git服务器

    一.安装git服务器所需软件 1.安装git-core git-core是git版本控制核心软件. apt-get install git-core 若安装提示失败,可能是因为系统软件库的检索文件太旧 ...

  2. 如何在Ubuntu上搭建apache服务器

    1.安装apache2服务器 注意:如果以及安装可以这一步可以忽略 sudo apt install apache2: 2.查看是否安装成功 在浏览器输入Ubuntu的IP地址,出现以下情况视为成功 ...

  3. 在Ubuntu上搭建FTE服务器

    目录 目录 关于FTE 下载FTE OSX系统 Ubuntu 测试 FTE命令详解 1命令格式 2命令参数 开始搭建 客户端设置 服务器端设置 测试 客户端 关于FTE FTE的全称是Format-T ...

  4. Ubuntu系统搭建PPPoE服务器,Ubuntu上架设PPPoE Server

    一.安裝 PPPoE Server Software 1)sudo apt-get install ppp 2)rp-pppoe(非apt套件) wget -c http://www.roaringp ...

  5. 在ubuntu 上搭建Nginx-RTMP 直播服务器

    前言 近段时间在学习Android直播,那么毋庸置疑ffmpeg和WebRTC是音视频界的两个大佬. ffmpeg的基本使用:https://blog.csdn.net/huangliniqng/ar ...

  6. Ubuntu上搭建自己的ngrok服务器

    Ubuntu上搭建自己的ngrok服务器 参考网站:http://www.sunnyos.com/article-show-48.html 上面的内容似乎是sunny大神本人写的,了解的越多,发现自己 ...

  7. 乌班图系统我的世界服务器手机版,如何在Ubuntu 20.04上搭建Minecraft服务器

    <我的世界>是有史以来最受欢迎的游戏之一.本教程说明了如何在Ubuntu 20.04上制作Minecraft服务器.我们将使用Systemd运行Minecraft服务器,并使用该mcrco ...

  8. ubuntu下搭建FTP服务器并使用FileZilla上传下载

    ubuntu下搭建FTP服务器并使用FileZilla上传下载 为了让实验室同学在共享文件时更加方便,我们决定在实验室电脑上搭建一个FTP服务器,ubuntu系统版本为16.04,下面就是我的搭建流程 ...

  9. 在Ubuntu下搭建FTP服务器的方法

    由于整个学校相当于一个大型局域网,相互之间传送数据非常快,比如要共享个电影,传点资料什么的. 所以我们可以选择搭建一个FTP服务器来共享文件. 那么问题来了,有的同学会问,我们既然在一个局域网内,直接 ...

最新文章

  1. guido正式发布python年份_Python 基础学习笔记.docx
  2. 网易资深Java架构师:java方法的定义和使用
  3. 记录——oracle数据库备份
  4. Python MySQL选择
  5. phpcmsV9一、二级导航栏目loop循环输出、当前高亮显示
  6. 抖音回应视频泄露:草稿不会上传后台;苹果开卖5000元印度版iPhone XR;Jboot 2.2.5发布|极客头条...
  7. 20210803:AXI-Stream协议源码分析初探
  8. 日常折腾日记:手动配置UG二次开发环境——使用NX Open C++和Visual Studio
  9. 新的开始——参加培训
  10. Cpp--string常用函数用法总结
  11. 如何把字幕文件转换成txt文件或word文档,.ass文件内容怎么提取出来txt文件
  12. URL中经常出现的百分号22是什么意思
  13. 【大数据】城市公交网络分析与可视化(四):绘制城市公交(地铁)线路图
  14. 【项目】小餐馆(点餐系统)项目框架
  15. 1微秒等于多少皮秒_皮秒(ps)是一个时间单位。它是这样换算的↓1秒s_圈子-新氧美容整形...
  16. STM32F407高级定时器-死区时间研究-STM32CubeMX
  17. Proteus的安装和介绍及51单片机电路仿真
  18. windows在此计算机上找不到系统映象,Win7下打开程序提示应用程序或dll 为无效的windows映像怎么办...
  19. hadoop之hdfs命令
  20. 数据结构——线性表(三)

热门文章

  1. PX4的workqueue
  2. Linux内核分析06
  3. mysql索引结构原理、性能分析与优化
  4. 第三十四天 how can I 坚持
  5. 永远的beyond!(4 days left to get back touch)
  6. MYSQL中只知表名查询属于哪个SCHEMA
  7. hive与hbase集成
  8. SqlServer SqlBulkCopy批量插入 -- 多张表同时插入(事务)
  9. 十九. Python基础(19)--异常
  10. Bitmap recycle()