LNMP編譯安裝

準備:
1、操做系統:centos6.0
2、配置好IP、DNS、網關、YUM源,確保服務器遠程正常。
3、關閉防火牆與selinux(測試用能夠這麼作,工做中可自行配置iptables與selinux)
4、下載相應的軟件包 http://down.51cto.com/data/639275 (裏面含有全部的軟件包,解壓後上傳到服務器上,這邊我上傳到/soft目錄下)
5、軟件詳情
  1. nginx-1.2.2.tar.gz目前相對穩定的nginx安裝包
  2. pcre-8.31.tar.gz perl語言兼容正則表達式)是一個用C語言編寫的正則表達式函數庫,支持nginx僞靜態
  3. mysql-5.5.25.tar.gz 關係型數據庫管理系統
  4. php-5.4.3.tar.gz 一種 HTML 內嵌式的語言,是一種在服務器端執行的嵌入HTML文檔的腳本語言
  5. cmake-2.8.8.tar.gz  CMake是一個跨平臺的安裝(編譯)工具,能夠用簡單的語句來描述全部平臺的安裝(編譯過程)。這邊主要用cmake來編譯mysql
  6. libmcrypt-2.5.8.tar.gz   PHPlibmcrypt模塊
  6、安裝編譯工具及庫文件,爲了方便,使用 yum 源安裝便可
yum install make apr* autoconf automake curl-devel gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel gd kernel keyutils patch perl kernel-headers compat* mpfr cpp glibc libgomp libstdc++-devel ppl cloog-ppl keyutils-libs-devel libcom_err-devel libsepol-devel libselinux-devel krb5-devel zlib-devel libXpm* freetype libjpeg* libpng* php-common php-gd ncurses* libtool* libxml2 libxml2-devel 

patch安裝篇
1、     安裝cmake
cd /soft
tar –zxvf cmake-2.8.8.tar.gz  #
解壓縮cmake
cd cmake-2.8.8  #
進入解壓後的目錄進行配置、編譯、安裝

./configure  #
配置cmake,配置以後生成Makefile的編譯文件
gmake  #
編譯
make install  #
安裝
2、     安裝mysql
useradd mysql –s /sbin/nologin  #
建立mysql用戶、組,方便管理mysql。不容許mysql用戶直接登陸系統(安全考慮)
mkdir –p /usr/local/mysql/data  #
建立mysql安裝目錄與數據庫存放目錄
chown –R mysql:mysql /usr/local/mysql/data   #
設置數據庫目錄權限
cd /soft
tar –zxvf mysql-5.5.25.tar.gz 
cd mysql-5.5.25
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc  # 使用cmake配置mysql
make&&make install
cd /usr/local/mysql
cp ./support-files/my-huge.cnf /etc/my.cnf  #
拷貝配置文件(注意:若是/etc目錄下面默認有一個my.cnf,直接覆蓋便可)

