ubuntu 12.04 安装 Nginx+PHP5 (PHP-FPM) +MySQL主机详解

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

很长时间没有在 Ubuntu 安装实际操作安装web服务器了,今天想练练手,在虚拟机上做个试验,我不该保证你也一定会成功,做参考吧!

现象我介绍一下基本系统情况:

  • 虚拟机(Oracle VM)
  • 操作系统 Ubuntu 12.04 server (该系统安装时我只选择了ssh server)
  • 真机与虚拟机使用桥接方式
  • 设置为静态IP:192.168.1.208 适情况个人设置

1.首先为了安装方便,我切换到root账户,输入命令:

sudo su

2 安装 MySQL 5

apt-get install mysql-server mysql-client

系统会提示你设置密码,输入两次密码:

New password for the MySQL “root” user: (输入密码)
Repeat password for the MySQL “root” user: (再输入一次)

3 安装 Nginx

apt-get install nginx

启动Nginx服务:

/etc/init.d/nginx start

浏览器输入网址看看是否正常:http://192.168.1.208(修改成你设置的静态IP)

网页显示”Welcome to nginx!”说明已经安装成功并运行。

4 安装 PHP5

apt-get install php5-fpm

5 设置 nginx ,修改文件:

vi /etc/nginx/nginx.conf

修改下面两行代码:

worker_processes  4;
keepalive_timeout   2;

虚拟主机配置文件修改:

vi /etc/nginx/sites-available/default

修改代码如下面的显示:

server {
        listen   80; ## listen for ipv4; this line is default and implied
        listen   [::]:80 default ipv6only=on; ## listen for ipv6
        root /usr/share/nginx/www;
        index index.php index.html index.htm;
        # Make site accessible from http://localhost/
        server_name _;
        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to index.html
                try_files $uri $uri/ /index.html;
        }
        location /doc {
                root /usr/share;
                autoindex on;
                allow 127.0.0.1;
                deny all;
        }
        #error_page 404 /404.html;
        # redirect server error pages to the static page /50x.html
        #
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /usr/share/nginx/www;
        }
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #       proxy_pass http://127.0.0.1;
        #}
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                include fastcgi_params;
        }
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
                deny all;
        }
}

重新加载nginx:

/etc/init.d/nginx reload

创建一个探针文件,测试:

vi /usr/share/nginx/www/info.php

写入内容

 

然后再打开浏览器输入:http://192.168.1.208/info.php

会显示一下支持的模块,增加模块支持,输入下面的命令查询PHP模块:

apt-cache search php5

会显示模块和模块功能解释(英文的,需要一定英文能力,谷歌或百度翻译一下,了解)
例如输入下面安装你要的模块:

apt-get install php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl

安装完毕之后重启php5-fpm

/etc/init.d/php5-fpm restart

参考:http://wiki.ubuntu.org.cn/Nginx

原文发布时间为:2012-05-18

本文来自云栖社区合作伙伴“Linux中国”

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
26天前
|
Ubuntu NoSQL 关系型数据库
Ubuntu系统下安装常用软件
Ubuntu系统下安装常用软件
57 0
Ubuntu系统下安装常用软件
|
4天前
|
Ubuntu Docker 索引
ubuntu 20.04 安装docker教程和安装中遇到的问题解决方案(超详细 附加图文教程)
ubuntu 20.04 安装docker教程和安装中遇到的问题解决方案(超详细 附加图文教程)
27 0
|
6天前
|
Ubuntu 数据安全/隐私保护
在UBUNTU虚拟机上安装R软件包
在UBUNTU虚拟机上安装R软件包
|
7天前
|
存储 编解码 Ubuntu
0-零基础安装ubuntu(超详细安装步骤)
0-零基础安装ubuntu(超详细安装步骤)
|
7天前
|
Ubuntu Linux 定位技术
手把手教你优雅的安装虚拟机 Ubuntu —— 图文并茂
手把手教你优雅的安装虚拟机 Ubuntu —— 图文并茂
|
17天前
|
Ubuntu Python
WSL ubuntu 20.04安装python3
通过以上步骤,你可以在WSL的Ubuntu 20.04上成功安装Python 3。 买CN2云服务器,免备案服务器,高防服务器,就选蓝易云。百度搜索:蓝易云
19 1
|
17天前
|
Ubuntu Python
ubuntu安装python3.9
通过以上步骤,你可以在Ubuntu上成功安装Python 3.9。 买CN2云服务器,免备案服务器,高防服务器,就选蓝易云。百度搜索:蓝易云
21 1
|
17天前
|
Ubuntu 网络安全 数据安全/隐私保护
ubuntu篇-配置FTP服务,本机和docker安装
通过以上步骤,你可以在Ubuntu上配置FTP服务,无论是本机安装还是Docker内安装,都可以提供FTP文件传输服务。 买CN2云服务器,免备案服务器,高防服务器,就选蓝易云。百度搜索:蓝易云
20 1
|
21天前
|
Kubernetes Ubuntu Linux
手把手教你如何安装Ubuntu
手把手教你如何安装Ubuntu
38 1
|
21天前
|
Ubuntu Linux 虚拟化
【Linux】ubuntu安装samba服务器
【Linux】ubuntu安装samba服务器