软件版本:
安装LAMP之前必备安装包 1
| yum install wget gcc gcc-c++ make re2c curl curl-devel libxml2 libxml2-devel libjpeg libjpeg-devel libpng libpng-devel libmcrypt libmcrypt-devel zlib zlib-devel openssl openssl-devel freetype freetype-devel gd gd-devel perl perl-devel ncurses ncurses-devel bison bison-devel libtool gettext gettext-devel cmake bzip2 bzip2-devel pcre pcre-devel
|
编译安装mysql 解压并移动;
1
2
| # tar zxvf mysql-5.1.40-linux-i686-icc-glibc23.tar.gz
# mv mysql-5.1.40-linux-x86_64-icc-glibc23 /usr/local/mysql
|
创建数据库用户、目录、更改属主; 1
2
3
| # useradd -s /sbin/nologin mysql
# mkdir -p /data/mysql
# chown -R mysql:mysql /data/mysql
|
初始化数据库; 1
2
| # cd /usr/local/mysql
# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
|
拷贝配置文件,修改my.cnf; 1
2
3
4
5
| # cp support-files/my-large.cnf /etc/my.cnf
# vim /etc/init.d/mysqld
[mysqld]
user=mysql
datadir=/data/mysql
|
很多模板配置文件在/support-files/目录下;
根据内存大小选择: ·my-small.cnf (内存 <= 64M) ·my-medium.cnf (内存 128M ) ·my-large.cnf (内存 512M) ·my-huge.cnf (内存 1G-2G) ·my-innodb-heavy-4G.cnf (内存 4GB) 编辑mysqld启动脚本,找到basedir和datadir添加路径; 1
2
3
| # vi /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/data/mysql
|
拷贝启动文件、添加开机启动; 1
2
3
4
| # cp support-files/mysql.server /etc/init.d/mysqld
# chmod 755 /etc/init.d/mysqld
# chkconfig --add mysqld
# chkconfig mysqld on
|
启动mysql;
编译安装php 1
2
3
4
| [iyunv@localhost src]# tar jxvf php-5.4.37.tar.bz2
[iyunv@localhost src]# cd php-5.4.37
[iyunv@localhost php-5.4.37]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --disable-ipv6 --with-curl
[iyunv@localhost php-5.4.37]# make && make install
|
拷贝php配置文件; 1
| [iyunv@localhost php-5.4.37]#cp /usr/local/src/php-5.3.28/php.ini-production /usr/local/php/etc/php.ini
|
拷贝php-fpm启动脚本;
1
| [iyunv@localhost php-5.4.37]#cp /usr/local/src/php-5.4.37/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
|
拷贝php-fpm配置文件、修改权限、开机启动;
1
2
3
4
| [iyunv@localhost php-5.4.37]#mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[iyunv@localhost php-5.4.37]#chmod 755 /etc/init.d/php-fpm
[iyunv@localhost php-5.4.37]#chkconfig --add php-fpm
[iyunv@localhost php-5.4.37]#chkconfig php-fpm on
|
启动php-fpm;
编译安装nginx
安装pcre库
·pcre是什么:perl兼容正表达式
·为什么安装pcre:使nginx支持HTTP rewrite模块 1
2
3
4
| tar zxvf pcre-8.37.tar
cd pcre-8.37
./configure
make && make install
|
编译安装nginx;
1
2
3
4
5
| [iyunv@localhost ~]# cd /usr/local/src/
[iyunv@localhost src]# tar zxvf nginx-1.6.2.tar.gz
[iyunv@localhost src]# cd nginx-1.6.2
[iyunv@localhost nginx-1.6.2]# ./configure --prefix=/usr/local/nginx
[iyunv@localhost nginx-1.6.2]# make && make install
|
编写nginx启动脚本;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
| # vim /etc/init.d/nginx
###########################################################################
#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"
start() {
echo -n $"Starting $prog: "
mkdir -p /dev/shm/nginx_temp
daemon $NGINX_SBIN -c $NGINX_CONF
RETVAL=$?
echo
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -TERM
rm -rf /dev/shm/nginx_temp
RETVAL=$?
echo
return $RETVAL
}
reload(){
echo -n $"Reloading $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -HUP
RETVAL=$?
echo
return $RETVAL
}
restart(){
stop
start
}
configtest(){
$NGINX_SBIN -c $NGINX_CONF -t
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
restart
;;
configtest)
configtest
;;
*)
echo $"Usage: $0 {start|stop|reload|restart|configtest}"
RETVAL=1
esac
exit $RETVAL
###########################################################################
|
设置nginx权限、开机启动;
1
2
3
| [iyunv@localhost nginx-1.6.2]# chmod 755 /etc/init.d/nginx
[iyunv@localhost nginx-1.6.2]# chkconfig --add nginx
[iyunv@localhost nginx-1.6.2]# chkconfig nginx on
|
配置解析php
编辑nginx配置文件,找到下面的代码,删除前面的#号,更改 fastcgi_param这一行,加入nginx存放路径;
1
2
3
4
5
6
7
8
| [iyunv@localhost nginx-1.6.2]# vi /usr/local/nginx/conf/nginx
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
include fastcgi_params;
}
|
重新加载nginx;
1
| /usr/local/nginx/sbin/nginx -s reload
|
测试解析php;
1
2
3
4
| [iyunv@localhost nginx-1.6.2]# vi /data/www/index.php
<?php
phpinfo();
?>
|
访问网站出现页面则为成功;
|