vi /etc/my.cnf  # 編輯配置文件,在 [mysqld] 部分增長下面一行
datadir = /usr/local/mysql/data  #
添加MySQL數據庫路徑
:wq! #
保存退出
./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data   # 生成mysql數據庫文件, 需指定 basedir datadir 不然會報錯 還需確認 mysql_install_db 有執行權限
cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld  # Mysql加入系統啓動
chmod 755 /etc/init.d/mysqld  #
增長執行權限
chkconfig mysqld on  #
加入開機啓動
vi /etc/rc.d/init.d/mysqld  #
編輯,確認如下兩行無誤
basedir = /usr/local/mysql  #MySQL
程序安裝路徑
datadir = /usr/local/mysql/data  #MySQl
數據庫存放目錄
service mysqld start  #
啓動mysql服務
vi /etc/profile  #
mysql服務加入系統環境變量:在最後添加下面這一行
export PATH=$PATH:/usr/local/mysql/bin
:wq! #
保存退出
下面這兩行把myslq的庫文件連接到系統默認的位置,這樣你在編譯相似PHP等軟件時能夠不用指定mysql的庫文件地址。
ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
ln -s /usr/local/mysql/include/mysql /usr/include/mysql
/usr/local/mysql/bin/mysqladmin –u root –p password 「password」   # 設置mysql密碼
service mysqld restart  #
重啓mysql
刪除數據庫的test表與匿名用戶,讓mysql更安全
mysql -u root -p
mysql> DROP DATABASE test; [ 刪除test數據庫]
mysql> DELETE FROM mysql.user WHERE user = ''; [刪除匿名賬戶]
mysql> FLUSH PRIVILEGES; [重載權限]
3、     安裝pcre
cd /soft
tar –zxvf pcre-8.31.tar.gz
cd pcre-8.31
./configure –prefix=/usr/local/pcre
make&&make install
4、     安裝nginx
useradd www –s /sbin/nologin
cd /soft
tar –zxvf nginx-1.2.2.tar.gz
cd nginx.1.2.2
./configure --prefix=/usr/local/nginx --without-http_memcached_module --user=www --group=www --with-http_stub_status_module --with-openssl=/usr/ --with-pcre=/usr/local/src/pcre-8.31
注意:--with-pcre=/usr/local/src/pcre-8.31指向的是源碼包解壓的路徑,而不是安裝的路徑,不然會報錯
make && make install
設置nginx開機啓動
vi /etc/rc.d/init.d/nginx  #
編輯啓動文件,添加以下內容
===========================================
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/logs/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid
}
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
============================================================
:wq  #
保存退出
chmod 775 /etc/rc.d/init.d/nginx  #
賦予文件執行權限
chkconfig nginx on #
設置開機啓動
service nginx restart 
 重啓服
5、     安裝libmcrypt
cd /soft
tar –zxvf libmcrypt-2.5.8.tar.gz 
cd libmcrypt-2.5.8 # 進入目錄
./configure #
配置
make && make install
6、     安裝php
cd /soft
tar -zvxf php-5.4.3.tar.gz
cd php-5.4.3
./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/php5/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-gd --with-iconv --with-zlib --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl
make && make install
cp php.ini-production /usr/local/php5/etc/php.ini  #
複製php配置文件到安裝目錄
rm -rf /etc/php.ini  #
刪除系統自帶配置文件
ln -s /usr/local/php5/etc/php.ini /etc/php.ini  #
添加軟連接
cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf   #
拷貝模板文件爲php-fpm配置文件
vi /usr/local/php5/etc/php-fpm.conf #
編輯
user = www #
設置php-fpm運行帳號爲www
group = www #
設置php-fpm運行組爲www
pid = run/php-fpm.pid #
取消前面的分號
設置 php-fpm開機啓勱
cp /usr/local/src/php-5.4.5/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm #
拷貝php-fpm到啓勱目錄
chmod a+x /etc/rc.d/init.d/php-fpm #
添加執行權限
chkconfig php-fpm on #
設置開機啓勱
vi /usr/local/php5/etc/php.ini #
編輯配置文件
找到:disable_functions =    修改成
disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname
7、     配置nginx支持php
vi /usr/local/nginx/conf/nginx.conf #
編輯配置文件,需作以下修改
user www www; #
首行user去掉註釋,修改Nginx運行組爲www www;必須不/usr/local/php5/etc/php-fpm.conf中的user,group配置相同,不然php運行出錯
index index.php index.html index.htm; #
添加index.php
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#
取消FastCGI server部分location的註釋,並要注意fastcgi_param行的參數,改成$document_root$fastcgi_script_name,或者使用絕對路徑
service nginx restart
8、     測試
cd /usr/local/nginx/html/ # 進入nginx默認網站根目錄
vi index.php #
編輯
<?php
phpinfo();
?>
:wq! #
保存退出
chown www.www /usr/local/nginx/html/ -R  #
設置目錄全部者
chmod 700 /usr/local/nginx/html/ -R  #
設置目錄權限
service nginx restart  #
重啓nginx
使用瀏覽器訪問服務器ip便可檢驗是否配置成功。
相關文章
相關標籤/搜索