CentOS 6 默认仓库不包含nginx,我们可以手动添加nginx的仓库。

访问nginx官网获取repo文件

我们需要先访问nginx的官方网站,获取官方的仓库地址。
点击这里访问nginx官方文档

依照文档中的说明,最后的repo文件应该是下面这样,您可以直接复制。

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/6/$basearch/
gpgcheck=0
enabled=1

使用vim将上面的配置保存到/etc/yum.repos.d/nginx.repo文件中。

安装nginx

安装好仓库后可以直接使用yum安装nginx。

yum install -y nginx

启动nginx

执行service nginx start启动nginx。

启动成功后执行netstat -tunlp|grep 80就可以看到nginx已经启动了80端口的监听。

  1. [root@localhost ~]# netstat -tunlp|grep 80
  2. tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1881/nginx

并且通过浏览器直接访问服务器的ip地址,能看到已经出现了nginx的欢迎页面。

设置nginx为开机启动

执行chkconfig nginx on设置nginx为开机启动。

安装MySQL

CentOS 6的默认仓库直接包含MySQL,可以直接通过yum安装 MySQL Server。

yum install -y mysql mysql-server

MySQL服务名称为mysqld,我们可以通过下面命令启动MySQL服务。

service mysqld start

同nginx一样,使用下面命令将mysqld加入开机启动任务。

chkconfig mysqld on

启动成功后执行netstat -tunlp|grep 3306就可以看到mysqld已经启动了3306端口的监听。

  1. [root@localhost ~]# netstat -tunlp|grep 3306
  2. tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2094/mysqld

还可以通过mysql客户端连接到MySQL服务器。

  1. [root@localhost ~]# mysql
  2. Welcome to the MySQL monitor. Commands end with ; or \g.
  3. Your MySQL connection id is 2
  4. Server version: 5.1.73 Source distribution
  5.  
  6. Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
  7.  
  8. Oracle is a registered trademark of Oracle Corporation and/or its
  9. affiliates. Other names may be trademarks of their respective
  10. owners.
  11.  
  12. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  13.  
  14. mysql>
  15.  

安装PHP

CentOS 默认仓库中包含了php套件,我们可以直接使用yum安装。
下面是最小化安装,我们使用php-fpm来解析php。

yum install -y php-cli php-fpm

您可以随时使用yum list php-*查看其它php扩展,下面是默认仓库中包含的所有扩展。

  1. [root@localhost ~]# yum list php-*
  2. Loaded plugins: fastestmirror
  3. Loading mirror speeds from cached hostfile
  4. * base: mirrors.sina.cn
  5. * extras: mirrors.sina.cn
  6. * updates: mirrors.sina.cn
  7. Installed Packages
  8. php-cli.x86_64 5.3.3-48.el6_8 @updates
  9. php-common.x86_64 5.3.3-48.el6_8 @updates
  10. php-fpm.x86_64 5.3.3-48.el6_8 @updates
  11. Available Packages
  12. php.x86_64 5.3.3-48.el6_8 updates
  13. php-bcmath.x86_64 5.3.3-48.el6_8 updates
  14. php-dba.x86_64 5.3.3-48.el6_8 updates
  15. php-devel.x86_64 5.3.3-48.el6_8 updates
  16. php-embedded.x86_64 5.3.3-48.el6_8 updates
  17. php-enchant.x86_64 5.3.3-48.el6_8 updates
  18. php-gd.x86_64 5.3.3-48.el6_8 updates
  19. php-imap.x86_64 5.3.3-48.el6_8 updates
  20. php-intl.x86_64 5.3.3-48.el6_8 updates
  21. php-ldap.x86_64 5.3.3-48.el6_8 updates
  22. php-mbstring.x86_64 5.3.3-48.el6_8 updates
  23. php-mysql.x86_64 5.3.3-48.el6_8 updates
  24. php-odbc.x86_64 5.3.3-48.el6_8 updates
  25. php-pdo.x86_64 5.3.3-48.el6_8 updates
  26. php-pear.noarch 1:1.9.4-5.el6 base
  27. php-pecl-apc.x86_64 3.1.9-2.el6 base
  28. php-pecl-apc-devel.i686 3.1.9-2.el6 base
  29. php-pecl-apc-devel.x86_64 3.1.9-2.el6 base
  30. php-pecl-memcache.x86_64 3.0.5-4.el6 base
  31. php-pgsql.x86_64 5.3.3-48.el6_8 updates
  32. php-process.x86_64 5.3.3-48.el6_8 updates
  33. php-pspell.x86_64 5.3.3-48.el6_8 updates
  34. php-recode.x86_64 5.3.3-48.el6_8 updates
  35. php-snmp.x86_64 5.3.3-48.el6_8 updates
  36. php-soap.x86_64 5.3.3-48.el6_8 updates
  37. php-tidy.x86_64 5.3.3-48.el6_8 updates
  38. php-xml.x86_64 5.3.3-48.el6_8 updates
  39. php-xmlrpc.x86_64 5.3.3-48.el6_8 updates
  40. php-zts.x86_64 5.3.3-48.el6_8 updates

