centos6安装lnmp
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端口的监听。
- [root@localhost ~]# netstat -tunlp|grep 80
- 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端口的监听。
- [root@localhost ~]# netstat -tunlp|grep 3306
- tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2094/mysqld
还可以通过mysql客户端连接到MySQL服务器。
- [root@localhost ~]# mysql
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 2
- Server version: 5.1.73 Source distribution
- Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
- Oracle is a registered trademark of Oracle Corporation and/or its
- affiliates. Other names may be trademarks of their respective
- owners.
- Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
- mysql>
安装PHP
CentOS 默认仓库中包含了php套件,我们可以直接使用yum安装。
下面是最小化安装,我们使用php-fpm来解析php。
yum install -y php-cli php-fpm
您可以随时使用yum list php-*
查看其它php扩展,下面是默认仓库中包含的所有扩展。
- [root@localhost ~]# yum list php-*
- Loaded plugins: fastestmirror
- Loading mirror speeds from cached hostfile
- * base: mirrors.sina.cn
- * extras: mirrors.sina.cn
- * updates: mirrors.sina.cn
- Installed Packages
- php-cli.x86_64 5.3.3-48.el6_8 @updates
- php-common.x86_64 5.3.3-48.el6_8 @updates
- php-fpm.x86_64 5.3.3-48.el6_8 @updates
- Available Packages
- php.x86_64 5.3.3-48.el6_8 updates
- php-bcmath.x86_64 5.3.3-48.el6_8 updates
- php-dba.x86_64 5.3.3-48.el6_8 updates
- php-devel.x86_64 5.3.3-48.el6_8 updates
- php-embedded.x86_64 5.3.3-48.el6_8 updates
- php-enchant.x86_64 5.3.3-48.el6_8 updates
- php-gd.x86_64 5.3.3-48.el6_8 updates
- php-imap.x86_64 5.3.3-48.el6_8 updates
- php-intl.x86_64 5.3.3-48.el6_8 updates
- php-ldap.x86_64 5.3.3-48.el6_8 updates
- php-mbstring.x86_64 5.3.3-48.el6_8 updates
- php-mysql.x86_64 5.3.3-48.el6_8 updates
- php-odbc.x86_64 5.3.3-48.el6_8 updates
- php-pdo.x86_64 5.3.3-48.el6_8 updates
- php-pear.noarch 1:1.9.4-5.el6 base
- php-pecl-apc.x86_64 3.1.9-2.el6 base
- php-pecl-apc-devel.i686 3.1.9-2.el6 base
- php-pecl-apc-devel.x86_64 3.1.9-2.el6 base
- php-pecl-memcache.x86_64 3.0.5-4.el6 base
- php-pgsql.x86_64 5.3.3-48.el6_8 updates
- php-process.x86_64 5.3.3-48.el6_8 updates
- php-pspell.x86_64 5.3.3-48.el6_8 updates
- php-recode.x86_64 5.3.3-48.el6_8 updates
- php-snmp.x86_64 5.3.3-48.el6_8 updates
- php-soap.x86_64 5.3.3-48.el6_8 updates
- php-tidy.x86_64 5.3.3-48.el6_8 updates
- php-xml.x86_64 5.3.3-48.el6_8 updates
- php-xmlrpc.x86_64 5.3.3-48.el6_8 updates
- php-zts.x86_64 5.3.3-48.el6_8 updates
同样的,我们需要将php-fpm设置为开机启动。
- chkconfig php-fpm on
- service php-fpm start
启动完成后,我们可以通过netstat -tunlp|grep 9000
命令查看到,php-fpm 已经开始监听9000端口。
- [root@localhost ~]# netstat -tunlp|grep 9000
- tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 2147/php-fpm
配置nginx使其支持php程序
接下来我们演示如何部署web服务的内容。
创建web目录和文件
我们假设web目录为/var/www
,创建并进入这个目录。
- mkdir /var/www
- cd /var/www
我们新建两个文件,一个html文件,一个php文件,稍后会看到效果。
a.html的内容为:
<h1>Hello World</h1>
b.php的内容为:
- <?php
- phpinfo();
- // 将会打印出所有的PHP信息
- ?>
变更nginx配置
我们使用vim打开nginx第一个站点的配置文件vim /etc/nginx/conf.d/default.conf
。
将第9行的root
变更为我们指定的目录。
修改
- location / {
- root /usr/share/nginx/html;
- index index.html index.htm;
- }
变更为
- location / {
- root /var/www;
- index index.html index.htm;
- }
将30-36行的注释去掉,使其支持php文件,同时还需要修改root
和fastcgi_param
选项指定我们的工作目录。
修改
- # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
- #
- #location ~ \.php$ {
- # root html;
- # fastcgi_pass 127.0.0.1:9000;
- # fastcgi_index index.php;
- # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
- # include fastcgi_params;
- #}
变更为
- # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
- #
- location ~ \.php$ {
- root /var/www;
- fastcgi_pass 127.0.0.1:9000;
- fastcgi_index index.php;
- fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
- include fastcgi_params;
- }
保存后,执行service nginx reload
重新载入nginx配置。
此时,我们可以通过浏览器直接访问我们刚才建立的文件了。
结语
以上,就是lnmp的简单安装和配置,它已经可以解析php程序。生产环境中,往往还要对其配置文件进行各种更改,已对其性能进行优化。
例如,php的session目录可能默认会没有写权限、nginx的连接数要更改等各种问题。
熟悉了lnmp的简单安装以后,就可以继续深入了解,学习手动编译指定版本的nginx、php或mysql服务了。
centos6安装lnmp的更多相关文章
- 阿里云centos6.5实践编译安装LNMP架构web环境
LNMP 代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构. 本次测试需求: **实践centos6.5编译安装 LNMP生产环境 架构 web生产环境 使用 ngx_pa ...
- CENTOS6.5源码安装LNMP
CENTOS6.5源码安装LNMP 一.安装前准备 ########################################################################## ...
- linux--->阿里云centos6.9环境配置安装lnmp
阿里云centos6.9环境配置安装lnmp mysql安装 本人博客:http://www.cnblogs.com/frankltf/p/8615418.html PHP安装 1.安装依赖关系 yu ...
- 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 ...
- 细化如何安装LNMP + Zabbix 监控安装文档以及故障排除
1.LNMP所需安装包: 上传如下软件包到/soft目录中 mysql- (centos6. 64位自带)也可根据版本自行挑选,前提你了解这个版本 pcre-8.36.tar.gz nginx-.ta ...
- VPS CentOS-6 下 LNMP HTTP服务器的搭建
VPS CentOS-6 下 LNMP HTTP服务器的搭建 前言 恢复更新后的第一篇博文, 前段时间由于各种理由, 把博客更新给宕掉了, 个人独立博客的开发也搁浅了, 现在随着工作的逐步稳定, 决心 ...
- 急速安装lnmp 编译版本
急速安装lnmp 编译版本 安装msyql+PHP 系统centos6.5 安装 开发软件包 已经改成了163的源需要执行下面的代码 官网不自带 libmcrypt libmcrypt-devel w ...
- Centos7下使用yum安装lnmp zabbix3.2
1:配置epel-release mysql zabbix 源 配置epel源 wget http://mirrors.aliyun.com/epel/epel-release-latest-7.no ...
- CentOS 5.5编译安装lnmp
如果是安装Centos6.5记得Perl是必选的,否则无法安装VMWare Tools!!!!切记 如果出现make错误需要安装其他软件,装好后 make clean make install ...
随机推荐
- [poj2104]可持久化线段树入门题(主席树)
解题关键:离线求区间第k小,主席树的经典裸题: 对主席树的理解:主席树维护的是一段序列中某个数字出现的次数,所以需要预先离散化,最好使用vector的erase和unique函数,很方便:如果求整段序 ...
- 局域网中使用的IP地址有哪些?
当我们建设一个局域网的时候,需要为网络中的每台计算机分配一个IP地址.那么都有哪些IP地址可以使用在局域网中呢?局域网中的IP地址有什么规定呢? 在局域网中,我们是不能使用如202.106.45.11 ...
- bos物流面试题
BOS物流项目问题汇总 1 请描述一下这个系 统? 从两个方面回答, 第一个方面:系统背景及系统概述 本系统是基于B/S架构而设计开发的,是某物流公司的一个后台管理系统,属于物流公司整个ERP平台的一 ...
- 菜鸟大充电啦啦啦啦啦:eclipse SDK 是什么啊
为什么下载是,没有单独的ecipse呢,,总是eclipse-sdk呢 而且还很大几百兆 回复1: Eclipse有好多专用名称,例如Eclipse SDK等.先说一下SDK, Eclipse Pro ...
- iperf3
1.安装 将下载得到的“iperf-3.1.3-win64.zip”文件解压缩,得到“iperf3.exe”和“cygwin1.dll”两个文件.将这两个文件复制到“%systemroot%”(大多数 ...
- linux中制作动态库
制作一个动态库我们可以使用gcc工具来制作一个动态库示例:自己制作一个动态库,库函数的功能是传递一个字符串并输出.第一步:需要准备3个文件:hello.h.hello.c.test.c.其中hello ...
- Codeforces Beta Round #71 C【KMP+DP】
Codeforces79C 题意: 求s串的最大子串不包含任意b串: 思路: dp[i]为以i为起点的子串的最长延长距离. 我们可以想到一种情况就是这个 i 是某个子串的起点,子串的长度-1就是最短, ...
- 数据绑定—Source(绑定到静态类的静态属性)
<UserControl x:Class="绑定.绑定Source" xmlns="http://schemas.microsoft.com/winfx/2006/ ...
- cogs 915. 隐藏口令
915. 隐藏口令 ★★☆ 输入文件:hidden.in 输出文件:hidden.out 简单对比时间限制:1 s 内存限制:128 MB USACO/hidden(译 by Feli ...
- 分层图最短路【bzoj2662】[BeiJing wc2012]冻结
分层图最短路[bzoj2662][BeiJing wc2012]冻结 Description "我要成为魔法少女!" "那么,以灵魂为代价,你希望得到什么?" ...