[三木]十分钟系列教程快速导读:
第一篇:[三木]十分钟教程之本地安装搭建Ubuntu12.04+Apache+PHP+MySQL+phpMyAdmin+Git+Gitweb(带LAMP全自动安装shell脚本)
第二篇:[三木]十分钟教程之服务器安装搭建CentOS6.x+Nginx+PHP+MariaDB(MySQL)+phpMyAdmin+Git+Gitweb(带LAMP全自动安装shell脚本)
第三篇:PHP环境搭建:Windows 7下安装配置PHP(VC6)+Apache+Mysql+phpMyAdmin环境教程(带自启动bat脚本)
第四篇:[三木]十分钟教程之本地安装搭建Ubuntu12.04+Java7+ZendStudio9.03汉化破解(带全自动安装shell脚本)
第五篇:[三木]十分钟教程之CenotOS6.x字符(最简化)安装+网卡设置+更新yum源(带自动设置网卡和更新yum源shell脚本)
第六篇:[三木]十分钟教程之CenotOS5.x 6.x服务器初始化安全设置+用SSH Key远程登录linux服务器(带自动设置shell脚本)
第七篇:[三木]十分钟教程之CentOS6.x安装搭建Apache+MariaDB(MySQL)+PHP+SSL+phpMyAdmin+Git+Gitweb(带LAMP服务器全自动安装shell脚本)
第八篇:VisualSVN Server + Tortoise SVN windows平台快速搭建SVN服务器(带SVN Hooks(钩子)自动更新测试网站)使用教程
文章版本更新
* 2012-09-02 三木 v1.1
- [ADD] 增加Git和Gitweb的安装设置
- [ADD] 增加Git和Gitweb的全自动安装Shell脚本
- [ADD] 增加MariaDB在CentOS其它版本上安装的说明
- [FIX] 更新LAMP全自动安装Shell脚本到1.1版本
- [FIX] 优化文章的排版和修改一些错别字
* 2012-08-31 三木 v1.0
- [ADD] 初始版本建立
前言:
为了方便自己今后查阅和希望对一些刚接触这方面知识的同学有所帮助,少走湾路,于是根据这段时间自已的实践经验,特意整理了几篇关于搭建本地开发环境和服 务器运行环境的教程。网上关于这方面的教程也很多,但往往过于陈旧,或是不全面,不详细,或是你抄我的,我抄你的,在互抄的过程中,也产生了一些错漏,所 以我们可以很容易的在网上搜到这方面的资料,但真正在操作的过程中却发现按他们说的方法,不能完全正确的搭建所需要的环境。本人也是深受这些劣质文章的 害,费了不少时间和精力才搭建成功。其实,只要你掌握了正确的方法,再按照正确的文档去操作,要搭建一个本地开发运行环境并不难,如果网速足够快,通过我 已整理好的Shell安装脚本进行自动安装,十分钟内你完全可以搭建起一个稳定高效的开发环境。所以特意将这些教程命名为开发运行环境搭建十分钟系统教 程。本篇是这系列教程的第二篇——[三木]十分钟教程之服务器安装搭建CentOS6.x+Nginx+PHP+MariaDB(MySQL)+phpMyAdmin+Git+Gitweb(带LNMP全自动安装shell脚本)
本篇教程中,我们用MariaDB代替大家所熟知的MySQL。因为MariaDB比MySQL有比较大的优越性。具体优点可以Google查阅相关文章。
名词解说:
LNMP是Linux web服务器组合套装的缩写,分别是Nginx+MySQL+PHP。
Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,第一个公开版本0.1.0发布于2004年10月4日。其将源代码以类BSD许可证的形式发布,因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名。
MariaDB 是一个采用 Maria 存储引擎的 MySQL 分支版本,是由原来 MySQL 的作者 Michael Widenius 创办的公司所开发的免费开源的数据库服务器。MariaDB数据库完全兼容MySQL数据库,因此可以直接把MySQL数据库的文件(.frm、.MYD、.MYI文件)拷贝到MariaDB数据库中直接运行。
与 MySQL 相比较,MariaDB 更强的地方在于:
Maria 存储引擎
PBXT 存储引擎
XtraDB 存储引擎
FederatedX 存储引擎
更快的复制查询处理
线程池
更少的警告和bug
运行速度更快
更多的 Extensions (More index parts, new startup options etc)
更好的功能测试
数据表消除
慢查询日志的扩展统计
支持对 Unicode 的排序
Git是一个由林纳斯·托瓦兹为了更好地管理linux内核开发而创立的分布式版本控制/软件配置管理软件。最初的开发动力来自于 BitKeeper和Monotone。Git最初只是作为一个可以被其他前端比如Cogito或StGIT包装的后端而开发的。不过,后来Git内核已 经成熟到可以独立地用作版本控制。很多有名的软件都使用Git来进行版本控制,其中有Linux内核、X.Org服务器和OLPC内核开发。想了解更多 Git的信息和Git优于其它版本控制软件如Svn等可以自行Google查询。
Gitweb为Git 资源库提供了一个web界面,其中一个功能是提供RSS输入,用于跟踪项目的开发进展。简单的说,Gitweb和Git的关系就像是phpMyAdmin和MySQL的关系。
安装步骤:
- 我们使用root账户进行安装,首先切换到root账户,输入命令:
su - - 开始安装Nginx和PHP-FPM之前,我们必须卸载系统中以前安装的或系统自动安装的Apache和PHP然后更新软件库。输入下面的命令:
yum remove httpd* php* mysql
yum update - Nginx+PHP安装
使用Nginx官方源,需要先安装epel扩展库和remi源,remi源基于epel,必须先安装epel源,remi包含php-fpm,mysql-server5.5(在本篇教程中我们已经使用MariaDB取代MySQL),如果只需要php-fpm可以单独安装php-fpm后禁用此源什么是epel:
epel 即: Extra Packages for Enterprise Linux 的缩写,是yum 的一个相关丰富的的软件库!
企业版Linux附加软件包(Extra Packages for Enterprise Linux,以下简称EPEL)是一个由特别兴趣小组(EPEL(http://fedoraproject.org/wiki/EPEL) 是由 Fedora 社区打造)创建、维护并管理的,针对红帽企业版Linux(RHEL)及其衍生发行版(比如CentOS、Scientific Linux)的一个高质量附加软件包项目。为什么要配置epel源呢
因为rhel6里很多开发包没有在iso里,在epel的源里(rhel6 是建立在fedra 12上的)!
官方地址: http://fedoraproject.org/wiki/EPEL
中国下载地址: ftp://mirrors.ustc.edu.cn/fedora/epel/或http://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-5.noarch.rpm下面用到的参数说明:
uvh指的是升级安装。而ivh就是指安装而已。
u---upgrade install
i---install安装EPEL源(注意:CentOs 5 的下载 EPEL5,CentOs6的下载 EPEL6 的版本,64位系统和32位系统的也请选择相应的源下载):
CentOS6源:
## CentOS 6 64位Epel源##
rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-7.noarch.rpm
## CentOS 6 32位Epel源##
rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-7.noarch.rpmCentOS5源:
## CentOS 5 64位Epel源##
rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
## CentOS 5 32位Epel源##
rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm安装REMI源(注意:CentOs 5 的下载 EPEL5,CentOs6的下载 EPEL6 的版本):
## CentOS 6 Remi源##
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
## CentOS 5 Remi源##
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm安装Nginx源:
CentOS6
rpm -Uvh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
CentOS5
rpm -Uvh http://nginx.org/packages/centos/5/noarch/RPMS/nginx-release-centos-5-0.el5.ngx.noarch.rpm安装compat-mysql55,解决MariaDB与mysql-lib版本中突的问题
##CenotOS6用到
rpm -Uvh http://rpms.famillecollet.com/enterprise/6/test/x86_64/compat-mysql55-5.5.11-1.el6.remi.x86_64.rpm
##CenotOS5用到
#rpm -Uvh http://rpms.famillecollet.com/enterprise/5/test/x86_64/compat-mysql55-5.5.11-1.el5.remi.x86_64.rpm安装Nginx,PHP 5.3.8,PHP-FPM和所需的PHP模块:
yum --enablerepo=remi,remi-test install nginx php php-fpm php-common
yum --enablerepo=remi,remi-test install php-pear php-pdo php-mysql
yum --enablerepo=remi,remi-test install php-pgsql php-pecl-memcache
yum --enablerepo=remi,remi-test install php-gd php-mbstring php-mcrypt php-xmlPHP模块列表和说明:
APC (php-pecl-apc) – APC caches and optimizes PHP intermediate code
CLI (php-cli) – Command-line interface for PHP
PEAR (php-pear) – PHP Extension and Application Repository framework
PDO (php-pdo) – A database access abstraction module for PHP applications
MySQL (php-mysql) – A module for PHP applications that use MySQL databases
PostgreSQL (php-pgsql) – A PostgreSQL database module for PHP
MongoDB (php-pecl-mongo) – PHP MongoDB database driver
SQLite (php-sqlite) – Extension for the SQLite V2 Embeddable SQL Database Engine
Memcache (php-pecl-memcache) – Extension to work with the Memcached caching daemon
Memcached (php-pecl-memcached) – Extension to work with the Memcached caching daemon
GD (php-gd) – A module for PHP applications for using the gd graphics library
XML (php-xml) – A module for PHP applications which use XML
MBString (php-mbstring) – A module for PHP applications which need multi-byte string handling
MCrypt (php-mcrypt) – Standard PHP module provides mcrypt library supportnginx安装方法二:
a、配置CentOS 6.3 第三方yum源(CentOS默认的标准源里没有nginx软件包):
#安装下载工具wget
yum install wget
#下载atomic yum源
wget http://www.atomicorp.com/installers/atomic
#安装
sh ./atomic
#更新yum软件包
yum check-update
b、安装nginx:
#安装nginx,根据提示,输入Y安装即可成功安装
yum install nginx配置nginx支持php
cp /etc/nginx/nginx.conf /etc/nginx/nginx.confbak #备份原有配置文件
vi /etc/nginx/nginx.conf #编辑
user www www; #修改nginx运行账号为:www组的www用户
:wq! #保存退出cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.confbak #备份原有配置文件
vi /etc/nginx/conf.d/default.conf #编辑index index.php index.html index.htm; #增加index.php
# 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 $document_root$fastcgi_script_name;
include fastcgi_params;
}
#取消FastCGI server部分location的注释,并要注意fastcgi_param行的参数,改为$document_root$fastcgi_script_name,或者使用绝对路径配置php-fpm
cp /etc/php-fpm.d/www.conf /etc/php-fpm.d/www.confbak #备份原有配置文件
vi /etc/php-fpm.d/www.conf #编辑
user = www #修改用户为www
group = www #修改组为www
启动 Nginx 和 PHP-FPM:
/etc/init.d/nginx start ## use restart after update
## OR ##
service nginx start ## use restart after update/etc/init.d/php-fpm start ## use restart after update
## OR ##
service php-fpm start ## use restart after update最后,设置 Nginx 和 PHP-FPM 开机自动启动:
chkconfig --add nginx
chkconfig --levels 235 nginx on
chkconfig --add php-fpm
chkconfig --levels 235 php-fpm on - MariaDB的安装
方法一:
yum安装参考网址(速度可能有点慢):
1、http://kb.askmonty.org/en/installing-mariadb-with-yum/#importing-the-mariadb-signing-key
2、http://downloads.mariadb.org/mariadb/repositories/
#导入MariaDB签名##########################################################
rpm --import http://yum.mariadb.org/RPM-GPG-KEY-MariaDB
#添加MariaDB Yum 源#######################################################
echo '# MariaDB repository list - created 2012-08-12 10:47 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/5.5/centos5-amd64
gpgcheck=1'>>/etc/yum.repos.d/MariaDB.repo
echo 中的内容是针对CentOS6系列64位的系统,如果您的系统是其它的版本,请在http://downloads.mariadb.org/mariadb/repositories/中自行选择,然后替换上面的内容#通过Yum安装MariaDB#######################################################
yum install MariaDB-server MariaDB-client
#启动MariaDB#############################################################
/etc/init.d/mysql start方法二:
rpm安装:
参考网址:http://kb.askmonty.org/en/installing-mariadb-with-the-rpm-tool/加入启动项并启动mysql
chkconfig --levels 235 mysql on
/etc/init.d/mysql start
设置mysql密码及相关设置
mysql_secure_installation
因为第一次启动这命令,所以直接回车下一步,然后输入你的mysql密码,按照提示操作,删除test数据库和禁止root用户远程登录等。 - 安装phpMyAdmin来管理MySQL:
yum -y install phpmyadmin
将phpMyAdmin的配置文件复制到apache配置文件目录:
修改nginx配置文件cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak #备份配置文件vi /etc/nginx/conf.d/default.conf #修改配置文件,在server {
listen 80;
server_name localhost;#charset koi8-r;#access_log logs/host.access.log main;
location / {
root html;
index index.php index.html index.htm;
}下面添加以下内容:
location /phpmyadmin {
alias /usr/share/phpmyadmin;
index index.php;
}location ~ /phpmyadmin/.+\.php$ {
if ($fastcgi_script_name ~ /phpmyadmin/(.+\.php.*)$) {
set $valid_fastcgi_script_name $1;
}
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/phpmyadmin/$valid_fastcgi_script_name;
}:wq! #保存,退出
设置/home/phpmyadmin目录权限
chown www.www /usr/share/phpmyadmin -R #修改目录所有者为www账号
service nginx restart #重启nginx
service php-fpm restart #重启php-fpm
现在可以使用域名+phpmyadmin来访问了http://192.168.1.100/phpmyadmin/
- 安装git和gitweb安装git
安装git非常简单,在CentOS下只要以下命令即可# yum install git
(用 yum install git-core也可以)
安装gitweb
# yum install gitweb
系统默认安装到了/var/www/git下
配置nginx访问git,git需要CGI支持,配置nginx支持CGI请参考网址:http://blog.onovps.com/archives/nginx-perl-fastcgi.html
配置文件参考:server { listen 80; #listen 443; server_name cgi.test.com; index gitweb.cgi; error_log /var/log/nginx/git.error.log; access_log /var/log/nginx/git.access.log; # ssl because cox sucks #ssl on; #ssl_certificate /etc/nginx/ssl/git.eatabrick.org; #ssl_certificate_key /etc/nginx/ssl/server.key; root /var/www/git; # static repo files for cloning over https location ~ ^.*\.git/objects/([0-9a-f]+/[0-9a-f]+|pack/pack-[0-9a-f]+.(pack|idx))$ { root /data/wwwroot/git/; } # requests that need to go to git-http-backend location ~ ^.*\.git/(HEAD|info/refs|objects/info/.*|git-(upload|receive)-pack)$ { root /data/wwwroot/git; fastcgi_pass unix:/tmp/perl-fastcgi.sock; fastcgi_param SCRIPT_FILENAME /usr/libexec/git-core/git-http-backend; fastcgi_param PATH_INFO \$uri; fastcgi_param GIT_PROJECT_ROOT /data/wwwroot/git; include fastcgi_params; } # send anything else to gitweb if it\'s not a real file try_files \$uri @gitweb; location @gitweb { fastcgi_pass unix:/tmp/perl-fastcgi.sock; fastcgi_param SCRIPT_FILENAME /var/www/git/gitweb.cgi; fastcgi_param PATH_INFO \$uri; fastcgi_param GITWEB_CONFIG /etc/gitweb.conf; include fastcgi_params; } }
service nginx restart #重启nginx
service php-fpm restart #重启php-fpm
就可以通过IE浏览,http://xxxx/git/gitweb.cgi
Git全自动安装shell脚本#!/bin/bash # ------------------------------------------------------------------------------- # Filename: git.sh # Revision: 1.1 # Date: 2012/09/10 # Author: 三木 # Email: linmaogan#gmail.com # Website: www.3mu.me # Description: 安装git # Notes: 需要切换到root运行,版本针对64位系统,操作系统为CentOS6.3 # ------------------------------------------------------------------------------- # Copyright: 2012 (c) 三木 # License: GPL # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # you should have received a copy of the GNU General Public License # along with this program (or with Nagios); # # Credits go to Ethan Galstad for coding Nagios # If any changes are made to this script, please mail me a copy of the changes # ------------------------------------------------------------------------------- #Version 1.0 #2012-08-21 三木 初始版本建立 #Version 1.1 #2012-09-10 三木 增加git的web服务器类型判断 # ------------------------------------------------------------------------------- #变量定义############################################################################# #设置做为git的web服务器的类型,apache或nginx SERVICE=apache #设置Git默认访问的用户名和密码,可根据实际进行修改 DEFAULT_USER1=linmaogan DEFAULT_USER2=linmaogan DEFAULT_PASSWORD=123456 #安装git############################################################################### yum -y install git #安装gitweb############################################################################ yum -y install gitweb #设置版本库的根目录#################################################################### cp -p /etc/gitweb.conf /etc/gitweb.conf.bak sed -i 's/$projectroot = /#$projectroot = /g' /etc/gitweb.conf echo '$projectroot = "/data/wwwroot/git";' >> /etc/gitweb.conf #开启网址伪静态 echo '$feature{'pathinfo'}{'default'} = [1];' >> /etc/gitweb.conf #生成虚拟主机配置文件################################################################## if [ $SERVICE == 'apache' ];then echo ' ServerAdmin webmaster@build-server ServerName nb.tooqe.com #ServerAlias guiwan.com Alias /gitweb.css /var/www/git/gitweb.css Alias /gitweb.js /var/www/git/gitweb.js Alias /git-logo.png /var/www/git/git-logo.png Alias /git-favicon.png /var/www/git/git-favicon.png SetEnv GIT_PROJECT_ROOT /data/wwwroot/git SetEnv GIT_HTTP_EXPORT_ALL SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER AuthType Basic AuthName "Git" AuthUserFile /data/conf/gitweb.passwd Require valid-user Options +ExecCGI -Includes # This pattern matches git operations and passes them to http-backend ScriptAliasMatch \ "(?x)^/git/(.*/(HEAD | \ info/refs | \ objects/(info/[^/]+ | \ [0-9a-f]{2}/[0-9a-f]{38} | \ pack/pack-[0-9a-f]{40}\.(pack|idx)) | \ git-(upload|receive)-pack))$" \ /usr/libexec/git-core/git-http-backend/$1 # Anything not matched above goes to displayable gitweb interface ScriptAlias /git /var/www/git/gitweb.cgi/ Options FollowSymLinks +ExecCGI AddHandler cgi-script .cgi ' > /data/conf/sites-available/gitweb.conf else cat > /data/conf/sites-available/gitweb.conf << EOFI server { listen 80; #listen 443; server_name cgi.test.com; index gitweb.cgi; error_log /var/log/nginx/git.error.log; access_log /var/log/nginx/git.access.log; # ssl because cox sucks #ssl on; #ssl_certificate /etc/nginx/ssl/git.eatabrick.org; #ssl_certificate_key /etc/nginx/ssl/server.key; root /var/www/git; # static repo files for cloning over https location ~ ^.*\.git/objects/([0-9a-f]+/[0-9a-f]+|pack/pack-[0-9a-f]+.(pack|idx))$ { root /data/wwwroot/git/; } # requests that need to go to git-http-backend location ~ ^.*\.git/(HEAD|info/refs|objects/info/.*|git-(upload|receive)-pack)$ { root /data/wwwroot/git; fastcgi_pass unix:/tmp/perl-fastcgi.sock; fastcgi_param SCRIPT_FILENAME /usr/libexec/git-core/git-http-backend; fastcgi_param PATH_INFO \$uri; fastcgi_param GIT_PROJECT_ROOT /data/wwwroot/git; include fastcgi_params; } # send anything else to gitweb if it\'s not a real file try_files \$uri @gitweb; location @gitweb { fastcgi_pass unix:/tmp/perl-fastcgi.sock; fastcgi_param SCRIPT_FILENAME /var/www/git/gitweb.cgi; fastcgi_param PATH_INFO \$uri; fastcgi_param GITWEB_CONFIG /etc/gitweb.conf; include fastcgi_params; } } EOFI fi #apache创建sites-available/*到sites-enabled/*的链接 ln -s /data/conf/sites-available/gitweb.conf /data/conf/sites-enabled/ #创建初始密码########################################################################## htpasswd -bc /data/conf/gitweb.passwd $DEFAULT_USER1 $DEFAULT_PASSWORD htpasswd -b /data/conf/gitweb.passwd $DEFAULT_USER2 $DEFAULT_PASSWORD #重启所有服务器 if [ $SERVICE == 'apache' ];then /etc/init.d/nginx restart /etc/init.d/php-fpm restart /etc/init.d/perl-fastcgi restart else /etc/init.d/httpd restart fi /etc/init.d/mysql restart
- 本文在CentOS 6 64bit minimal版本上测试通过
- 到此,我们LNMP运行环境的搭建已经完成。
- 本来还打算写另一篇教程:[三木]十分钟教程之服务器安装搭建CentOS5.x+Nginx+PHP+MariaDB(MySQL)+phpMyAdmin(带LAMP全自动安装shell脚本),因为CentOS5.x和6.x的安装设置差不多,只是需要对yum源做相应的修改即可,所以针对CentOS5.x不再额外出教程,需要在这个版本上配置LNMP运行环境的同学直接参考这篇教程即可。
- LNMP全自动安装Shell脚本:
#!/bin/bash # ------------------------------------------------------------------------------- # Filename: lnmp.sh # Revision: 1.0 # Date: 2012/08/21 # Author: 三木 # Email: linmaogan#gmail.com # Website: www.3mu.me # Description: CentOS6.3+Nginx+PHP+MariaDB+Memcache及相关扩展安装脚本 # Notes: 需要切换到root运行,版本针对64位系统,操作系统为CentOS6.3 # ------------------------------------------------------------------------------- # Copyright: 2012 (c) 三木 # License: GPL # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # you should have received a copy of the GNU General Public License # along with this program (or with Nagios); # # Credits go to Ethan Galstad for coding Nagios # If any changes are made to this script, please mail me a copy of the changes # ------------------------------------------------------------------------------- #Version 1.0 #2012-08-21 三木 初始版本建立 #Version 1.1 #2012-09-01 三木 修复php不能连接mysql的bug # ------------------------------------------------------------------------------- #变量定义############################################################################# IS_VPS=1 #解锁系统文件######################################################################### chattr -i /etc/passwd chattr -i /etc/group chattr -i /etc/shadow chattr -i /etc/gshadow #如果已安装Apache和PHP,则卸载######################################################## yum -y remove httpd* php* mysql #更新软件库########################################################################### yum -y update #安装Nginx源########################################################################## rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm #安装EPEL源########################################################################### rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-7.noarch.rpm #安装REMI源########################################################################### rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm #安装Nginx############################################################################ yum -y --enablerepo=remi,remi-test install nginx #加入启动项########################################################################### chkconfig --levels 235 nginx on #start Nginx########################################################################## /etc/init.d/nginx start #安装compat-mysql55,解决MariaDB与mysql-lib版本突的问题############################### ##CenotOS6用到 rpm -Uvh http://rpms.famillecollet.com/enterprise/6/test/x86_64/compat-mysql55-5.5.11-1.el6.remi.x86_64.rpm ##CenotOS5用到 #rpm -Uvh http://rpms.famillecollet.com/enterprise/5/test/x86_64/compat-mysql55-5.5.11-1.el5.remi.x86_64.rpm #安装PHP和常用库###################################################################### yum -y --enablerepo=remi,remi-test install php php-fpm php-common php-pear php-pdo php-mysql php-pgsql php-pecl-memcache php-gd php-mbstring php-mcrypt php-xml #php-fpm加入启动项#################################################################### chkconfig --levels 235 php-fpm on #安装phpmyadmin####################################################################### yum -y install phpmyadmin #Importing the MariaDB Signing Key#################################################### rpm --import http://yum.mariadb.org/RPM-GPG-KEY-MariaDB #Adding the MariaDB YUM Repository#################################################### echo '# MariaDB repository list - created 2012-08-12 09:38 UTC # http://downloads.mariadb.org/mariadb/repositories/ [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/5.5/centos6-amd64 gpgcheck=1'>>/etc/yum.repos.d/MariaDB.repo #Installing MariaDB with YUM########################################################## yum -y install MariaDB-server MariaDB-client #加入启动项########################################################################### chkconfig --levels 235 mysql on #start MariaDB######################################################################## /etc/init.d/mysql start #设置mysql密码及相关设置############################################################## mysql_secure_installation #配置php-fpm修改用户为nginx cp /etc/php-fpm.d/www.conf /etc/php-fpm.d/www.conf.bak #备份原有配置文件 sed -i 's/user = apache/user = www/g s/group = apache/group = www/g' /etc/php-fpm.d/www.conf #配置nginx支持php cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak #备份原有配置文件 sed -i '1,5s/user nginx/user www www/g s/include \/etc\/nginx\/conf.d/#include \/etc\/nginx\/conf.d/g /include \/etc\/nginx\/conf.d/a\\include \/data\/conf\/sites-enabled\/\*;' /etc/nginx/nginx.conf #修改nginx运行账号为:www组的www用户 echo "server { listen 80; server_name localhost; charset utf8; #access_log /var/log/nginx/log/host.access.log main; location / { root /www/wwwroot/web; index index.html index.htm index.php; #增加index.php } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /www/wwwroot/web; } # 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 # #取消FastCGI server部分location的注释,并要注意fastcgi_param行的参数,改为$document_root$fastcgi_script_name,或者使用绝对路径 location ~ \.php$ { root /www/wwwroot/web; fastcgi_pass 127.0.0.1:9000; 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; #} }" > /etc/nginx/conf.d/default.conf ##################################################################################### ##################################################################################### #目录设置############################################################################ #创建网站相关目录#################################################################### if [ $IS_VPS ];then mkdir /home/data ln -s /home/data /data else mkdir /data fi mkdir /www mkdir /data/wwwroot ln -s /data/wwwroot /www/ mkdir /data/wwwroot/log mkdir /data/wwwroot/web mkdir /data/wwwroot/git mkdir /data/conf mkdir /data/conf/sites-available mkdir /data/conf/sites-enabled mkdir /backup ln -s /backup /data/ #配置文件目录设置###################################################################### #移动nginx配置文件 cp -p /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak mv /etc/nginx/conf.d/default.conf /data/conf/sites-available/ ln -s /data/conf/sites-available/default.conf /data/conf/sites-enabled/ cp -p /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak mv /etc/nginx/nginx.conf /data/conf/ ln -s /data/conf/nginx.conf /etc/nginx/ #移动mysql配置文件 cp -p /etc/my.cnf /etc/my.cnf.bak mv /etc/my.cnf /data/conf/ ln -s /data/conf/my.cnf /etc/ #移动mysql数据库 cp -p /var/lib/mysql /var/lib/mysql-bak mv /var/lib/mysql /data/ ln -s /data/mysql /var/lib/ #移动php配置文件 cp -p /etc/php.ini /etc/php.ini.bak mv /etc/php.ini /data/conf/ ln -s /data/conf/php.ini /etc/ #移动php配置文件 cp -p /etc/php-fpm.conf /etc/php-fpm.conf.bak mv /etc/php-fpm.conf /data/conf/ ln -s /data/conf/php-fpm.conf /etc/ #添加www组和www用户#################################################################### groupadd www useradd -g www www #设置目录权限########################################################################## chown -R www:www /data/wwwroot/web #php配置############################################################################# #修改时区 #禁用的函数 #禁止显示php版本的信息 sed -i 's/;date.timezone \=/date.timezone \= PRC/ s/disable_functions \=/disable_functions \= passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname/ s/expose_php = On/expose_php = Off/' /data/conf/php.ini #设置session文件为www用户组 chown -R root:www /var/lib/php/session #phpMyAdmin配置###################################################################### #设置config.inc.php文件为www用户组 chown root:www /usr/share/phpmyadmin/config.inc.php #配置配置文件,将这里tooqe.com文字修改为自己的字符,可任意 sed -i "/blowfish_secret/s/''/'tooqe.com'/" /usr/share/phpmyadmin/config.inc.php #phpMyAdmin虚拟主机设置 echo 'server { server_name nb.tooqe.com; root /data/wwwroot/web; access_log /data/wwwroot/log/nb.tooqe.com-access.log; error_log /data/wwwroot/log/nb.tooqe.com-error.log; location / { index index.html index.htm index.php; } location /phpmyadmin { alias /usr/share/phpmyadmin; index index.php; } location ~ /phpmyadmin/.+\.php$ { if ($fastcgi_script_name ~ /phpmyadmin/(.+\.php.*)$) { set $valid_fastcgi_script_name $1; } include fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/phpmyadmin/$valid_fastcgi_script_name; } location ~ \.php$ { include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } }' > /data/conf/sites-available/phpmyadmin.conf ln -s /data/conf/sites-available/phpmyadmin.conf /data/conf/sites-enabled/phpmyadmin.conf #设置/usr/share/phpmyadmin目录权限 chown www.www /usr/share/phpmyadmin -R #修改目录所有者为www账号 #开启防火墙 /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT /sbin/iptables -I INPUT -p tcp --dport 443 -j ACCEPT /sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT /etc/rc.d/init.d/iptables save /etc/init.d/iptables restart #重启所有服务器 /etc/init.d/nginx restart /etc/init.d/php-fpm restart /etc/init.d/mysql restart #/etc/init.d/memcached restart #系统文件加锁 chattr +i /etc/passwd chattr +i /etc/shadow chattr +i /etc/gshadow chattr +i /etc/group
不错的文章,内容博学多才.禁止此消息:nolinkok@163.com
非常好的文章,我有些关于php-mysql安装的问题,能帮助我么?我QQ332731151
回复@桂林_元元:都是被电脑给整的
快出师了