1.Mysql

centos 7 下mysql被替换掉,如有需要请看另一篇:

centos 6.5下:

yum install mysql mysql-server mysql-devel

启动mysql :

centos 6.5:

/etc/init.d/mysqld start

开机启动:

centos 6.5:

chkconfig mysqld on

2.安装php

yum install php php-mysql php-common php-gd php-mbstring php-mcrypt php-devel php-xml php-fpm php-cli php-ldap php-odbc php-pdo php-pecl-memcache php-pear php-mbstring php-xml php-xmlrpc php-snmp php-soap

启动fpm:

centos 6.5:

service php-fpm start

centos 7:

systemctl enable php-fpm.service
systemctl start php-fpm.service

3.安装apache(可选)

yum install httpd httpd-devel

启动和开机启动:

/etc/init.d/httpd start
chkconfig httpd on

这里需要更改apache的默认端口,使其不为80,避免与nginx冲突,如有需要参见apache配置文件修改

4.Nginx安装

Nginx不是从官方CentOS库安装,我们从 nginx 项目安装库安装,修改源:

vi /etc/yum.repos.d/nginx.repo
修改为:
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=
enabled=
yum install nginx

启动和开机启动:

centos 7:

systemctl enable nginx.service
systemctl start nginx.service

centos 6.5:

service nginx start

5.配置nginx

现在我们打开配置文件 

/etc/nginx/nginx.conf

这里没有需要不需更改,如有需要参见nginx详细配置
vi /etc/nginx/conf.d/default.conf
server {
listen ;
server_name localhost; #charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main; location / {
root /usr/share/nginx/html;
index index.html index.htm;
} #error_page /.html; # redirect server error pages to the static page /50x.html
#
error_page /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:
#
#location ~ .php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:
# location ~ .php$ {
root /usr/share/nginx/html;
#try_files $uri =;
fastcgi_pass 127.0.0.1:;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /.ht {
deny all;
}
}

现在保存文件并重新加载nginx:

systemctl restart nginx.service

ystemctl reload nginx.service

6.打开防火墙端口:

注意:有时安装好可能无法访问,很大的原因是防火墙,需要打开80端口

通过

/etc/init.d/iptables status

命令查询是否有打开80端口,如果没有可通过两种方式处理:

1.修改vi /etc/sysconfig/iptables命令添加使防火墙开放80端口

-A RH-Firewall--INPUT -m state --state NEW -m tcp -p tcp --dport  -j ACCEPT

2.关闭防火墙
/etc/init.d/iptables stop 
#start 开启 
#restart 重启
永久性关闭防火墙chkconfig --level 35 iptables off

7.测试php

现在创建的文档根目录下的PHP探针文件 /usr/share/nginx/html

vi /usr/share/nginx/html/info.php
<?php
phpinfo();
?>

测试输入ip,根据nginx的log来调试。

8.使用php-fpm套接字来连接nginx(可选)

默认情况下监听端口 9000 。 另外,也可以使PHP-FPM使用Unix套接字,这避免了TCP的开销。要做到这一点,打开 /etc/php-fpm.d/www.conf…

vi /etc/php-fpm.d/www.conf

… 修改后如下:

[...]
;listen = 127.0.0.1:
listen = /var/run/php-fpm/php5-fpm.sock
[...]

然后重新加载 PHP-FPM:

systemctl restart php-fpm.service

接下来通过你的nginx的配置和所有的虚拟主机和改线 fastcgi_pass 127.0.0.1:9000; to fastcgi_pass unix:/tmp/php5-fpm.sock;,像这样:

vi /etc/nginx/conf.d/default.conf

