本文全部采用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 345 mysqld on chkconfig --level 345 php-fpm on chkconfig --level 345 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 [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -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 22 -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 #重启系统