系統版本centos6.5
一、安裝MySQL
1.下載下傳MySQL
2.解壓MySQL
tar -zxvf mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz
3.将解壓出的資料移到/usr/local/mysql
mv mysql-5.6.26-linux-glibc2.5-x86_64 /usr/local/mysql
4.建立MySQL使用者
useradd -s /sbin/nologin mysql
5.初始化
二、安裝PHP
1.下載下傳php源碼包
#cd /usr/local/src/
2.解壓源碼包,建立賬号
# tar jxf php-5.4.44.tar.bz2 # useradd -s /sbin/nologin php-fpm 該賬号用來運作php-fpm服務,在LNMP環境中,php是以一個服務來提供服務的。
3.配置編譯選項
#cd php-5.4.44
# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --disable-ipv6 --with-curl
編譯過程中會碰到下面這些錯誤:
①
checking for cc... no
checking for gcc... no
configure: error: in `/usr/local/src/php-5.4.37':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
解決辦法:yum install -y gcc
②configure: error: xml2-config not found. Please check your libxml2 installation.
解決辦法:yum install -y libxml2-devel
③configure: error: Please reinstall the libcurl distribution -
easy.h should be in <curl-dir>/include/curl/
解決辦法:yum install -y curl-devel
④configure: error: jpeglib.h not found.
解決辦法:yum install -y libjpeg libjpeg-devel
⑤configure: error: png.h not found.
解決辦法:
⑥configure: error: freetype-config not found.
解決辦法:yum install -y freetype freetype-devel
⑦configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解決辦法:因為yum庫是沒有這個包的,是以要去下載下傳個第三方yum源
然後yum install -y libmcrypt-devel
3.make && make install
4.修改配置檔案
[root@localhost php-5.4.37]# cp php.ini-production /usr/local/php/etc/php.ini
[root@localhost php-5.4.37]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-5.4.37]# mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@localhost php-5.4.37]# chmod 755 /etc/init.d/php-fpm
5.啟動php
service php-fpm start
三、安裝nginx
下載下傳nginx源碼包
#wget http://nginx.org/download/nginx-1.6.3.tar.gz
2.解壓
# tar -zxvf nginx-1.6.3.tar.gz
3.cd nginx-1.6.3
# ./configure --prefix=/usr/local/nginx --with-pcre
可能會碰到
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
解決辦法:yum install -y pcre pcre-devel
4.make && make install
5.編譯啟動腳本
vim /etc/init.d/nginx
寫入以下内容:
#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"
start() {
echo -n $"Starting $prog: "
mkdir -p /dev/shm/nginx_temp
daemon $NGINX_SBIN -c $NGINX_CONF
RETVAL=$?
echo
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -TERM
rm -rf /dev/shm/nginx_temp
reload(){
echo -n $"Reloading $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -HUP
restart(){
stop
start
configtest(){
$NGINX_SBIN -c $NGINX_CONF -t
return 0
case "$1" in
start)
;;
stop)
reload)
reload
restart)
restart
configtest)
configtest
*)
echo $"Usage: $0 {start|stop|reload|restart|configtest}"
RETVAL=1
esac
exit $RETVAL
儲存後
# chmod 755 /etc/init.d/nginx
6.配置解析php
vim /usr/local/nginx/conf/nginx.conf
更改這一部分,将#注釋去掉
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
7.重新加載
/usr/local/nginx/sbin/nginx -s reload
8.測試是否解析php檔案
# vim /usr/local/nginx/html/1.php
<?php
phpinfo();
?>
~
如果解析,LNMP搭建成功
本文轉自YU文武貝 51CTO部落格,原文連結:http://blog.51cto.com/linuxerxy/1717910,如需轉載請自行聯系原作者