LNMP=Liunx+nginx+mysql+php
1. 上传所需软件包
2.安装并配置libevent
2.1挂载光盘
[root@gjp99 ~]# mkdir /mnt/cdrom
[root@gjp99 ~]# mount /dev/cdrom /mnt/cdrom
mount: block device /dev/cdrom is write-protected, mounting read-only
2.2 配本地yum
[root@gjp99 ~]# vim /etc/yum.repos.d/rhel-debuginfo.repo
[root@gjp99 ~]# cat /etc/yum.repos.d/rhel-debuginfo.repo
[rhel-server]
name=Red Hat Enterprise Liunx server
baseurl=file:///mnt/cdrom/Server
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
2.3 查看开发环境:
[root@gjp99 ~]# yum grouplist |less
所需开发包:
Development Libraries
Development Tools
Legacy Network Server
X Software Development
2.4 安装prce-devel
[root@gjp99 ~]# yum list all |grep pcre
This system is not registered with RHN.
RHN support will be disabled.
pcre.i386 6.6-2.el5_1.7 installed
pcre-devel.i386 6.6-2.el5_1.7 rhel-server
[root@gjp99 ~]# yum install pcre-devel -y 默认输入y ,一直安装
2.5 加载的库文件并查看版本
[root@gjp99 ~]# ldconfig –v 可以看到从哪里调用的库文件 /lib /usr/lib/
[root@gjp99 ~]# ldconfig -pv |grep libev
libevent-1.1a.so.1 (libc6) => /usr/lib/libevent-1.1a.so.1 //老版本信息
2.6解压缩文件
[root@gjp99 ~]# tar -zxvf libevent-2.0.16-stable.tar.gz -C /usr/local/src/
[root@gjp99 ~]# cd /usr/local/src/
[root@gjp99 src]# ll
total 4
drwxr-xr-x 8 500 500 4096 Nov 19 2011 libevent-2.0.16-stable
[root@gjp99 src]# cd libevent-2.0.16-stable/
[root@gjp99 libevent-2.0.16-stable]# ls
2.7查看预安装目录:
[root@gjp99 libevent-2.0.16-stable]# ./configure --help |less
Installation directories:
--prefix=PREFIX install architecture-independent files in PREFIX [/usr/local]
2.8 开始安装----编译----整理
[root@gjp99 libevent-2.0.16-stable]# ./configure
[root@gjp99 libevent-2.0.16-stable]# make
[root@gjp99 libevent-2.0.16-stable]# make install
2.9 安装后的路径为非标准路径,系统不能自动进行加载
[root@gjp99 libevent-2.0.16-stable]# cd /usr/local/
[root@gjp99 local]# ll
total 72
drwxr-xr-x 2 root root 4096 Aug 8 2008 bin
drwxr-xr-x 2 root root 4096 Aug 8 2008 etc
drwxr-xr-x 2 root root 4096 Aug 8 2008 games
drwxr-xr-x 2 root root 4096 Aug 8 2008 include
drwxr-xr-x 2 root root 4096 Aug 8 2008 lib
drwxr-xr-x 2 root root 4096 Aug 8 2008 libexec
drwxr-xr-x 2 root root 4096 Aug 8 2008 sbin
drwxr-xr-x 4 root root 4096 Aug 2 21:19 share
drwxr-xr-x 3 root root 4096 Aug 3 14:09 src
[root@gjp99 local]# cd lib
[root@gjp99 lib]# pwd
/usr/local/lib //非标准路径
2.10 编辑配置文件,让系统能够顺利加载
[root@gjp99 lib]# vim /etc/ld.so.conf
[root@gjp99 lib]# cat /etc/ld.so.conf
include ld.so.conf.d/*.conf //编辑配置文件,放到/etc/ld.so.conf.d目录下
[root@gjp99 lib]# vim /etc/ld.so.conf.d/libevent.conf //新创建的.conf文件
[root@gjp99 lib]# cat /etc/ld.so.conf.d/libevent.conf
/usr/local/lib/
3.安装并配置nginx
3.1 解压缩到指定文件夹
[root@gjp99 ~]# tar -zxvf nginx-1.0.11.tar.gz -C /usr/local/src/
3.2 安装---编译----整理
[root@gjp99 nginx-1.0.11]# ./configure --help |less //查看要配置文件
[root@gjp99 nginx-1.0.11]# groupadd -r nginx //添加组
[root@gjp99 nginx-1.0.11]# useradd -r -g nginx -s /bin/false -M nginx //建账户并添加组
[root@gjp99 nginx-1.0.11]# ./configure \ //配置文件,带\表示换行
> --prefix=/usr \
> --sbin-path=/usr/sbin/nginx \
> --conf-path=/etc/nginx/nginx.conf \
> --error-log-path=/var/log/nginx/error.log \
> --http-log-path=/var/log/nginx/access.log \
> --pid-path=/var/run/nginx/nginx.pid \
> --lock-path=/var/lock/nginx.lock \
> --user=nginx \
> --group=nginx \
> --with-http_ssl_module \
> --with-http_flv_module \
> --with-http_stub_status_module \
> --with-http_gzip_static_module \
> --http-proxy-temp-path=/var/tmp/nginx/proxy/ \
> --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
> --with-pcre //最后一个没带\,自动执行
checking for OS //检测操作系统
+ Linux 2.6.18-164.el5 i686
checking for C compiler ... found //检测编译器
+ using GNU C compiler
+ gcc version: 4.1.2 20080704 (Red Hat 4.1.2-46)
checking for gcc -pipe switch ... found
[root@gjp99 nginx-1.0.11]# make //编译
[root@gjp99 nginx-1.0.11]# make insatll //整理文档
3.3 查看nginx是否安装成功
[root@gjp99 sbin]# ll |grep nginx
-rwxr-xr-x 1 root root 3910130 Aug 3 15:08 nginx
[root@gjp99 sbin]# nginx //启动服务
nginx: [emerg] mkdir() "/var/tmp/nginx/proxy/" failed (2: No such file or directory)
[root@gjp99 sbin]# mkdir -pv /var/tmp/nginx //创建相应目录
mkdir: created directory `/var/tmp/nginx'
[root@gjp99 sbin]# nginx //启动服务
[root@gjp99 sbin]# netstat -tupln |grep 80 //搜索相应端口
tcp 0 0 0.0.0.0:870 0.0.0.0:* LISTEN 2808/rpc.statd
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 27630/nginx: master
udp 0 0 0.0.0.0:864 0.0.0.0:* 2808/rpc.statd
udp 0 0 0.0.0.0:867 0.0.0.0:* 2808/rpc.statd
3.4 查看默认网页文件所放之处
[root@gjp99 usr]# ll -d html //路径:/usr/html
drwxr-xr-x 2 root root 4096 Aug 3 15:08 html
[root@gjp99 usr]# cd html
[root@gjp99 html]# ll
total 8
-rw-r--r-- 1 root root 383 Aug 3 15:08 50x.html
-rw-r--r-- 1 root root 151 Aug 3 15:08 index.html
[root@gjp99 html]# cat index.html
Welcome to nginx!
[root@gjp99 html]# pwd
/usr/html
4 . 常规应用:
4.1 物理目录:
[root@gjp99 html]# mkdir gjp
[root@gjp99 html]# cd gjp
[root@gjp99 gjp]# echo "guo jiping " >>index.html
[root@gjp99 ~]# vim /etc/nginx/nginx.conf
43 location / { //如果是location=/的话,只能访问主目录下的网页
44 root html;
45 index index.html index.htm;
46 }
4.2 虚拟目录:
[root@gjp99 ~]# mkdir /guo
[root@gjp99 ~]# cd /guo
[root@gjp99 guo]# echo "guo jiping tec" >index.html
[root@gjp99 guo]# vim /etc/nginx/nginx.conf
[root@gjp99 guo]# pkill -1 nginx //无需打断用户的请求,重启
4.3 基于ip的虚拟主机:
nginx主机配置:
[root@gjp99 guo]# mkdir /mkt
[root@gjp99 guo]# cd /mkt
[root@gjp99 mkt]# echo "market center ">index.html
[root@gjp99 mkt]# ifconfig eth0:0 192.168.20.101
[root@gjp99 mkt]# vim /etc/nginx/nginx.conf
35 server {
36 listen 192.168.20.100:80;
37 server_name tec.gjp.com;
38 access_log /var/log/tec.access.log;
39 error_log /var/log/tec.error.log;
40 root /guo;
41 index index.html index.htm;
42 #charset koi8-r;
中间省略……
82 }
83 server {
84 listen 192.168.20.101:80;
85 server_name mkt.gjp.com;
86 access_log /var/log/mkt.access.log;
87 error_log /var/log/mkt.error.log;
88 root /mkt;
89 index index.html index.htm;
}
[root@gjp99 mkt]# pkill -1 nginx //重启服务
[root@gjp99 mkt]# pkill nginx
[root@gjp99 mkt]# ps aux |grep nginx
root 27799 0.0 0.0 3740 524 pts/1 S+ 16:19 0:00 tail -f /var/log/nginx/access.log
root 27806 0.0 0.0 3920 688 pts/0 R+ 16:22 0:00 grep nginx
[root@gjp99 mkt]# nginx
测试机配置:
C:\Windows\System32\drivers\etc
4.4 基于主机头的配置:
[root@gjp99 mkt]#
nginx主机配置:
vim /etc/nginx/nginx.conf
35 server {
36 listen 192.168.20.100:80;
37 server_name tec.gjp.com;
38 access_log /var/log/tec.access.log;
39 error_log /var/log/tec.error.log;
40 root /guo;
41 index index.html index.htm;
42 #charset koi8-r;
中间省略……
82 }
83 server {
84 listen 192.168.20.100:80;
85 server_name mkt.gjp.com;
86 access_log /var/log/mkt.access.log;
87 error_log /var/log/mkt.error.log;
88 root /mkt;
89 index index.html index.htm;
}
[root@gjp99 mkt]# pkill -1 nginx
测试机:hosts文件修改
192.168.20.100 tec.gjp.com
192.168.20.100 mkt.gjp.com
清除缓存:
5. mysql的安装
5.1 上传mysql 及php
5.2 解压mysql
由于mysql 为绿色软件,不是源代码,故拆解位置在/usr/local/下,若是源代码则应拆解在/usr/local/src下。
[root@gjp99 ~]# tar -zxvf mysql-5.5.15-linux2.6-i686.tar.gz -C /usr/local
[root@gjp99 ~]# cd /usr/local
[root@gjp99 local]# cd mysql-5.5.15-linux2.6-i686/
[root@gjp99 mysql-5.5.15-linux2.6-i686]# ls
bin data include lib mysql-test scripts sql-bench
COPYING docs INSTALL-BINARY man README share support-files
5.3 查看安装文件并配置
vim INSTALL-BINARY
按照里面的安装步骤来详细配置mysql
groupadd mysql //创建组mysql
useradd -r -g mysql mysql // 创建系统帐号mysql,加入mysql组
cd /usr/local 进入/usr/local
ln -s mysql-5.5.15-linux2.6-i686 mysql //为该目录设置软连接,方便使用
cd mysql
chown -R mysql . //更改所有文件的所有者为mysql
chgrp -R mysql . // 更改所有文件的所属组为mysql
scripts/mysql_install_db --user=mysql //以mysql的身份执行scripts/mysql_install_db脚本
chown -R root . //再将所有文件的所有者改为root
chown -R mysql data //其中要将data目录及其子文件的所有者改为mysql
cp support-files/my-medium.cnf /etc/my.cnf
bin/mysqld_safe --user=mysql & //启动mysql 数据库,3306 端口
如果想使用service mysqld restart ,来启动数据库,则需要在/etc/init.d下要有名为mysqld 的脚本,执行下面指令,创建/etc/init.d/mysqld脚本
cp support-files/mysql.server /etc/init.d/mysqld
[root@gjp99 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@gjp99 mysql]# netstat -tupln |grep mysql
tcp 0 0 :::3306 :::* LISTEN 1922/mysqld
停止服务,再重启,测试:
[root@gjp99 mysql]# service mysqld stop
Shutting down MySQL. [ OK ]
[root@gjp99 mysql]# netstat -tupln |grep mysql
[root@gjp99 mysql]# service mysqld start
Starting MySQL.. [ OK ]
[root@gjp99 mysql]# netstat -tupln |grep mysql
tcp 0 0 :::3306 :::* LISTEN 2279/mysqld
5.4 设置mysqld开机自启动
[root@gjp99 mysql]# chkconfig --list |grep mysql //没有设置
查看/etc/init.d/mysqld文件,chkconfig: 2345 64 36 : 2345 表示可设置在2345 级别下开机启动或关闭;64 表示s64mysqld ,开机启动顺序,可在/etc/rc.d/rc3.d下查看;36 表示K36mysqld ,关机时关闭服务顺序
[root@gjp99 mysql]# chkconfig --add mysqld
[root@gjp99 mysql]# chkconfig --list |grep mysql
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@gjp99 mysql]# chkconfig mysqld on
[root@gjp99 mysql]# ll /etc/rc.d/rc3.d/ |grep mysql
lrwxrwxrwx 1 root root 16 Sep 3 18:12 S64mysqld -> ../init.d/mysqld
[root@gjp99 mysql]# ll /etc/rc.d/rc1.d/ |grep mysql
lrwxrwxrwx 1 root root 16 Sep 3 18:12 K36mysqld -> ../init.d/mysqld
5.5 调整库文件路径:
系统启动时,自动调用库文件,位置有/lib /usr/lib ,但是现在mysql的数据库文件位置在/usr/local/mysql/lib,编辑/etc/ld.so.conf文件,该文件指明包含ld.so.conf.d/下的所有.conf文件。在/etc/ld.so.conf.d/ 下新建mysql.conf文件,指明mysqld 的lib 文件的位置
[root@gjp99 mysql]# cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
[root@gjp99 mysql]# vim /etc/ld.so.conf.d/mysql.conf
[root@gjp99 mysql]# cat /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
5.6 查看是否加载到mysql 的lib 库文件
[root@gjp99 mysql]# ldconfig –v
[root@gjp99 mysql]# ldconfig -pv |grep mysql
libtcmalloc_minimal.so.0 (libc6) => /usr/local/mysql/lib/libtcmalloc_minimal.so.0
libmysqlclient.so.18 (libc6) => /usr/local/mysql/lib/libmysqlclient.so.18
libmysqlclient.so (libc6) => /usr/local/mysql/lib/libmysqlclient.so
系统的头文件位置有:/usr/include/ /usr/local/include/ ,但是mysql的头文件位置在/usr/local/mysql/include,为非标准路径,系统无法调用,应该指明位置,使系统能够找到该位置。可在 /usr/include/ 或者 /usr/local/include/下 做符号连接
[root@gjp99 mysql]# cd /usr/include
[root@gjp99 include]# ln -s /usr/local/mysql/include/ mysql
[root@gjp99 include]# ll mysql/
total 492
-rw-r--r-- 1 root mysql 4209 Jul 14 2011 decimal.h
-rw-r--r-- 1 root mysql 4087 Jul 14 2011 errmsg.h
-rw-r--r-- 1 root mysql 7078 Jul 14 2011 keycache.h
-rw-r--r-- 1 root mysql 27155 Jul 14 2011 m_ctype.h
-rw-r--r-- 1 root mysql 9733 Jul 14 2011 m_string.h
-rw-r--r-- 1 root mysql 1924 Jul 14 2011 my_alloc.h
-rw-r--r-- 1 root mysql 2101 Jul 14 2011 my_attribute.h
-rw-r--r-- 1 root mysql 4236 Jul 14 2011 my_compiler.h
-rw-r--r-- 1 root mysql 15869 Jul 14 2011 my_config.h
-rw-r--r-- 1 root mysql 7950 Jul 14 2011 my_dbug.h
-rw-r--r-- 1 root mysql 3573 Jul 14 2011 my_dir.h
-rw-r--r-- 1 root mysql 5453 Jul 14 2011 my_getopt.h
-rw-r--r-- 1 root mysql 46803 Jul 14 2011 my_global.h
-rw-r--r-- 1 root mysql 1506 Jul 14 2011 my_list.h
-rw-r--r-- 1 root mysql 2002 Jul 14 2011 my_net.h
-rw-r--r-- 1 root mysql 31701 Jul 14 2011 my_pthread.h
drwxr-xr-x 3 root mysql 4096 Sep 3 17:50 mysql
6.php的源码安装
6.1 解压缩php文件
[root@gjp99 ~]# tar -jxvf php-5.3.7.tar.bz2 -C /usr/local/src
[root@gjp99 ~]# cd /usr/local/src/
[root@gjp99 src]# ll
total 12
drwxr-xr-x 10 500 500 4096 Aug 3 14:23 libevent-2.0.16-stable
drwxr-xr-x 9 1001 1001 4096 Aug 3 14:40 nginx-1.0.11
drwxr-xr-x 13 1000 1000 4096 Aug 17 2011 php-5.3.7
[root@gjp99 src]# cd php-5.3.7/
[root@gjp99 php-5.3.7]# ls
6.2 检测----编译----整理
6.2.1 检测预编译环境:
./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --enable-fpm --with-libevent-dir=/usr/local --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --with-iconv-dir=/usr/local
6.2.2 编译make ,产生四类文件:头文件、库文件、可执行文件、说明文件
directorytreeiterator.inc
directorygraphiterator.inc
invertedregexiterator.inc
pharcommand.inc
clicommand.inc
phar.inc
Build complete.
Don't forget to run 'make test'.
6.2.3 make install //把对应文件放到相应目录
[root@gjp99 php-5.3.7]# make install
Installing PHP SAPI module: fpm
Installing PHP CLI binary: /usr/local/php/bin/
Installing PHP CLI man page: /usr/local/php/man/man1/
Installing PHP FPM binary: /usr/local/php/sbin/
Installing PHP FPM config: /usr/local/php/etc/
6.3 拷贝配置文件.
[root@gjp99 php-5.3.7]# ll php*
-rw-r--r-- 1 root root 1489 Sep 3 18:28 php5.spec
-rw-r--r-- 1 1000 1000 1489 Sep 26 2007 php5.spec.in
-rw-r--r-- 1 1000 1000 2523 Mar 7 2006 php.gif
-rw-r--r-- 1 1000 1000 68898 Feb 9 2011 php.ini-development
-rw-r--r-- 1 1000 1000 69128 Feb 9 2011 php.ini-production
[root@gjp99 php-5.3.7]# cp php.ini-production /usr/local/php/etc/php.ini
[root@gjp99 php-5.3.7]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@gjp99 php-5.3.7]# vim /usr/local/php/etc/php-fpm.conf
30 error_log = log/php-fpm.log
161 pm.max_children = 50
166 pm.start_servers = 20
171 pm.min_spare_servers = 5
176 pm.max_spare_servers = 3
182 pm.max_requests = 500
[root@gjp99 php-5.3.7]# /usr/local/php/sbin/php-fpm &
[1] 30351
[root@gjp99 php-5.3.7]# echo "/usr/local/php/sbin/php-fpm &">> /etc/rc.local
[root@gjp99 php-5.3.7]# vim /etc/nginx/fastcgi.conf
[root@gjp99 php-5.3.7]# cd /etc/nginx/
[root@gjp99 nginx]# ls
fastcgi.conf fastcgi_params.default mime.types nginx.conf.default uwsgi_params
fastcgi.conf.default koi-utf mime.types.default scgi_params uwsgi_params.default
fastcgi_params koi-win nginx.conf scgi_params.default win-utf
[root@gjp99 nginx]# cat fastcgi.conf > fastcgi_params
6.4 修改nginx的主配置文件
[root@gjp99 nginx]# vim /etc/nginx/nginx.conf
[root@gjp99 nginx]# pkill nginx //杀掉nginx进程
[root@gjp99 nginx]# nginx //启动nginx服务
nginx: [emerg] mkdir() "/var/tmp/nginx/proxy/" failed (2: No such file or directory)
[root@gjp99 nginx]# mkdir /var/tmp/nginx
6.5 测试:
[root@gjp99 nginx]# cd /mkt
[root@gjp99 mkt]# ll
total 4
-rw-r--r-- 1 root root 21 Sep 3 16:55 index.php
[root@gjp99 mkt]# cat index.php
phpinfo();
?>
[root@gjp99 mkt]# nginx
nginx 掉用php成功!
[root@gjp99 mkt]# vim index.php
[root@gjp99 mkt]# service mysqld stop
Shutting down MySQL.. [ OK ]