同样的,我们需要将php-fpm设置为开机启动。

  1. chkconfig php-fpm on
  2. service php-fpm start

启动完成后,我们可以通过netstat -tunlp|grep 9000命令查看到,php-fpm 已经开始监听9000端口。

  1. [root@localhost ~]# netstat -tunlp|grep 9000
  2. tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 2147/php-fpm

配置nginx使其支持php程序

接下来我们演示如何部署web服务的内容。

创建web目录和文件

我们假设web目录为/var/www,创建并进入这个目录。

  1. mkdir /var/www
  2. cd /var/www

我们新建两个文件,一个html文件,一个php文件,稍后会看到效果。

a.html的内容为:

<h1>Hello World</h1>

b.php的内容为:

  1. <?php
  2. phpinfo();
  3. // 将会打印出所有的PHP信息
  4. ?>

变更nginx配置

我们使用vim打开nginx第一个站点的配置文件vim /etc/nginx/conf.d/default.conf

将第9行的root变更为我们指定的目录。

修改

  1. location / {
  2. root /usr/share/nginx/html;
  3. index index.html index.htm;
  4. }

变更为

  1. location / {
  2. root /var/www;
  3. index index.html index.htm;
  4. }

将30-36行的注释去掉,使其支持php文件,同时还需要修改rootfastcgi_param选项指定我们的工作目录。

修改

  1. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  2. #
  3. #location ~ \.php$ {
  4. # root html;
  5. # fastcgi_pass 127.0.0.1:9000;
  6. # fastcgi_index index.php;
  7. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  8. # include fastcgi_params;
  9. #}

变更为

  1. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  2. #
  3. location ~ \.php$ {
  4. root /var/www;
  5. fastcgi_pass 127.0.0.1:9000;
  6. fastcgi_index index.php;
  7. fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
  8. include fastcgi_params;
  9. }

保存后,执行service nginx reload重新载入nginx配置。

此时,我们可以通过浏览器直接访问我们刚才建立的文件了。

结语

以上,就是lnmp的简单安装和配置,它已经可以解析php程序。生产环境中,往往还要对其配置文件进行各种更改,已对其性能进行优化。

例如,php的session目录可能默认会没有写权限、nginx的连接数要更改等各种问题。

熟悉了lnmp的简单安装以后,就可以继续深入了解,学习手动编译指定版本的nginx、php或mysql服务了。

