1.安裝nignx的源,默認cenots6沒有的。php
rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
若是所有軟件想要最新的那麼就改yum的源吧html
本人安裝的操做系統是centos 6.5,默認的yum源是centos官網的,速度慢是不用說了。因此使用yum安裝東西以前須要把yum源改成國內的。現貼上國內網易和搜狐的yum源。mysql
參考 http://mirrors.163.com/.help/centos.html 和 http://mirrors.sohu.com/help/centos.html 中的介紹。linux
設置方法以下:nginx
1,進入yum源配置目錄
cd /etc/yum.repos.dsql
2,備份系統自帶的yum源
mv CentOS-Base.repo CentOS-Base.repo.bak數據庫
下載163網易的yum源:
wget http://mirrors.163.com/.help/CentOS6-Base-163.repovim
更改文件名centos
mv CentOS6-Base-163.repo CentOS-Base.repophp-fpm
3,更新玩yum源後,執行下邊命令更新yum配置,使操做當即生效
yum clean all
yum makecache
4,除了網易以外,國內還有其餘不錯的yum源,好比搜狐的
sohu的yum源
wget http://mirrors.sohu.com/help/CentOS-Base-sohu.repo
可是搜狐的好像截止到筆者發佈此文章時,尚未centos6的yum源。
中科大的
wget http://lug.ustc.edu.cn/wiki/_export/code/mirrors/help/centos?codeblock=2
一、安裝nginx
[root@localhost ~]# yum -y install nginx 安裝nginx軟件
[root@localhost ~]# service nginx start 啓動
[root@localhost ~]# chkconfig nginx on 設置開機啓動
[root@localhost ~]# /etc/init.d/nginx restart 重啓nginx服務
[root@localhost ~]# rm -rf /usr/share/nginx/html/* 刪除nginx默認頁面
二、安裝mysql
[root@localhost ~]# yum install mysql mysql-server -y 安裝mysql
[root@localhost ~]# /etc/init.d/mysqld start 啓動mysql
[root@localhost ~]# chkconfig mysqld on 設置開機啓動
[root@localhost ~]# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf 拷貝配置文件,直接覆蓋原有的
[root@localhost ~]# reboot 重啓系統
[root@localhost ~]# mysql_secure_installation 爲root設置密碼
[root@localhost ~]# /etc/init.d/mysqld stop 啓動mysql
[root@localhost ~]# /etc/init.d/mysqld start 中止mysql
[root@localhost ~]# service mysqld restart 重啓mysql
三、安裝php
[root@localhost ~]# yum install php -y
[root@localhost ~]# yum -y install php-mysql phpgd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt libmcrypt-devel php-fpm
[root@localhost ~]# /etc/init.d/mysqld restart 重啓mysql服務
[root@localhost ~]# /etc/init.d/nginx restart 重啓nginx服務
[root@localhost ~]# /etc/rc.d/init.d/php-fpm start 啓動php-fpm服務
[root@localhost ~]# chkconfig php-fpm on 設置開機啓動
配製
一、配置nginx支持PHP
[root@localhost ~]# cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
[root@localhost ~]# vim /etc/nginx/nginx.conf
user nginx nginx; #修改 nginx 運行帳號爲:nginx 組的 nginx 用 戶!
[root@localhost ~]# cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak
[root@localhost ~]# vim /etc/nginx/conf.d/default.conf
index index.php index.html index.htm;
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PHP_VALUE "open_basedir=$document_root:/tmp/"; 添加的這行 防止跨站
include fastcgi_params;
}
#取消 FastCGI server 部分location 的註釋,並要注意 fastcgi_param 行的參數, 改成$document_root$fastcgi_script_name,或者使用絕對路徑
二、php配置
[root@localhost ~]# vim /etc/php.ini
date.timezone = PRC
expose_php = Off
#;open_basedir = .:/tmp/ 註釋掉這行
三、配置php-fpm
[root@localhost ~]# vim /etc/php-fpm.d/www.conf 編輯
user = nginx 編輯用戶爲nginx
group = nginx 修改組爲nginx
[root@localhost ~]# /etc/init.d/mysqld restart 重啓mysql
[root@localhost ~]# /etc/init.d/nginx restart 啓動nginx
[root@localhost ~]# /etc/rc.d/init.d/php-fpm restart 重啓Php-fpm
測試篇
[root@localhost ~]# cd /usr/share/nginx/html/ 進入nginx默認網站根目錄
[root@localhost html]# cat index.php 新建index.php文件
<?
phpinfo()
?>
[root@localhost html]# chown nginx.nginx /usr/share/nginx/html/ -R 設置是目錄全部者
[root@localhost html]# chmod 700 /usr/share/nginx/html/ -R 設置目錄權限
備註
[root@localhost ~]# cd /usr/share/nginx/html/ nginx默認的程序目錄
[root@localhost ~]# chown nginx.nginx /usr/share/nginx/html/ -R 權限設置
[root@localhost ~]# cd /var/lib/mysql/ 數據庫目錄是
[root@localhost ~]# chown mysql.mysql -R /var/lib/mysql/ 權限設置
[root@localhost html]# tail -n20 /var/log/nginx/error.log 查看nginx的日誌
軟件版本
[root@localhost html]# nginx -v nginx version: nginx/1.6.2[root@localhost html]# php -v PHP 5.4.36 (cli) (built: Dec 22 2014 16:06:29) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies[root@localhost html]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.5.41-cll-lve MySQL Community Server (GPL) by Atomicorp