nginx+LAMP(apache+php+mysql)

科技探索者發表於2017-11-12

 



nginx+LAMP(apache+php+mysql)



一、安裝LAMP(apache+mysql+php)平臺

 

1、安裝apache

下載地址:http://sunsite.bilkent.edu.tr/pub/apache/httpd/httpd-2.2.9.tar.gz



# tar zxf httpd-2.2.9.tar.gz -C /usr/src

# cd /usr/src/httpd-2.2.9

# ./configure    –prefix=/usr/local/apache  –enable-so –enable-mods-shared=all  –enable-

rewrite –enable-ssl –with-ssl=/usr/lib  –enable-auth-digest –enable-cgi –enable-suexec —

with-suexec-caller=daemon –with-suexec-docroot=/usr/local/apache/htdocs 

# make && make install

# cd /usr/local/apache/conf

# ls

# cp httpd.conf httpd.conf.bak

# grep -v “#” httpd.conf.bak   | grep -v “^$” > httpd.conf

# cd /usr/local/apache/htdocs

# vi /usr/local/apache/conf/httpd.conf            (在最後編寫)

NameVirtualHost  173.17.17.11

<VirtualHost 173.17.17.11>

        DocumentRoot         /usr/local/apache/htdocs

        ServerName           www.benet.com

        ErrorLog             logs/www.benet.com.error.log

        CustomLog            logs/www.benet.com.access.log     common

</VirtualHost>



2、安裝mysql


http://down1.chinaunix.net/distfiles/mysql-5.0.56.tar.gz



# useradd -M -s /sbin/nologin  mysql

# tar zxf mysql-5.0.56.tar.gz -C /usr/src

# cd /usr/src/mysql-5.0.56

# ./configure –prefix=/usr/local/mysql

# make

# make install

# cp support-files/my-medium.cnf /etc/my.cnf

# /usr/local/mysql/bin/mysql_install_db –user=mysql

# chown -R root.mysql /usr/local/mysql/

# chown -R mysql /usr/local/mysql/var

# echo “/usr/local/mysql/lib/mysql”  >> /etc/ld.so.conf

# ldconfig

# /usr/local/mysql/bin/mysqld_safe  –user=mysql &

# 回車(Enter鍵)

# netstat -ntpl | grep 3306

# cp support-files/mysql.server  /etc/init.d/mysqld

# chmod +x /etc/init.d/mysqld

# chkconfig –add mysqld

# chkconfig –level 35 mysqld on

# export PATH=$PATH:/usr/local/mysql/bin

# echo “PATH=$PATH:/usr/local/mysql/bin”   >>  /etc/profile

# mysqladmin -u root password “123456”

# mysql -u root -p

 

3、安裝php



下載地址:http://www.php.net/downloads/


ftp://ftp.gnome.org/pub/GNOME/sources/libxml2/2.6/libxml2-2.6.30.tar.gz
http://prdownloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz
http://sourceforge.net/projects/libpng/files/zlib/1.2.3/zlib-1.2.3.tar.gz  
http://www.dnaphp.com/downloads/server/linux/18-gd-2-0-35-tar   (gd)
ftp://ftp.gnu.org/gnu/autoconf/autoconf-2.61.tar.gz
http://download.savannah.gnu.org/releases/freetype/freetype-2.3.5.tar.gz
http://sourceforge.net/projects/libpng/files/libpng15/1.5.6/libpng-1.5.6.tar.gz  
http://www.imagemagick.org/download/delegates/jpegsrc.v7.tar.gz   
http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz  
http://ftp.gnu.org/pub/gnu/gettext/gettext-0.18.1.1.tar.gz

 

所需庫檔案安裝:



# tar zxvf libxml2-2.6.30.tar.gz                 

# cd libxml2-2.6.30                            

# ./configure –prefix=/usr/local/libxml2

# make && make install                              



# tar zxvf libmcrypt-2.5.8.tar.gz                  

# cd libmcrypt-2.5.8                            

# ./configure –prefix=/usr/local/libmcrypt

# make && make install                             

# cd /usr/local/src/libmcrypt-2.5.8/libltdl 

# ./configure  –enable-ltdl-install    

# make && make install                                



# tar zxvf zlib-1.2.3.tar.gz                 

# cd zlib-1.2.3                             

# ./configure –prefix=/usr/local/zlib

# make && make install                                    

 

# tar zxvf libpng-1.2.31.tar.gz                

# cd libpng-1.2.31                           

# ./configure –prefix=/usr/local/libpng

# make && make install                       

                     

安裝GD2庫前所需的jpeg6庫檔案,需要自己手動地建立安裝需要的目錄,它們在安裝時不能自動建立。

# mkdir /usr/local/jpeg7                      //建立jpeg6軟體安裝目錄

# mkdir /usr/local/jpeg7/bin                  //建立存放命令的目錄

# mkdir /usr/local/jpeg7/lib                  //建立jpeg6庫檔案所在目錄

# mkdir /usr/local/jpeg7/include              //建立存放標頭檔案目錄

# mkdir -p /usr/local/jpeg7/man/man1          //建立存放手冊的目錄

# tar zxvf jpegsrc.v7.tar.gz                  

# cd jpeg-v7                               

# ./configure –prefix=/usr/local/jpeg7 –enable-shared –enable-static



注:

–enable-shared                                    //建立共享庫使用的GNU的libtool

–enable-static                                    //建立靜態庫使用的GNU的libtool

 

# make && make install                                             

 

# tar zxvf freetype-2.3.5.tar.gz                           

# cd  freetype-2.3.5                                  

# ./configure –prefix=/usr/local/freetype

# make && make install                                   

 

# tar zxvf autoconf-2.61.tar.gz                         

# cd autoconf-2.61                                  

# ./configure                              

# make && make install                                  



# tar zxvf libiconv-1.13.tar.gz

# cd libiconv-1.13/

# ./configure –prefix=/usr/local/libiconv

# make && make install



# tar xzf gettext-0.17.tar.gz

# cd gettext-0.17

# ./configure

# make && make install



# tar zxvf gd-2.0.35.tar.gz                     

# cd gd-2.0.35                             

# ./configure –prefix=/usr/local/gd2 –with-zlib=/usr/local/zlib –with-jpeg=/usr/local/jpeg7 –

-with-png=/usr/local/libpng –with-freetype=/usr/local/freetype                        

# make && make install                                   



# vi /usr/local/apache/conf/httpd.conf

….

AddType  application/x-httpd-php  .php

….

DirectoryIndex    index.php    index.html 

:wq

# tar jxf php-5.2.6.tar.bz2 -C /usr/src

# cd /usr/src/php-5.2.6

# ./configure –prefix=/usr/local/php –with-config-file-path=/usr/local/php/etc –with-

apxs2=/usr/local/apache2/bin/apxs –with-mysql=/usr/local/mysql –with-libxml-

dir=/usr/local/libxml2 –with-png-dir=/usr/local/libpng –with-jpeg-dir=/usr/local/jpeg7 –with-

freetype-dir=/usr/local/freetype –with-gd=/usr/local/gd2 –with-zlib-dir=/usr/local/zlib –with

-mcrypt=/usr/local/libmcrypt –with-mysqli=/usr/local/mysql/bin/mysql_config –enable-soap —

enable-mbstring=all –enable-sockets  

# make && make install

# cp php.ini-dist  /usr/local/php/etc/php.ini

# vi /usr/local/php/etc/php.ini

extension_dir=”/usr/lib/php/modules”        (原為extension_dir=”./” )

:wq

# setenforce 0

# chcon -c -v -R -u system_u -r object_r -t textrel_shlib_t /usr/local/apache/modules/libphp5.so

# /usr/local/apache/bin/apachectl restart

# setenforce 1



測試:

# vi /usr/local/apache/htdocs/test.php

<?php

phpinfo();

?>

:wq

# /usr/local/apache/bin/apachectl restart



訪問:http://www.benet.com/test.php

 

二、安裝nginx



下載地址:

http://blog.s135.com/soft/linux/nginx_php/nginx/nginx-0.7.51.tar.gz
http://blog.s135.com/soft/linux/nginx_php/pcre/pcre-7.8.tar.gz

 

# tar zxvf pcre-7.9.tar.gz

# cd pcre-7.9

# ./configure

# make && make install

安裝pcre成功後,繼續安裝nginx

# tar zxf nginx-0.7.51.tar.gz

# cd nginx-0.7.51

# ./configure

# make && make install

4、nginx安裝成功後的安裝目錄為/usr/local/nginx

編輯安裝目錄下conf資料夾中的nginx.conf,輸入如下內容 

 

3. 配置虛擬主機

 開啟配置檔案usr/local/nginx/conf/nginx.conf,可以看到http中包含多個server,註釋掉配置中預設的

server,在http中加上server {

        listen       80;

        charset utf8;

        server_name  www.benet.com;

        root  /usr/local/nginx/html;

        location ~ .php$

        {

         proxy_pass   http://127.0.0.1:8080;

}

    }



啟動  /usr/local/nginx/sbin/nginx

停止  /usr/local/nginx/sbin/nginx -s stop

重啟  /usr/local/nginx/sbin/nginx -s reload

本文轉自linux部落格51CTO部落格,原文連結http://blog.51cto.com/yangzhiming/834926如需轉載請自行聯絡原作者

yangzhimingg