1.安全更新
yum update
2.安装编译所需组件
yum install zlib-devel wget openssl-devel pcre pcre-devel sudo gcc make autoconf automake
3.安装与配置Nginx
./configure --prefix=/opt/nginx --user=nginx --group=nginx --with-http_ssl_module
上面的命令运行之后,会出现如下显示
接着
专门开一个用户运行nginx
useradd -M -r --shell /bin/sh --home-dir /opt/nginx nginx
编辑nginx启动脚本
vi /etc/rc.d/init.d/nginx
yum update
2.安装编译所需组件
yum install zlib-devel wget openssl-devel pcre pcre-devel sudo gcc make autoconf automake
3.安装与配置Nginx
cd /opt/
tar -zxvf nginx-1.6.2.tar.gz
cd /opt/nginx-1.6.2/
mkdir /var/lib/nginx
上面的命令运行之后,会出现如下显示
nginx path prefix: "/opt/nginx"
nginx binary file: "/opt/nginx/sbin/nginx"
nginx configuration prefix: "/opt/nginx/conf"
nginx configuration file: "/opt/nginx/conf/nginx.conf"
nginx pid file: "/opt/nginx/logs/nginx.pid"
nginx error log file: "/opt/nginx/logs/error.log"
nginx http access log file: "/opt/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
接着
make
make install
专门开一个用户运行nginx
useradd -M -r --shell /bin/sh --home-dir /opt/nginx nginx
编辑nginx启动脚本
vi /etc/rc.d/init.d/nginx
#!/bin/sh
#
# nginx – this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /opt/nginx/conf/nginx.conf
# pidfile: /opt/nginx/logs/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/opt/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/opt/nginx/conf/nginx.conf"
lockfile=/var/lock/subsys/nginx
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
start
}
reload() {
configtest || return $?
echo -n $”Reloading $prog: ”
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
修改脚本可执行权限 和启动nginx
chmod +x /etc/rc.d/init.d/nginx
chkconfig --add nginx
chkconfig nginx on
service nginx start
cp /opt/nginx/conf/nginx.conf ~/nginx.conf.backup
配置nginx 虚拟主机
还差的组件用yum 安装即可。
mkdir -p /srv/www/demo/public_html
mkdir -p /srv/www/demo/logs
配置nginx 虚拟主机
vi /opt/nginx/conf/nginx.conf
插入 include /opt/nginx-sites.conf; 在nginx.conf http{}中
4.安装php与nginx配置运行php脚本
vi /opt/nginx-sites.conf
vi /opt/nginx-sites.conf
server {
listen 80;
server_name
demo.com;
access_log /srv/www/
demo/logs/access.log;
error_log /srv/www/
demo/logs/error.log;
location / {
root /srv/www/
demo/public_html;
index index.php index.html index.htm;
}
}
4.安装php与nginx配置运行php脚本
yum update
yum install php-cli php spawn-fcgi wget
vi /usr/bin/php-fastcgi
安装MariaDB数据库
Complete!
启动mysql
service mysql start
更改nginx配置为Magento可以使用的
vi /usr/bin/php-fastcgi
#!/bin/sh
if [ `grep -c "nginx" /etc/passwd` = "1" ]; then
FASTCGI_USER=nginx
elif [ `grep -c "www-data" /etc/passwd` = "1" ]; then
FASTCGI_USER=www-data
elif [ `grep -c "http" /etc/passwd` = "1" ]; then
FASTCGI_USER=http
else
# Set the FASTCGI_USER variable below to the user that
# you want to run the php-fastcgi processes as
FASTCGI_USER=
fi
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 6 -u $FASTCGI_USER -f /usr/bin/php-cgi
vi /etc/init.d/php-fastcgi
vi /etc/init.d/php-fastcgi
#!/bin/sh
# php-fastcgi - Use php-fastcgi to run php applications
#
# chkconfig: - 85 15
# description: Use php-fastcgi to run php applications
# processname: php-fastcgi
if [ `grep -c "nginx" /etc/passwd` = "1" ]; then
OWNER=nginx
elif [ `grep -c "www-data" /etc/passwd` = "1" ]; then
OWNER=www-data
elif [ `grep -c "http" /etc/passwd` = "1" ]; then
OWNER=http
else
# Set the OWNER variable below to the user that
# you want to run the php-fastcgi processes as
OWNER=
fi
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/php-fastcgi
NAME=php-fastcgi
DESC=php-fastcgi
test -x $DAEMON || exit 0
# Include php-fastcgi defaults if available
if [ -f /etc/default/php-fastcgi ] ; then
. /etc/default/php-fastcgi
fi
set -e
case "$1" in
start)
echo -n "Starting $DESC: "
sudo -u $OWNER $DAEMON
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
killall -9 php-cgi
echo "$NAME."
;;
restart)
echo -n "Restarting $DESC: "
killall -9 php-cgi
sleep 1
sudo -u $OWNER $DAEMON
echo "$NAME."
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart}" >&2
exit 1
;;
esac
exit 0
修改脚本可执行权限 与首次启动过程
chmod +x /usr/bin/php-fastcgi
chmod +x /etc/init.d/php-fastcgi
service php-fastcgi start
chkconfig --add php-fastcgi
chkconfig php-fastcgi on
cp /etc/sudoers ~/sudoers.backup
vi /etc/sudoers
# Defaults requiretty
vi /opt/nginx-sites.conf
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /srv/www/demo/public_html$fastcgi_script_name;
}
安装MariaDB数据库
vi /etc/yum.repos.d/MariaDB.repo
# MariaDB 5.5 CentOS repository list - created 2014-03-04 11:20 UTC
[mariadb]
name = MariaDB
baseurl =
http://yum.mariadb.org/5.5/centos6-amd64
gpgcheck=1
yum install MariaDB-server MariaDB-client
# yum install MariaDB-server MariaDB-client
Loaded plugins: fastestmirror, security
base | 3.7 kB 00:00
base/primary_db | 4.4 MB 01:11
extras | 3.4 kB 00:00
extras/primary_db | 19 kB 00:00
mariadb | 1.9 kB 00:00
mariadb/primary_db | 15 kB 00:00
updates | 3.4 kB 00:00
updates/primary_db | 2.1 MB 00:22
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package MariaDB-client.x86_64 0:5.5.36-1.el6 will be obsoleting
--> Processing Dependency: MariaDB-common for package: MariaDB-client-5.5.36-1.el6.x86_64
---> Package MariaDB-server.x86_64 0:5.5.36-1.el6 will be obsoleting
---> Package mysql.x86_64 0:5.1.71-1.el6 will be obsoleted
---> Package mysql-server.x86_64 0:5.1.71-1.el6 will be obsoleted
--> Running transaction check
---> Package MariaDB-common.x86_64 0:5.5.36-1.el6 will be installed
--> Processing Dependency: MariaDB-compat for package: MariaDB-common-5.5.36-1.el6.x86_64
--> Running transaction check
---> Package MariaDB-compat.x86_64 0:5.5.36-1.el6 will be obsoleting
---> Package mysql-libs.x86_64 0:5.1.71-1.el6 will be obsoleted
--> Finished Dependency Resolution
Dependencies Resolved
==================================================================================================================
Package Arch Version Repository Size
==================================================================================================================
Installing:
MariaDB-client x86_64 5.5.36-1.el6 mariadb 10 M
replacing mysql.x86_64 5.1.71-1.el6
MariaDB-compat x86_64 5.5.36-1.el6 mariadb 2.7 M
replacing mysql-libs.x86_64 5.1.71-1.el6
MariaDB-server x86_64 5.5.36-1.el6 mariadb 42 M
replacing mysql-server.x86_64 5.1.71-1.el6
Installing for dependencies:
MariaDB-common x86_64 5.5.36-1.el6 mariadb 23 k
Transaction Summary
==================================================================================================================
Install 4 Package(s)
Total download size: 55 M
Is this ok [y/N]: y
Downloading Packages:
(1/4): MariaDB-5.5.36-centos6-x86_64-client.rpm | 10 MB 04:45
(2/4): MariaDB-5.5.36-centos6-x86_64-common.rpm | 23 kB 00:00
(3/4): MariaDB-5.5.36-centos6-x86_64-compat.rpm | 2.7 MB 01:02
(4/4): MariaDB-5.5.36-centos6-x86_64-server.rpm | 42 MB 17:44
------------------------------------------------------------------------------------------------------------------
Total 40 kB/s | 55 MB 23:34
warning: rpmts_HdrFromFdno: Header V4 DSA/SHA1 Signature, key ID 1bb943db: NOKEY
Retrieving key from
https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
Importing GPG key 0x1BB943DB:
Userid: "Daniel Bartholomew (Monty Program signing key) <dbart@askmonty.org>"
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : MariaDB-compat-5.5.36-1.el6.x86_64 1/7
Installing : MariaDB-common-5.5.36-1.el6.x86_64 2/7
Error in PREIN scriptlet in rpm package MariaDB-server-5.5.36-1.el6.x86_64
******************************************************************
A MySQL or MariaDB server package (mysql-server-5.1.71-1.el6.x86_64) is installed.
The current MariaDB server package is provided by a different
vendor (CentOS) than Monty Program AB. Some files may be installed
to different locations, including log files and the service
startup script in /etc/init.d/.
Upgrading directly from MySQL 5.1 to MariaDB 5.5 may not
be safe in all cases. A manual dump and restore using mysqldump is
recommended. It is important to review the MariaDB manual's Upgrading
section for version-specific incompatibilities.
A manual upgrade is required.
- Ensure that you have a complete, working backup of your data and my.cnf
files
- Shut down the MySQL server cleanly
- Remove the existing MySQL packages. Usually this command will
list the packages you should remove:
rpm -qa | grep -i '^mysql-'
You may choose to use 'rpm --nodeps -ev <package-name>' to remove
the package which contains the mysqlclient shared library. The
library will be reinstalled by the MariaDB-shared package.
- Install the new MariaDB packages supplied by Monty Program AB
- Ensure that the MariaDB server is started
- Run the 'mysql_upgrade' program
This is a brief description of the upgrade process. Important details
can be found in the MariaDB manual, in the Upgrading section.
******************************************************************
error: %pre(MariaDB-server-5.5.36-1.el6.x86_64) scriptlet failed, exit status 1
error: install: %pre scriptlet failed (2), skipping MariaDB-server-5.5.36-1.el6
Installing : MariaDB-client-5.5.36-1.el6.x86_64 4/7
Erasing : mysql-5.1.71-1.el6.x86_64 5/7
Erasing : mysql-libs-5.1.71-1.el6.x86_64 6/7
Verifying : MariaDB-common-5.5.36-1.el6.x86_64 1/7
Verifying : MariaDB-compat-5.5.36-1.el6.x86_64 2/7
Verifying : MariaDB-client-5.5.36-1.el6.x86_64 3/7
Verifying : mysql-libs-5.1.71-1.el6.x86_64 4/7
Verifying : MariaDB-server-5.5.36-1.el6.x86_64 5/7
mysql-server-5.1.71-1.el6.x86_64 was supposed to be removed but is not!
Verifying : mysql-server-5.1.71-1.el6.x86_64 6/7
Verifying : mysql-5.1.71-1.el6.x86_64 7/7
Installed:
MariaDB-client.x86_64 0:5.5.36-1.el6 MariaDB-compat.x86_64 0:5.5.36-1.el6
Dependency Installed:
MariaDB-common.x86_64 0:5.5.36-1.el6
Replaced:
mysql.x86_64 0:5.1.71-1.el6 mysql-libs.x86_64 0:5.1.71-1.el6
Failed:
MariaDB-server.x86_64 0:5.5.36-1.el6 mysql-server.x86_64 0:5.1.71-1.el6
启动mysql
service mysql start
更改nginx配置为Magento可以使用的
server {
listen 80;
server_name demo.com;
rewrite / $scheme://www.$host$request_uri permanent; ## Forcibly prepend a www
}
server {
listen 80 default;
## SSL directives might go here
server_name www.
demo.com *.
demo.com; ## Domain is here twice so server_name_in_redirect will favour the www
root /srv/www/
demo.com/public_html;
location / {
index index.html index.php; ## Allow a static html file to be shown first
try_files $uri $uri/ @handler; ## If missing pass the URI to Magento's front handler
expires 30d; ## Assume all files are cachable
}
## These locations would be hidden by .htaccess normally
location ^~ /app/ { deny all; }
location ^~ /includes/ { deny all; }
location ^~ /lib/ { deny all; }
location ^~ /media/downloadable/ { deny all; }
location ^~ /pkginfo/ { deny all; }
location ^~ /report/config.xml { deny all; }
location ^~ /var/ { deny all; }
location /var/export/ { ## Allow admins only to view export folder
auth_basic "Restricted"; ## Message shown in login window
auth_basic_user_file htpasswd; ## See /etc/nginx/htpassword
autoindex on;
}
location /. { ## Disable .htaccess and other hidden files
return 404;
}
location @handler { ## Magento uses a common front handler
rewrite / /index.php;
}
location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
rewrite ^(.*.php)/ $1 last;
}
location ~ .php$ { ## Execute PHP scripts
if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss
expires off; ## Do not cache dynamic content
fastcgi_pass 127.0.0.1:9000;
#fastcgi_param HTTPS $fastcgi_https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE default; ## Store code is defined in administration > Configuration > Manage Stores
fastcgi_param MAGE_RUN_TYPE store;
include
/etc/nginx/fastcgi_params; ## See /etc/nginx/fastcgi_params
}
}
还差的组件用yum 安装即可。