CentOs 安装 Nginx + php + mysql (推荐方式)
本文全部采用yum进行安装, CentOs6.5 mini 版本。
一、更改yum源为网易的源加快速度, 如果是从网易镜像下载的安装包,直接注释这几项也可以
vim /etc/yum.repos.d/CentOS-Base.repo
# 需要更改的项
[base]
baseurl = http://mirror.163.com/centos/$releasever/os/$basearch/ [updates]
baseurl=http://mirror.163.com/centos/$releasever/updates/$basearch/ [extras]
baseurl=http://mirror.163.com/centos/$releasever/extras/$basearch/ [centosplus]
baseurl=http://mirror.163.com/centos/$releasever/centosplus/$basearch/
[contrib]
baseurl=http://mirror.163.com/centos/$releasever/contrib/$basearch/
二、安装依赖库
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
注:lib【生产环境库】, lib-dev【开发环境库】, lib-gdb【调试环境库】,我们安装生产环境库与开发环境库。
三、由于centos没有默认的nginx软件包,解决方法是:
1.启用REHL的附件包 (推荐)
# 32位
rpm -Uvh ftp://ftp.univie.ac.at/systems/linux/fedora/epel/6/i386/epel-release-6-8.noarch.rpm
# 64位
rpm -Uvh ftp://ftp.univie.ac.at/systems/linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
# 如果版本不对,打开列表查看最新版本号
如果既想获得 RHEL 的高质量、高性能、高可靠性,又需要方便易用(关键是免费)的软件包更新功能,那么 Fedora Project 推出的 EPEL(Extra Packages for Enterprise Linux)正好适合你。EPEL(http://fedoraproject.org/wiki/EPEL) 是由 Fedora 社区打造,为 RHEL 及衍生发行版如 CentOS、Scientific Linux 等提供高质量软件包的项目。
2. 应用第三方yum源 (不推荐)
yum install wget #安装下载工具wget
wget http://www.atomicorp.com/installers/atomic #下载atomic yum源
sh ./atomic #安装
yum check-update #更新yum软件包
四、开始一键安装Nginx, Mysql, PHP
yum -y install nginx mysql mysql-server mysql-dev php-mysql php-fpm php-cli php-pdo php-mcrypt php-mbstring php-gd php-tidy php-xml php-xmlrpc php-pear php-pecl-memcache php-eaccelerator
五、设置启动与开机启动
启动
service mysqld start
service php-fpm start
service nginx start 设置开机启动
chkconfig --level mysqld on
chkconfig --level php-fpm on
chkconfig --level nginx on 配置文件都在 /etc 下
六、配置nginx.conf, 能够使用php
vi /etc/nginx/nginx.conf
worker_processes 5;
keepalive_timeout 2;
server {
listen 80;
server_name localhost; # 这里一定要设置,否则不能支持php
#charset koi8-r;
#access_log logs/host.access.log main;
root /usr/share/nginx/html; # 放到该层级让下面的location继承
location / {
index index.php index.html index.htm;
}
error_page 404 /404.html;
location = /404.html {
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
# 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$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $ducoment_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
service nginx restart
5. 写一个php测试文件
<?php
phpinfo();
?>
如果用IP访问不了服务器,则需要配置
1. 防火墙配置, 开放80,3306端口:
vi /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [:]
:FORWARD ACCEPT [:]
:OUTPUT ACCEPT [:]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
/etc/init.d/iptables restart #最后重启防火墙使配置生效
2、关闭SELINUX
vi /etc/selinux/config
#SELINUX=enforcing #注释掉
#SELINUXTYPE=targeted #注释掉
SELINUX=disabled #增加
:wq 保存,关闭
shutdown -r now #重启系统
CentOs 安装 Nginx + php + mysql (推荐方式)的更多相关文章
- Linux--YUM 安装 nginx php mysql
Linux--YUM 安装 nginx php mysql (2011-11-13 11:27:14) 转载▼ 标签: 杂谈 分类: Linux 1.先新建一个 repo # vi /etc/yum. ...
- Linux 环境下安装 Nginx+php+mysql 开发环境
一直以来都没有养成记录学习的好习惯,我想从这么一天开始,把自己学习和工作中的经验和坑都记录下来.等到以后老的时候还有可以回忆的地方. 最近在学习linux,虽然已经玩linux很久了,但是没有怎么用心 ...
- centos 安装nginx
centos 安装nginx 安装依赖 更换源 yum install http://mirrors.163.com/centos/6.8/extras/x86_64/Packages/epel-re ...
- centos安装nginx(针对一哥们的博客进行的详细补充(用红色字体标出了补充部分))
centos安装nginx 原文地址:http://www.cnblogs.com/leechenxiang/p/5402960.html 一.什么是nginx 是一个C语言开发的HTTP反向代理服务 ...
- CentOS安装Nginx Pre-Built
CentOS安装Nginx Pre-Built比较简单,具体可参见:http://nginx.org/en/linux_packages.html#stable. 本文列出详细步骤,已做备份: cat ...
- ubuntu12.04 安装nginx+php+mysql (lnmp)的web服务器环境
1.Ubuntu12.04 安装nginx+php+mysql (lnmp)的web服务器环境 http://blog.db89.org/ubuntu12-04-install-nginx-php-m ...
- 今天用pro安装nginx+php+mysql出现故障的解决方法
今天用pro安装nginx+php+mysql出现故障的解决方法 by 伍雪颖 dyld: Library not loaded: @@HOMEBREW_CELLAR@@/openssl/1.0.1h ...
- centos 安装 nginx 及配置 的坑
centos 安装 nginx 教程 1.创建/etc/yum.repos.d/nginx. centos 安装 nginx 教程 1.创建/etc/yum.repos.d/nginx.repo to ...
- 在CentOS 7下编译安装Nginx+PHP+MySQL环境
本文转载自:http://www.softeng.cn/?p=156,本文已获得作者授权,未经作者同意,不可转载. 1.前言 本文适合于已经对Linux操作系统具有基本操作经验,并且能够在Linux或 ...
随机推荐
- 【转】jQuery on()选择器函数
on()函数用于为指定元素的一个或多个事件绑定事件处理函数. 此外,你还可以额外传递给事件处理函数一些所需的数据. 从jQuery 1.7开始,on()函数提供了绑定事件处理程序所需的所有功能,用于统 ...
- [Linked List]Reverse Linked List,Reverse Linked List II
一.Reverse Linked List (M) Reverse Linked List II (M) Binary Tree Upside Down (E) Palindrome Linked ...
- Best Time to Buy and Sell Stock I && II
Say you have an array for which the ith element is the price of a given stock on day i. If you were ...
- smarty模版使用php标签,获取模版变量!
<ul>{/foreach from=$A key=k item=val/}{/php/} $val = $this->_tpl_vars[val]; $date = substr( ...
- Python之路第四天,基础(4)-装饰器,迭代器,生成器
装饰器 装饰器(decorator)是一种高级Python语法.装饰器可以对一个函数.方法或者类进行加工.在Python中,我们有多种方法对函数和类进行加工,比如在Python闭包中,我们见到函数对象 ...
- c语言函数实现交换两个数的值
代码: #include <stdio.h> void swap(int x,int y) { int temp; temp = x; x = y; y = temp; printf(&q ...
- 怎查看linux系统的位数
# uname -a x86_64则说明你是64位内核, 跑的是64位的系统. i386, i686说明你是32位的内核, 跑的是32位的系统
- Keli Linux与网络安全(1)——在VMWare中安装Keli系统
Kali Linux是基于Debian的Linux发行版, 设计用于数字取证和渗透测试.由OffensiveSecurity Ltd维护和资助.最先由Offensive Security的Mati A ...
- paip.c++ qt 外部dll共享库的导入以及引用
paip.c++ qt 外部dll共享库的导入以及引用 作者Attilax , EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog.csdn. ...
- 开源DirectShow分析器和解码器: LAV Filter
LAV Filter 是一款开源的DirectShow视频分离和解码软件,他的分离器LAVSplitter封装了FFMPEG中的libavformat,解码器LAVAudio和LAVVideo则封装了 ...