[...]
location ~ .php$ {
root /usr/share/nginx/html;
try_files $uri =;
fastcgi_pass unix:/var/run/php-fpm/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
[...]

最后重新加载 nginx:

systemctl restart nginx.service

Linux -- Centos 下配置LNAMP 服务器环境的更多相关文章

  1. Linux CentOS下Python+robot framework环境搭建

    Linux CentOS下Python+robot framework环境搭建   by:授客 QQ:1033553122 操作系统环境:CentOS 6.5-x86_64 下载地址:http://w ...

  2. suse linux 10 下配置vpn服务器(pptp)

     一.安装所需的软件包:      pptpd-*.rpm      ppp-*.rpm      pptp-*.rpm     一般情况下系统已经将pptp和ppp包安装好了,所以只需安装pptpd ...

  3. 在Linux虚拟机下配置jdk的环境变量

    1.到Oracle公司的官网里下载好jdk,网址 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133 ...

  4. centos下配置gitosis服务器遇到的困难

    这篇博客主要讲的是在centos下配置gitosis遇到的问题. 背景:centos7.2 64 :gitosis2.0 1.困难1 1)产生的问题及原因.gitosis没有安装成功,没有出现fini ...

  5. Linux|CentOS下配置Maven环境

    1.下载maven包 wget http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.3.9/binaries/apache-maven ...

  6. Linux centOS下搭建RTMP服务器的具体步骤

    以下的所需的安装包,可直接在linux系统终端下载,也可从其他地方下载之后拷到对应目录下解压使用,遇到连接不到国外网站时可改变压缩包地址 1.安装依赖包: #yum install glibc.i68 ...

  7. centos下配置gitosis服务器

    背景: 一台windows电脑,Xshell可以登录centos服务器(centos7.2 64位,有root用户权限),windows电脑已经安装好git和tortoies 在windows下下载和 ...

  8. [ 原创 ]linux centos下配置java环境教程

    一.环境 centos 7.2 二.目标 在CentOS7.2上安装jdk1.8(tar.gz安装包),并配置环境变量 jdk安装在/home/soft/jdk1.8.0-131目录下 具体步骤 1. ...

  9. Linux CentOS下Python+robot framework环境搭建

    转载自:http://blog.sina.com.cn/s/blog_13cc013b50102vof1.html 操作系统环境:CentOS 6.5-x86_64 下载地址:http://www.c ...

随机推荐

  1. 简明 Python 编程规范

    http://blog.csdn.net/gzlaiyonghao/article/details/2834883

  2. Sql语句查看表结构

    快速查看表对的就说明,及表字段描述及字段类型 --表描述 SELECT tbs.name 表名,ds.value 描述 FROM sys.extended_properties ds LEFT JOI ...

  3. VS2015 Android

    最近安装了VS2015,体验了一下android 的开发,按模板创建运行了个,试下效果很不错.也可以可视化设计.但昨天再次打开或创建一个android程序后,设计界面直接不能显示,显示错误:(可能是升 ...

  4. 关于view.measure

    在编写下啦刷新的项目代码的时候,在Listview的HeaderView中的head.xml文件中,根布局为RelativeLayout的时候,在计算headerView.measure的时候,出现空 ...

  5. app测试与web测试的区别

    1.从功能测试的来讲的话,在流程和功能测试上是没有区别的.系统测试和一些细节可能会不一样. 那么我们就要先来了解,web和app的区别. web项目,一般都是b/s架构,基于浏览器的,而app则是c/ ...

  6. 解决Mac下GDB提示签名错误

    http://blog.csdn.net/powerlly/article/details/30323015

  7. 网络存储技术介绍(1) ( based on zt)

    最近由于某同学微信发了一些网络存储的文章,开始感兴趣,稍微收集了一些 一.  网络存储技术 http://ask.zol.com.cn/q/187044.html  (yxr:很老的技术介绍吧) 网络 ...

  8. HowTo Perform the spatial selection 'Share a line segment with' using ArcObjects

    HowTo  Perform the spatial selection 'Share a line segment with' using ArcObjects Article ID: 26528 ...

  9. VC++ 标准C++中的string类的用法总结

    相信使用过MFC编程的朋友对CString这个类的印象应该非常深刻吧?的确,MFC中的CString类使用起来真的非常的方便好用.但是如果离开了MFC框架,还有没有这样使用起来非常方便的类呢?答案是肯 ...

  10. strcat strcpy 使用出现的问题汇总

    事例1(转)  在程序中多次用的strcat函数,但是有时候编译通过,但是执行时却出现了错误.为了进一步了解strcat函数的使用,我首先写了这样的一个测试程序: main(){       char ...