centos6安装lnmp的更多相关文章

  1. 阿里云centos6.5实践编译安装LNMP架构web环境

    LNMP 代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构. 本次测试需求: **实践centos6.5编译安装 LNMP生产环境 架构 web生产环境 使用 ngx_pa ...

  2. CENTOS6.5源码安装LNMP

    CENTOS6.5源码安装LNMP 一.安装前准备 ########################################################################## ...

  3. linux--->阿里云centos6.9环境配置安装lnmp

    阿里云centos6.9环境配置安装lnmp mysql安装 本人博客:http://www.cnblogs.com/frankltf/p/8615418.html PHP安装 1.安装依赖关系 yu ...

  4. Centos6.5中 一键安装LNMP 安装Yii2.0 手工配置

    1.一键安装LNMP cd /usr wget -c http://soft.vpser.net/lnmp/lnmp1.2-full.tar.gz tar zxf lnmp1.-full.tar.gz ...

  5. 细化如何安装LNMP + Zabbix 监控安装文档以及故障排除

    1.LNMP所需安装包: 上传如下软件包到/soft目录中 mysql- (centos6. 64位自带)也可根据版本自行挑选,前提你了解这个版本 pcre-8.36.tar.gz nginx-.ta ...

  6. VPS CentOS-6 下 LNMP HTTP服务器的搭建

    VPS CentOS-6 下 LNMP HTTP服务器的搭建 前言 恢复更新后的第一篇博文, 前段时间由于各种理由, 把博客更新给宕掉了, 个人独立博客的开发也搁浅了, 现在随着工作的逐步稳定, 决心 ...

  7. 急速安装lnmp 编译版本

    急速安装lnmp 编译版本 安装msyql+PHP 系统centos6.5 安装 开发软件包 已经改成了163的源需要执行下面的代码 官网不自带 libmcrypt libmcrypt-devel w ...

  8. Centos7下使用yum安装lnmp zabbix3.2

    1:配置epel-release mysql zabbix 源 配置epel源 wget http://mirrors.aliyun.com/epel/epel-release-latest-7.no ...

  9. CentOS 5.5编译安装lnmp

    如果是安装Centos6.5记得Perl是必选的,否则无法安装VMWare Tools!!!!切记 如果出现make错误需要安装其他软件,装好后  make clean   make install ...

随机推荐

  1. Java探索之旅(14)——文本I/O与读写

    1文件类File    ❶封装文件或路径的属性.不包括创建和读写文件操作.File实例并不会实际创建文件.不论文件存在与否,可以创建任意文件名的实例.两种实例创建方式如下:               ...

  2. Windchill 预览效果偏向左边

    文档预览效果偏左 解决方法: 1.修改worker配置,去掉“fit worksheet to a single page”的勾 2.进行services,重新启动以下服务 3.重启windchill ...

  3. CentOS 6.5 and Ubuntu 14.04 使用外部邮箱发送邮件

    我们可以使用外部邮箱(163,126,gmail,139等等)为我们发邮件 for CentOS 6.5 yum -y install mailx vi /etc/mail.rc 在文件的末行添加以下 ...

  4. 8、泛型程序设计与c++标准模板库2.3双端队列容器

    双端队列容器是一种放松了访问权限的队列.除了从队列的首部和尾部访问元素外,标准的双端队列也支持通过使用下标操作符"[]"进行直接访问. 它提供了直接访问和顺序访问方法.其头文件为& ...

  5. Struts2 资源配置文件国际化

    Struts2 资源配置文件国际化 Struts2资源文件的命名规范:basename_language_country.properties Struts2国际化如果系统同时存在资源文件.类文件,系 ...

  6. 为什么ps中CPU占用率会有超出%100的现象?

    前面的关于ps中的%CPU的含义一文已经介绍了CPU占用率的含义,那么为什么有时会在ps的输出中看到CPU占用率超出%100的现象呢?我们知道在/proc目录下每个进程都会有一个以它的PID以名字的目 ...

  7. BOX (UVA-1587) 比较代码书写上的差距

    对比一下代码的书写差距: 我的代码: #include<iostream> using namespace std; ]; ]; ]; //访问标记 bool judge(int i, i ...

  8. .Net Core 扩展使用Refit

    .Net Core 扩展使用Refit 标签(空格分隔): 未分类 在.net core 2.1当中,目前可以是用HttpClientFactory进行Http的调用,它的使用方法我不再多说,具体参见 ...

  9. MAC电脑下Pycharm新建模板默认添加作者时间等信息

    在pycharm使用过程中,对于每次新建文件的shebang行和关于代码编写者的一些个人信息快捷填写,使用模板的方式比较方便. 方法如下: 1.打开pycharm,选择Pycharm-preferen ...

  10. 《OD大数据实战》Mahout入门实例

    一.环境搭建 1. 下载 mahout-0.9-cdh5.3.6.tar.gz 2. 解压 3. mahout org.apache.mahout.clustering.syntheticcontro ...