软件版本:
nginx 1.6.2版本下载:http://mirrors.sohu.com/nginx/nginx-1.6.2.tar.gz
mysql 5.1.72版本下载:http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.72-linux-x86_64-glibc23.tar.gz
php 5.4.37版本下载:http://mirrors.sohu.com/php/php-5.4.38.tar.bz2
安装LAMP之前必备安装包
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
解压并移动;
# 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
创建数据库用户、目录、更改属主;
# useradd -s /sbin/nologin mysql # mkdir -p /data/mysql # chown -R mysql:mysql /data/mysql
初始化数据库;
# cd /usr/local/mysql # ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
拷贝配置文件,修改my.cnf;
# 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添加路径;
# vi /etc/init.d/mysqld basedir=/usr/local/mysql datadir=/data/mysql
拷贝启动文件、添加开机启动;
# cp support-files/mysql.server /etc/init.d/mysqld # chmod 755 /etc/init.d/mysqld # chkconfig --add mysqld # chkconfig mysqld on
启动mysql;
service mysqld start
编译安装php
[[email protected] src]# tar jxvf php-5.4.37.tar.bz2 [[email protected] src]# cd php-5.4.37 [[email protected] 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 [[email protected] php-5.4.37]# make && make install
拷贝php配置文件;
[[email protected] php-5.4.37]#cp /usr/local/src/php-5.3.28/php.ini-production /usr/local/php/etc/php.ini
拷贝php-fpm启动脚本;
[[email protected] 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配置文件、修改权限、开机启动;
[[email protected] php-5.4.37]#mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf [[email protected] php-5.4.37]#chmod 755 /etc/init.d/php-fpm [[email protected] php-5.4.37]#chkconfig --add php-fpm [[email protected] php-5.4.37]#chkconfig php-fpm on
启动php-fpm;
service php-fpm start
编译安装nginx
安装pcre库
·pcre是什么:perl兼容正表达式
·为什么安装pcre:使nginx支持HTTP rewrite模块
tar zxvf pcre-8.37.tar cd pcre-8.37 ./configure make && make install
编译安装nginx;
[[email protected] ~]# cd /usr/local/src/ [[email protected] src]# tar zxvf nginx-1.6.2.tar.gz [[email protected] src]# cd nginx-1.6.2 [[email protected] nginx-1.6.2]# ./configure --prefix=/usr/local/nginx [[email protected] nginx-1.6.2]# make && make install
编写nginx启动脚本;
# 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权限、开机启动;
[[email protected] nginx-1.6.2]# chmod 755 /etc/init.d/nginx [[email protected] nginx-1.6.2]# chkconfig --add nginx [[email protected] nginx-1.6.2]# chkconfig nginx on
配置解析php
编辑nginx配置文件,找到下面的代码,删除前面的#号,更改 fastcgi_param这一行,加入nginx存放路径;
[[email protected] 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;
/usr/local/nginx/sbin/nginx -s reload
测试解析php;
[[email protected] nginx-1.6.2]# vi /data/www/index.php <?php phpinfo(); ?>
访问网站出现页面则为成功;