CentOS 6.3中配置安装nginx php-fpm drupal的方法

作者:袖梨 2022-11-14

一切本着从简原则来做,能yum/rpm的,坚决不手工编译,本次部署环境基于CentOS 6.3 x86_64系统。


更新yum

代码如下 复制代码

[root@imysql ~]# yum -y update
[root@imysql ~]# yum install libaio-devel.x86_64

安装curl模块

代码如下 复制代码

[root@imysql ~]# yum install curl-devel
[root@imysql ~]# yum -y install libpng-devel libjpeg-devel freetype-devel gmp-devel libxml2-devel

安装nginx

代码如下 复制代码

[root@imysql ~]# rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
[root@imysql ~]# yum -y install nginx
[root@imysql ~]# yum install spawn-fcgi
[root@imysql ~]# chkconfig nginx on

安装php-fpm

代码如下 复制代码

[root@imysql ~]# rpm -ivh rpm -Uvh http://repo.webtatic.com/yum/el6/latest.rpm
[root@imysql ~]# yum -y install php54w

配置nginx+php

/etc/nginx/nginx.conf 配置文件可以不用做任何修改。

编辑 /etc/nginx/conf.d/default.conf,以本站为例,配置文件如下:

代码如下 复制代码

server {
listen 80;
server_name www.111cn.Net;

root /data/www/www.111com.net/;
index index.php index.htm index.html index.shtml;

error_page 404 /page_not_found;
error_page 500 502 503 504 /page_not_found;

location ~ /.ht {
deny all;
}

if ($fastcgi_script_name ~ ..*/.*php) {
return 403;
}

location / {
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?q=$1 last;
}
}

location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$ {
expires 30d;
}

location ~ .*.(js|css)?$ {
expires 1h;
}

location ^~ /sites/default/files/imagecache/ {
index index.php index.html;
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?q=$1 last; break;
}
}
}

上述配置包括了nginx虚拟主机的配置,以及drupal的rewrite规则配置,简单快速。
启动测试


每次修改完配置文件后,都记得执行下面的命令测试配置文件正确性:

代码如下 复制代码

[root@imysql ~]# /etc/init.d/nginx configtest
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

确认配置文件无误后,执行下面的命令重载nginx,使其生效,上面仔细一点的朋友会发现没有安装mysql数据库了,因为drupal是需要数据库支持的

Drupal是使用PHP语言编写的开源内容管理框架(CMF),它由内容管理系统(CMS)和PHP开发框架(Framework)共同构成,所以我们再接着来安装mysql数据库吧

安装mysql数据库

执行yum程序安装MySQL

代码如下 复制代码

1.yum install mysql mysql-server

添加MySQL进启动项(这样系统启动时会自动启动MySQL),并立即启动MySQL服务器:

代码如下 复制代码

1.chkconfig --levels 235 mysqld on

2./etc/init.d/mysqld start

设置MySQL root帐号密码:

代码如下 复制代码

1.mysql_secure_installation


NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!


In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] <-- ENTER
New password: <-- 你的MySQL root密码
Re-enter new password: <-- 你的MySQL root密码
Password updated successfully!
Reloading privilege tables..
... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] <-- ENTER
... Success!

Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] <-- ENTER
... Success!

By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] <-- ENTER
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] <-- ENTER
... Success!

Cleaning up...


All done! If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

安装phpmyadmin

从phpmyadmin官方网站:http://www.phpmyadmin.net/home_page/downloads.php下载最新的phpmyadmin安装包,下载到网站目录下默认在/var/www/html/下。解压phpmyadmin压缩包后,找到 config.sample.inc.php 重命名为 config.inc.php,修改配置,就安装完成了。

代码如下 复制代码

[root@imysql ~]# [root@imysql ~]# /etc/init.d/nginx reload
#或者restart
[root@imysql ~]# /etc/init.d/nginx restart

至此,配置完成!

相关文章

精彩推荐