lnmp環境搭建(源碼安裝)

首先安裝nginx

在安裝nginx時有幾個依賴包,我們首先安裝依賴

[root@localhost ~]#  vim /etc/yum.repos.d/rhel-debuginfo.repo

wps_clip_image-5821

[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

wps_clip_image-12445

[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

wps_clip_image-10288

[root@localhost ~]# rpm -qip /mnt/cdrom/Server/pcre-devel-6.6-2.el5_1.7.i386.rpm

wps_clip_image-30222

[root@localhost ~]# yum install pcre-devel                     

[root@localhost ~]# ll

wps_clip_image-8737

解壓縮依賴的包:

[root@localhost ~]# tar -zxvf libevent-2.0.16-stable.tar.gz -C /usr/src/

[root@localhost ~]# cd /usr/src/

[root@localhost src]# ll

wps_clip_image-656

[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

wps_clip_image-574

[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

wps_clip_image-29555

[root@localhost local]# ll lib

[root@localhost local]#  ldconfig -v |grep libevent

wps_clip_image-5511

[root@localhost local]# cd

首先解壓源碼包:

[root@localhost ~]# tar -zxvf nginx-1.1.18.tar.gz -C /usr/src/

[root@localhost ~]# cd /usr/src/

wps_clip_image-15073

進入源碼包目錄進行預編譯:

[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

wps_clip_image-8707

用瀏覽器訪問: http://192.168.101.188

wps_clip_image-14656

安裝: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:

wps_clip_image-22286

然後我們通過mysql命令來連接mysql:

[root@localhost mysql-5.0.95]# mysql

wps_clip_image-14019

安裝PHP

安裝PHP前首先要安裝幾個源碼包依賴:

wps_clip_image-307

第一個:解壓安裝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

wps_clip_image-26217

[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的連接:

wps_clip_image-9640

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章