首先安装nginx
在安装nginx时有几个依赖包,我们首先安装依赖
[root@localhost ~]# vim /etc/yum.repos.d/rhel-debuginfo.repo
[root@localhost ~]# mkdir /mnt/cdrom/
[root@localhost ~]# mount /dev/cdrom /mnt/cdrom/
mount: block device /dev/cdrom is write-protected, mounting read-only
[root@localhost ~]# yum list all |grep libevent
[root@localhost ~]# ldconfig -v |grep libevent
libevent-1.1a.so.1 -> libevent-1.1a.so.1.0.2
[root@localhost ~]# yum list all |grep pcre
[root@localhost ~]# rpm -qip /mnt/cdrom/Server/pcre-devel-6.6-2.el5_1.7.i386.rpm
[root@localhost ~]# yum install pcre-devel
[root@localhost ~]# ll
解压缩依赖的包:
[root@localhost ~]# tar -zxvf libevent-2.0.16-stable.tar.gz -C /usr/src/
[root@localhost ~]# cd /usr/src/
[root@localhost src]# ll
[root@localhost src]# cd libevent-2.0.16-stable/
[root@localhost libevent-2.0.16-stable]# ls
[root@localhost libevent-2.0.16-stable]# ./configure
[root@localhost libevent-2.0.16-stable]# make
[root@localhost libevent-2.0.16-stable]# make install
[root@localhost libevent-2.0.16-stable]# cd /usr/local/
[root@localhost local]# ll
[root@localhost local]# ldconfig -v |grep libevent
libevent-1.1a.so.1 -> libevent-1.1a.so.1.0.2
[root@localhost local]# pwd
/usr/local
[root@localhost local]# vim /etc/ld.so.conf.d/libevent.conf
[root@localhost local]# ll lib
[root@localhost local]# ldconfig -v |grep libevent
[root@localhost local]# cd
首先解压源码包:
[root@localhost ~]# tar -zxvf nginx-1.1.18.tar.gz -C /usr/src/
[root@localhost ~]# cd /usr/src/
进入源码包目录进行预编译:
[root@localhost src]# cd /usr/src/nginx-1.1.18/
[root@localhost nginx-1.1.18]# groupadd -r nginx
[root@localhost nginx-1.1.18]# useradd -r -g nginx -s /bin/false -M nginx
[root@localhost nginx-1.1.18]# ./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-client-body-temp-path=/var/tmp/nginx/client/ \
> --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)
编译:
[root@localhost nginx-1.1.18]# make
安装:
[root@localhost nginx-1.1.18]# make install
[root@localhost nginx-1.1.18]# echo $PATH
/usr/lib/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[root@localhost nginx-1.1.18]# nginx
nginx: [emerg] mkdir() "/var/tmp/nginx/client/" failed (2: No such file or directory)
[root@localhost nginx-1.1.18]# mkdir -pv /var/tmp/nginx/client
mkdir: created directory `/var/tmp/nginx'
mkdir: created directory `/var/tmp/nginx/client'
启动nginx并查看端口:
[root@localhost nginx-1.1.18]# nginx
[root@localhost nginx-1.1.18]# netstat -tupln |grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 13366/nginx: master
用浏览器访问: http://192.168.101.188
安装:mysql-5.1.45.tar.gz
安装依赖:
[root@localhost ~]# yum -y install ncurses-devel
创建MySQL用户:
[root@localhost ~]# groupadd -r mysql
[root@localhost ~]# useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql
解压安装:
[root@localhost ~]# tar -zxvf mysql-5.0.95.tar.gztar.gz
[root@localhost ~]# cd mysql-5.0.95
[root@localhost mysql-5.1.45]# ./configure --prefix=/usr/local/mysql \
> --without-debug \
> --with-extra-charsets=utf8,gbk \
> --enable-assembler \
> --with-mysqld-ldflags=-all-static \
> --with-client-ldflags=-all-static \
> --with-unix-socket-path=/tmp/mysql.sock \
> --with-ssl
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
[root@localhost mysql-5.0.95]# make && make install
安装完成后复制配置文件和启动脚本:
[root@localhost mysql-5.0.95]# cp support-files/my-medium.cnf /etc/my.cnf
[root@localhost mysql-5.0.95]# cp support-files/mysql.server /etc/init.d/mysqld
cp: overwrite `/etc/init.d/mysqld'? y
[root@localhost mysql-5.0.95]# chmod +x /etc/init.d/mysqld
为了以后方便我们为所有的二进制可执行文件和动态链接库文件做一个软连接:
[root@localhost mysql-5.0.95]# ln -s /usr/local/mysql/bin/* /usr/local/bin/
[root@localhost mysql-5.0.95]# ln -s /usr/local/mysql/lib/mysql/lib* /usr/lib/
然后我们初始化数据库:
[root@localhost mysql-5.0.95]# mysql_install_db --user=mysql
配置完毕后我们启动mysql:
然后我们通过mysql命令来连接mysql:
[root@localhost mysql-5.0.95]# mysql
安装PHP
安装PHP前首先要安装几个源码包依赖:
第一个:解压安装libmcrypt-2.5.8.tar.bz2
[root@localhost ~]# tar -jxvf libmcrypt-2.5.8.tar.bz2
[root@localhost ~]# cd libmcrypt-2.5.8
[root@localhost libmcrypt-2.5.8]# make && make install
第二个:解压安装mhash-0.9.9.9.tar.bz2
[root@localhost libmcrypt-2.5.8]# cd
[root@localhost ~]# tar -jxvf mhash-0.9.9.9.tar.bz2
[root@localhost ~]# cd mhash-0.9.9.9
[root@localhost mhash-0.9.9.9]# ./configure
[root@localhost mhash-0.9.9.9]# make && make install
这两个包安装完成后要把动态链接库做一个软连接到/usr/lib,以为接下来的mcrypt依赖于这两个包
[root@localhost mhash-0.9.9.9]# ln -s /usr/local/lib/libmcrypt* /usr/lib
[root@localhost mhash-0.9.9.9]# ln -s /usr/local/lib/libmhash.* /usr/lib/
第三个:解压安装mcrypt-2.6.8.tar.gz
[root@localhost mhash-0.9.9.9]# cd
[root@localhost ~]# tar -zxvf mcrypt-2.6.8.tar.gz
[root@localhost ~]# cd mcrypt-2.6.8
[root@localhost mcrypt-2.6.8]# ./configure
[root@localhost mcrypt-2.6.8]# make && make install
[root@localhost mcrypt-2.6.8]# cd
解压安装php:
[root@localhost ~]# tar -zxvf php-5.4.0.tar.gz
[root@localhost ~]# cd php-5.4.0
[root@localhost php-5.4.0]# ./configure --prefix=/usr/local/php \
> --with-mysql=/usr/local/mysql/ \
> --with-zlib \
> --enable-xml \
> --disable-rpath \
> --enable-safe-mode \
> --enable-bcmath \
> --enable-shmop \
> --enable-sysvsem \
> --with-curl \
> --with-curlwrappers \
> --enable-fpm \
> --enable-fastcgi \
> --with-mcrypt \
> --with-gd \
> --with-openssl \
> --with-mhash \
> --enable-sockets \
> --with-ldap \
> --with-ldap-sasl \
> --with-xmlrpc \
> --enable-zip \
> --enable-soap
creating cache ./config.cache
checking for Cygwin environment... no
checking for mingw32 environment... no
checking for egrep... grep -E
checking for a sed that does not truncate output... /bin/sed
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
[root@localhost php-5.4.0]# make $$ make install
配置php和nginx能运行php网站,首先为php创建配置文件:
[root@localhost php-5.4.0]# cp php.ini-production /usr/local/php/php.ini
[root@localhost php-5.4.0]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@localhost php-5.4.0]# ln -s /usr/local/php/bin/php /usr/bin/
配置php-fpm,编辑php-fpm.conf
[root@localhost php-5.4.0]# vim /usr/local/php/etc/php-fpm.conf
找到listen那一行,修改成如下内容:
143 listen = /var/run/php-fpm/php-fpm.sock
启动php-fpm
[root@localhost php-5.4.0]# mkdir /var/run/php-fpm
[root@localhost html]# cd /usr/local/php/sbin/
[root@localhost sbin]# ./php-fpm
然后配置nginx,编辑nginx配置文件
[root@localhost sbin]# cd /usr/src/php-5.4.0/
[root@localhost php-5.4.0]# vim /etc/nginx/nginx.conf
修改nginx配置文件支持php:
44 index index.php index.html index.htm;
添加46―52行
46 location ~ \.php$ {
47 fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
48 fastcgi_index index.php;
49 fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
50 include fastcgi_params;
51 include fastcgi.conf;
52 }
修改完毕后保存退出重启nginx:
[root@localhost php-5.4.0]# service nginx restart
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Stopping nginx: [ OK ]
Starting nginx: [ OK ]
增加网页测试文件:编辑nginx的配置文件使识别index.php文件
[root@localhost php-5.4.0]# cd /usr/html/
[root@localhost html]# ll
[root@localhost html]# vim index.php
<?php
phpinfo();
?>
测试nginx与PHP的连接: