centos6.2ubuntu 12.04上安裝httpd2.4,nginx,php5.3.8...

1、安裝一些必要的軟件。

ubuntu
安裝之後,有一些包是沒有安裝上的。咱們須要安裝上,不然下面的編譯將會出現問題。 javascript

複製內容到剪貼板代碼:apt-getinstall binutils cpp fetchmail flex gcc libarchive-zip-perl libc6-devlibpcre3 libpopt-dev lynx m4 make ncftp nmap perl perl-modules unzipzip zlib1g-dev autoconf automake1.9 libtool bison autotools-dev g++build-essential libpcre3-dev libncurses5-dev libcurl4-openssl-devopenssh-server openssh-client php

2、設置安裝目錄,下載必要的軟件。

安裝完畢之後,咱們創建幾個目錄,用來進行下一步的安裝。 css

複製內容到剪貼板代碼:mkdir/usr/src/lamp (用來存放安裝軟件)
/usr/local(
安裝目錄,nginxphp,mysql等都安裝在這個目錄下)
mkdir/var/www(
發佈目錄)
下載編譯須要的各類軟件,所有放到/var/software
mysql-5.5.23.tar.gz
php-5.3.10.tar.gz
nginx-1.2.0.tar.gz
html

spawn-fcgi-1.6.3.tar.gz(用來加載fastcgi)
java

//如下爲php的依賴庫 node

freetype-2.3.5.tar.gz mysql

jpegsrc.v6b.tar.gz linux

libiconv-1.11.1.tar.gz nginx

libmcrypt-2.5.8.tar.gz web

libpng-1.2.29.tar.gz(注意,你們不要使用1.2.28這個版本,彷佛有不少問題)
libxml2-2.6.30.tar.gz

mcrypt-2.6.7.tar.gz

mhash-0.9.9.tar.gz

pcre-8.30.tar.gz

爲了方便,我已經已將上面全部的軟件包下載後打包


、編譯安裝PHP所需的支持庫。

複製內容到剪貼板代碼:

cd /usr/src/lamp/beforephp
tar zxvf libiconv-1.11.1.tar.gz
cd libiconv-1.11.1/
./configure --prefix=/usr/local
make &&make install
cd ..

tar zxvf freetype-2.3.5.tar.gz
cd freetype-2.3.5
./configure
make && make install
cd..

tar zxvf libpng-1.2.29.tar.gz
cd libpng-1.2.29
./configure
###mvscripts/makefile.linux ./makefile
make
make install
cd ..


tar zxvf jpegsrc.v6b.tar.gz
cd jpeg-6b/
./configure--enable-static --enable-shared
make && make install
makeinstall-lib
cd ..

(libxml2會影響php的編譯)
tarzxvf libxml2-2.6.30.tar.gz
cd libxml2-2.6.30

打開當前目錄下的nanohttp.c,第1588行由
fd = open(filename, O_CREAT | O_WRONLY);
更換爲
fd = open(filename, O_CREAT | O_WRONLY,0777);

http://temix.blog.163.com/blog/static/364133200810237854799/

gcc-4.3對語法檢查嚴格的結果,找到出錯的那一句,OK
./configure
make&& make install
cd ..



tarzxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8


./configure
make&& make install
/sbin/ldconfig
cd libltdl/
./configure--enable-ltdl-install
make && make install
cd ../..


tar zxvf mhash-0.9.9.tar.gz


cd mhash-0.9.9


./configure
make&& make install
cd ..

cp /usr/local/lib/libmcrypt.*/usr/lib
##ln-s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2 ()
建立連接時出錯,說已經存在,不過好像不影響編譯

tar zxvf mcrypt-2.6.7.tar.gz
cd mcrypt-2.6.7
./configure
make&& make install (
這裏出現了不少警告,好像不影響)
cd..

4、編譯安裝MySQL

因爲一些Linux操做系統並不自帶MySQL數據庫,或者有些電腦(如國產龍芯,基於MIPS指令系統)並不支持MySQL官方提供的RPM包的安裝,所以須要使用源碼進行重編譯,而後安裝使用

下載地址:http://www.mysql.com/downloads/mysql/進入MySQLCommunity Server下載頁面,在SelectPlatform選項中選擇SourceCode

選擇最後一項.tar.gz的文件,以下圖

點擊Download進入鏡像連接頁面,隨便選擇一個鏡像進行下載到本地磁盤

  1. 建立mysql安裝目錄

此處的安裝目錄能夠任選,若是是默認安裝則在/usr/local/mysql

#mkdir -p /usr/local/mysql/

2、建立數據存放目錄

#mkdir-p/service/mysql/

3、建立用戶和用戶組與賦予數據存放目錄權限

  #groupadd mysql

  #useradd -g mysql mysql

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

4、安裝cmake

mysql5.5之後是經過cmake工具來編譯的,CMake是個跨平臺的自動化建構系統,它用組態檔(生成Makefile文件的特殊腳本)控制建構過程,mysql的源碼進行buildProcess(構建),而後生成Makefile文件.

Cmake下載地址:http://www.cmake.org/cmake/resources/software.html

  選擇Unix/LinuxSource.tar.gz文件進行下載最新版本,而後將其解壓縮到本地,並配置、安裝,如下是相關命令

cd..

  tar zxvfcmake-2.8.8.tar.gz

  cd cmake-2.8.8

  ./configure

  make&& make install (這要幾分鐘的時間,反正比前面的編譯時間長點)

cd..

5、編譯mysql

tar zxvf mysql-5.5.23.tar.gz

cd mysql-5.5.23

進入MySQL解壓目錄下,使用cmake來對mysql的安裝目錄、數據存放、配置文件、系統語言等相關信息進行編輯,如下是相關指令:

如下是編輯命令的集合,能夠直接拷貝、粘貼並執行,注意的是安裝目錄與數據目錄的位置

cmake. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-DMYSQL_DATADIR=/usr/local/mysql/data/-DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysqld.sock-DWITH_INNOBASE_STORAGE_ENGINE=1 -DSYSCONFDIR=/etc-DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8-DDEFAULT_COLLATION=utf8_unicode_ci -DWITH_DEBUG=0

執行以上命令,將構建MySQL源碼中的Makefile文件。

選項說明:

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql

mysql安裝的主目錄,5.5.17版本默認爲/usr/local/mysql(可省略)

-DMYSQL_DATADIR=/home/system_username/mysql/mysqldata

mysql數據保存的路徑,自定義

-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock

系統Socket文件(.sock)設置,基於該文件路徑進行Socket鏈接,必要爲絕對路徑

-DSYSCONFDIR=/etc

mysql配置文件my.cnf地址,默認/etc(可省略)

-DMYSQL_TCP_PORT=3306

數據庫服務器TCP/IP鏈接的監聽端口,默認爲3306(可省略)

-DENABLED_LOCAL_INFILE=1

默認爲關閉,這裏開啓

-DEXTRA_CHARSETS=all

-DDEFAULT_CHARSET=utf8

-DDEFAULT_COLLATION=utf8-general_ci

數據庫編碼設置

-DWITH_INNOBASE_STORAGE_ENGINE=1

-DWITH_ARCHIVE_STORAGE_ENGINE=1

-DWITH_BLACKHOLE_STORAGE_ENGINE=1

-DWITH_FEDERATED_STORAGE_ENGINE=1

-DWITH_PARTITION_STORAGE_ENGINE=1

存儲引擎設置

8、安裝MySQL

make&& make install

這將是一個比較漫長的編譯過程。。。。。

9、配置MySQL的啓動項

cp support-files/my-medium.cnf /etc/my.cnf //更改配置文件位置

cp support-files/mysql.server /etc/init.d/mysqld //設置mysql服務器操做路徑

(以上兩個文件是source下面的)

chmod 755 /etc/init.d/mysqld //更改權限

bashscripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql--datadir=/usr/local/mysql/data/ //安裝數據庫,並設置用戶名和數據存放位置

  1. MySQL啓動與使用

1、在命令行中輸入:

/etc/init.d/mysqldstart

啓動Mysql服務

2、登陸MySQL

ln /usr/local/mysql/bin/mysql /usr/sbin/mysql(之後直接輸入mysql便可以啓動登陸)

命令行:mysql

使用mySQL數據庫的root用戶登陸,默認無密碼,也能夠mysql -u root–p

  1. 簡單操做

mysql>usemysql ; //使用mysql數據庫

//更改root用戶的登陸密碼

mysql>updateuser set password=PASSWORD("123456") where user='root';

//刷新更新

mysql>FLUSHPRIVILEGES;

  1. 總結

最好將上面的安裝指令等寫成一個Shell腳本,以免錯誤,並使安裝更簡單。。完畢!


運行如下命令便可啓動MySQL服務器:
/etc/init.d/mysqldstart
(啓動MySQL
bin/mysqladmin-u root password"password_for_root"
(設置mysqlroot密碼)
/etc/init.d/mysqldstop
(關閉 MySQL

nano /etc/rc.local

ctrl+O
在最後加入:/etc/init.d/mysqldstart(這樣開機的時候,mysql就能夠自動啓動了。)

5、編譯安裝PHP-5.3.10FastCGI模式)

ln -s/usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18

(沒有這個連接會報錯)
cd..
tarzxvf php-5.3.10.tar.gz
cd php-5.3.10

複製內容到剪貼板代碼:(用於ubuntu
./configure--prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc--with-mysql=/usr/local/mysql –with-mysqli=/usr/local/mysql--with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir--with-png-dir --with-zlib --with-libxml-dir --enable-xml --enable-discard-path --enable-safe-mode --enable-bcmath--enable-shmop --enable-sysvsem --enable-inline-optimization--with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi--enable-force-cgi-redirect --enable-mbstring --with-mcrypt--disable-ipv6 --enable-soap --with-openssl --with-gettext--disable-rpath
(
編譯時間較長,請耐心等待)
                    

 phpfpmcentosphp-fpm cgi啓動方式)

./configure--prefix=/usr/local/php5310--with-config-file-path=/usr/local/php5310/etc--with-mysql=/usr/local/mysql--with-mysqli=/usr/local/mysql/bin/mysql_config--with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir--with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml--disable-rpath --enable-discard-path --enable-safe-mode--enable-bcmath --enable-shmop --enable-sysvsem--enable-inline-optimization --with-curl --with-curlwrappers--enable-mbregex --enable-fastcgi --enable-fpm--enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd--enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl--enable-sockets
make ZEND_EXTRA_LIBS='-liconv'
make install
cpphp.ini-dist /usr/local/php/etc/php.ini

centos apache

./configure--prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-config-file-path=/usr/local/php/etc--with-mysql=/usr/local/mysql--with-mysqli=/usr/local/mysql/bin/mysql_config--with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir--with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml--disable-rpath --enable-discard-path --enable-safe-mode--enable-bcmath --enable-shmop --enable-sysvsem--enable-inline-optimization --with-curl --with-curlwrappers--enable-mbregex --enable-mbstring --with-mcrypt --with-gd--enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl--enable-sockets

make
makeinstall
cp php.ini-development /usr/local/php/etc/php.ini

 make ZEND_EXTRA_LIBS='-liconv'

6、編譯安裝PHP5擴展模塊

複製內容到剪貼板代碼:

cd ext/gd/
/usr/local/php/bin/phpize
./configure --with-jpeg-dir--with-png-dir --with-zlib-dir --with-ttf --with-freetype-dir--with-php-config=/usr/local/php/bin/php-config
make
makeinstall

cd../../
、對php進行一些設置,而且爲安裝nginx作一些準備工做。
1
、修改php.ini文件
手工修改:查找/usr/local/php/etc/php.ini中的extension_dir= "./"
修改成extension_dir="/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/"
並在此行後增長如下幾行,而後保存。

複製內容到剪貼板代碼:
extension= "gd.so"

自動修改:若嫌手工修改麻煩,可執行如下shell命令,自動完成對php.ini文件的修改:

複製內容到剪貼板代碼:
#sed -i 's#extension_dir = "./"#extension_dir ="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"\nextension= "gd.so"\n#' /usr/local/php/etc/php.ini  

2、建立www用戶和組,以及其使用的目錄。

複製內容到剪貼板代碼:/usr/sbin/groupaddwww -g 48
/usr/sbin/useradd -u 48 -g www www

mkdir/var/www
chmod +w /var/www/
chown -R www:www /var/www/

兒、安裝Nginx1.2.0
1
、安裝Nginx所需的pcre庫。

複製內容到剪貼板代碼:

tarzxvf pcre-8.30.tar.gz
cd pcre-8.30/


./configure
make&& make install
cd ../..

2、安裝Nginx

複製內容到剪貼板代碼:
tarzxvf nginx-1.2.0.tar.gz
cd nginx-1.2.0/
./configure--user=nginx --group=www --prefix=/usr/local/nginx--with-http_stub_status_module --with-http_ssl_module--with-pcre=/home/xuefen/tar/lnmp/pcre-8.30

#--with-pcre=/ pcre要用源碼的目錄,我看它代碼是找./cofigure
make
make install
cd ..


3
、建立Nginx日誌目錄。

複製內容到剪貼板代碼:
chmod+w /usr/local/nginx/logs
chown -R nginx:www /usr/local/nginx/logs/

4、建立Nginx配置文件。
更改/usr/local/nginx/conf/目錄中的nginx.conf文件。


nano/usr/local/nginx/conf/nginx.conf

如下是參考配置

usernginx www;

worker_processes 5;

error_log/usr/local/nginx/logs/nginx_error.log crit;

#pidlogs/nginx.pid;

#Specifies the value for maximum filedescriptors that can be opened by this process.
worker_rlimit_nofile51200;

events
{
use epoll;
worker_connections 51200;
}

http
{
includemime.types;
default_type application/octet-stream;

charsetutf-8;

server_names_hash_bucket_size 128;

#sendfileon;
#tcp_nopush on;

keepalive_timeout 60;

tcp_nodelayon;

gzip on;
gzip_min_length 1k;
gzip_buffers 48k;
gzip_http_version 1.1;
gzip_types text/plainapplication/x-javascript text/css text/htmlapplication/xml;

server
{
listen 80;
server_nameservername.com;
index index.html index.htm index.php;
root/usr/local/webserver/webdata;

if (-d$request_filename)
{
rewrite ^/(.*)([^/])$ http://$host/$1$2/permanent;
}

location ~ .*.php?$
{
root /var/www;

fastcgi_pass 127.0.0.1:9999;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;

include fastcgi_params;
}

log_format access '$remote_addr -$remote_user [$time_local] "$request" '
'$status$body_bytes_sent "$http_referer" '
'"$http_user_agent"$http_x_forwarded_for';
access_log/usr/local/webserver/logs/access.log access;
}

server
{
listen80;
server_name status.servername.com;

location /{
stub_status on;
access_log off;
}
}
}

保存,退出nano

11、安裝zend

複製內容到剪貼板代碼:
tarzxvf ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz
cdZendOptimizer-3.3.3-linux-glibc23-i386
./install

在詢問php.ini的路徑的時候,填入.

複製內容到剪貼板代碼:/usr/local/webserver/php/etc

web服務器選擇不是apache

12、Apache(httpd)的安裝

所需的庫:(apache有下面三個庫)

apr-1.4.6.tar.bz2

apr-util-1.4.1.tar.bz2

httpd-2.4.2.tar.bz2

命令 :

tarjxvf apr-1.4.6.tar.bz2

cdapr-1.4.6

./configure–prefix=/usr/local/apr

make&& make install

cd..

tarjxvf apr-util-1.4.1.tar.bz2

cdapr-util-1.4.1

./configure--prefix=/usr/local/apr-util –with-apr=/usr/local/apr

make&& make install

cd..

tarjxvf httpd-2.4.2.tar.bz2

cdhttpd-2.4.2

./configure--prefix=/usr/local/apache -enable-rewrite --enable-module=so-enable-so --with-apr=/usr/local/apr/--with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local

make&& make install

useraddapache -g www

chmod755 /etc/init.d/httpd

chkconfig--add httpd

chkconfig--lefel 35 httpd on


十3、後續的處理工做

1,nginx防盜鏈

通常的防盜鏈以下:

location~* .(gif|jpg|png|swf|flv)$ {

valid_referersnone blocked server_names *.bnxb.com www.bnxb.com;

if($invalid_referer) {

rewrite^/ http://www.bnxb.com/403.html;

#return404;

}

}

2,nginx虛擬目錄

Nginx的目錄若是是在網站根下創建的話,就能夠直接當成目錄訪問,實現虛擬目錄的效果,若是另外

指一個目錄創建網站的虛擬目錄的話,須要用到如下方法來實現。

nginx虛擬目錄配置有兩種方法aliasroot。虛擬目錄的概念與其它的Web應用同樣。

最基本的區別:alias指定的目錄是準確的,root是指定目錄的上級目錄,而且該上級目錄要含有

location指定名稱的同名目錄。另外,根據前文所述,使用alias標籤的目錄塊中不能使用rewrite

break

示例1:

location/abc/ {

alias/home/html/abc/;

}

在這段配置下,http://test/abc/a.html就指定的是/home/html/abc/a.html

示例2:

這段配置亦可改爲

location/abc/ {

root/home/html/;

}

/*abc的上級目錄*/

示例3:

alias的配置改爲:

location/abc/ {

alias/home/html/def/;

}

那麼nginx將會從/home/html/def/取數據,這段配置還不能直接使用root配置,若是非要配置,

有在/home/html/下創建一個def->abc的軟link(快捷方式)了。

說明:

1、使用alias時目錄名後面必定要加/

2nginxresin當虛擬目錄名與真實目錄同名時,虛擬目錄比真實目錄優先級要高。

3.配置開機自動啓動Nginx+ PHP

vi/etc/rc.local

加入如下內容:

ulimit-SHn 51200

/usr/local/php/sbin/php-fpmstart

/usr/local/nginx/sbin/nginx

4設置mysql開機自動啓動服務
cp./support-files/mysql.server /etc/rc.d/init.d/mysqld
chkconfig--add mysqld
chkconfig --level 345 mysqld on

5打開防火牆80端口

寫入規則,保存並重啓服務

iptables -I INPUT -p tcp--dport 80 -j ACCEPT

/etc/rc.d/init.d/iptablessave

/etc/init.d/iptablesrestart

查看防火牆信息
/etc/init.d/iptables status

若是顯示如下相似信息,即表示已經打開了80端口

1 ACCEPT tcp -- 0.0.0.0/00.0.0.0/0 tcp dpt:80

6編寫nginx啓動服務

cd /etc/init.d

vim nginx

輸入如下代碼並保存

#!/bin/sh

#

# nginx - nginx啓動與中止,平滑更新nginx配置

# Source function library.

. /etc/rc.d/init.d/functions

# Source networkingconfiguration.

. /etc/sysconfig/network

# Check that networking isup.

[ "$NETWORKING" ="no" ] && exit 0

nginx="/usr/local/nginx/sbin/nginx"

prog=$(basename $nginx)

NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

lockfile=/var/lock/subsys/nginx

start() {

[ -x $nginx ] || exit 5

[ -f $NGINX_CONF_FILE ]|| exit 6

echo -n $"Starting$prog: "

daemon $nginx -c$NGINX_CONF_FILE

retval=$?

echo

[ $retval -eq 0 ] &&touch $lockfile

return $retval

}

stop() {

echo -n $"Stopping$prog: "

killproc $prog -QUIT

retval=$?

echo

[ $retval -eq 0 ] &&rm -f $lockfile

return $retval

}

restart() {

configtest || return $?

stop

start

}

reload() {

configtest || return $?

echo -n $"Reloading$prog: "

killproc $nginx -HUP

RETVAL=$?

echo

}

force_reload() {

restart

}

configtest() {

$nginx -t -c$NGINX_CONF_FILE

}

rh_status() {

status $prog

}

rh_status_q() {

rh_status >/dev/null2>&1

}

case "$1" in

start)

rh_status_q &&exit 0

$1

;;

stop)

rh_status_q || exit0

$1

;;

restart|configtest)

$1

;;

reload)

rh_status_q || exit7

$1

;;

force-reload)

force_reload

;;

status)

rh_status

;;

condrestart|try-restart)

rh_status_q || exit0

;;

*)

echo $"Usage: $0{start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"

exit 2

esac


保存後,設置權限,並添加到啓動服務列表中

chmod755 /etc/init.d/nginx

chkconfig--add nginx

chkconfig--level 345 nginx on

servicenginx start

7安裝php-fpm

cp/opt/php/etc/php-fpm.conf.default /opt/php/etc/php-fpm.conf
vim/opt/php/etc/php-fpm.conf

修改如下地方
[global]
pid= run/php-fpm.pid-p
error_log =log/php-fpm.log
emergency_restart_threshold =10
emergency_restart_interval = 1m
process_control_timeout =5s
pm.start_servers = 20
pm.min_spare_servers =5
pm.max_spare_servers = 35

[www]
user = www
group =www

8修改nginx,支持php

vim/opt/nginx/conf/nginx.conf

找到並修改如下代碼

location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9999;#
不少網上是配置9000,我上次因zenddebug也用9000,結果折騰了半天
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
include fastcgi_params;
}

9php-fpm做爲服務運行

cd /usr/local/src/php-5.3.8
cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod 700 /etc/init.d/php-fpm
chkconfig--add php-fpm
chkconfig --level 345 php-fpm on
服務方式啓動php-fpm service php-fpm restart

相關文章
相關標籤/搜索