标签:lnmp
1.安装mysql //在练习lamp时已经安装过
2.php安装
[root@localhost php-5.4.37]# wget http://cn2.php.net/distributions/php-5.4.37.tar.bz2
[root@localhost php-5.4.37]# tar jxf php-5.4.37.tar.bz2
[root@localhost php-5.4.37]# useradd -s /sbin/nologin php-fpm
[root@localhost php-5.4.37]# cd php-5.4.37
[root@localhost php-5.4.37]# ./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/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
configure: error: Please reinstall the libcurl distribution -
easy.h should be in <curl-dir>/include/curl/
[root@localhost php-5.4.37]# yum install -y curl-devel
[root@localhost php-5.4.37]# cp php.ini-production /usr/local/php-fpm/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]# chmod 755 /etc/init.d/php-fpm
[root@localhost php-5.4.37]# chkconfig --add php-fpm
[root@localhost php-5.4.37]# chkconfig php-fpm on
[root@localhost php-5.4.37]# service php-fpm start
Starting php-fpm [14-May-2015 03:00:25] ERROR: failed to open configuration file ‘/usr/local/php-fpm/etc/php-fpm.conf‘: No such file or directory (2)
[14-May-2015 03:00:25] ERROR: failed to load configuration file ‘/usr/local/php-fpm/etc/php-fpm.conf‘
[14-May-2015 03:00:25] ERROR: FPM initialization failed
failed
[root@localhost ~]# mv /usr/local/php-fpm/etc/{php-fpm.conf.default,php-fpm.conf} -v
"/usr/local/php-fpm/etc/php-fpm.conf.default" -> "/usr/local/php-fpm/etc/php-fpm.conf"
[root@localhost ~]# service php-fpm start
Starting php-fpm done
3.安装nginx:
[root@localhost nginx-1.6.2]# cd /usr/local/src/
[root@localhost nginx-1.6.2]# wget http://nginx.org/download/nginx-1.6.2.tar.gz
[root@localhost nginx-1.6.2]# tar zxvf nginx-1.6.2.tar.gz
[root@localhost nginx-1.6.2]# cd nginx-1.6.2
[root@localhost nginx-1.6.2]# ./configure --prefix=/usr/local/nginx --with-pcre
checking for PCRE library in /usr/local/ ... not found
checking for PCRE library in /usr/include/pcre/ ... not found
checking for PCRE library in /usr/pkg/ ... not found
checking for PCRE library in /opt/local/ ... not found
./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.
[root@localhost nginx-1.6.2]# yum install -y pcre-devel
4.编写nginx启动脚本:
[root@localhost nginx-1.6.2]# vi /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
RETVAL=$?
echo
return $RETVAL
}
reload(){
echo -n $"Reloading $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -HUP
RETVAL=$?
echo
return $RETVAL
}
restart(){
stop
start
}
configtest(){
$NGINX_SBIN -c $NGINX_CONF -t
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
restart
;;
configtest)
configtest
;;
*)
echo $"Usage: $0 {start|stop|reload|restart|configtest}"
RETVAL=1
esac
exit $RETVAL
[root@localhost nginx-1.6.2]# chmod a+x /etc/init.d/nginx
[root@localhost nginx-1.6.2]# chkconfig --add nginx
[root@localhost nginx-1.6.2]# chkconfig nginx on
5.配置解析php
[root@localhost nginx-1.6.2]# vi /usr/local/nginx/conf/nginx.conf
**************************
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /data/www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
include fastcgi_params;
}
重新加载 /usr/local/nginx/sbin/nginx -s reload
[root@localhost ~]# cat /data/www/phpinfo.php
<?php
phpinfo();
?>
[root@localhost ~]# curl -x127.0.0.1:80 www.123.com/phpinfo.php -I
HTTP/1.1 200 OK
Server: nginx/1.6.2
Date: Sun, 17 May 2015 13:31:23 GMT
Content-Type: text/html
Connection: keep-alive
X-Powered-By: PHP/5.4.37
搭建中运到的问题:
1.安装mysql //在练习lamp时已经安装过
2.php安装
[root@localhost php-5.4.37]# wget http://cn2.php.net/distributions/php-5.4.37.tar.bz2
[root@localhost php-5.4.37]# tar jxf php-5.4.37.tar.bz2
[root@localhost php-5.4.37]# useradd -s /sbin/nologin php-fpm
[root@localhost php-5.4.37]# cd php-5.4.37
[root@localhost php-5.4.37]# ./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/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
configure: error: Please reinstall the libcurl distribution -
easy.h should be in <curl-dir>/include/curl/
[root@localhost php-5.4.37]# yum install -y curl-devel
[root@localhost php-5.4.37]# cp php.ini-production /usr/local/php-fpm/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]# chmod 755 /etc/init.d/php-fpm
[root@localhost php-5.4.37]# chkconfig --add php-fpm
[root@localhost php-5.4.37]# chkconfig php-fpm on
[root@localhost php-5.4.37]# service php-fpm start
Starting php-fpm [14-May-2015 03:00:25] ERROR: failed to open configuration file ‘/usr/local/php-fpm/etc/php-fpm.conf‘: No such file or directory (2)
[14-May-2015 03:00:25] ERROR: failed to load configuration file ‘/usr/local/php-fpm/etc/php-fpm.conf‘
[14-May-2015 03:00:25] ERROR: FPM initialization failed
failed
[root@localhost ~]# mv /usr/local/php-fpm/etc/{php-fpm.conf.default,php-fpm.conf} -v
"/usr/local/php-fpm/etc/php-fpm.conf.default" -> "/usr/local/php-fpm/etc/php-fpm.conf"
[root@localhost ~]# service php-fpm start
Starting php-fpm done
3.安装nginx:
[root@localhost nginx-1.6.2]# cd /usr/local/src/
[root@localhost nginx-1.6.2]# wget http://nginx.org/download/nginx-1.6.2.tar.gz
[root@localhost nginx-1.6.2]# tar zxvf nginx-1.6.2.tar.gz
[root@localhost nginx-1.6.2]# cd nginx-1.6.2
[root@localhost nginx-1.6.2]# ./configure --prefix=/usr/local/nginx --with-pcre
checking for PCRE library in /usr/local/ ... not found
checking for PCRE library in /usr/include/pcre/ ... not found
checking for PCRE library in /usr/pkg/ ... not found
checking for PCRE library in /opt/local/ ... not found
./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.
[root@localhost nginx-1.6.2]# yum install -y pcre-devel
4.编写nginx启动脚本:
[root@localhost nginx-1.6.2]# vi /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
RETVAL=$?
echo
return $RETVAL
}
reload(){
echo -n $"Reloading $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -HUP
RETVAL=$?
echo
return $RETVAL
}
restart(){
stop
start
}
configtest(){
$NGINX_SBIN -c $NGINX_CONF -t
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
restart
;;
configtest)
configtest
;;
*)
echo $"Usage: $0 {start|stop|reload|restart|configtest}"
RETVAL=1
esac
exit $RETVAL
[root@localhost nginx-1.6.2]# chmod a+x /etc/init.d/nginx
[root@localhost nginx-1.6.2]# chkconfig --add nginx
[root@localhost nginx-1.6.2]# chkconfig nginx on
5.配置解析php
[root@localhost nginx-1.6.2]# vi /usr/local/nginx/conf/nginx.conf
**************************
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /data/www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
include fastcgi_params;
}
重新加载 /usr/local/nginx/sbin/nginx -s reload
[root@localhost ~]# cat /data/www/phpinfo.php
<?php
phpinfo();
?>
[root@localhost ~]# curl -x127.0.0.1:80 www.123.com/phpinfo.php -I
HTTP/1.1 200 OK
Server: nginx/1.6.2
Date: Sun, 17 May 2015 13:31:23 GMT
Content-Type: text/html
Connection: keep-alive
X-Powered-By: PHP/5.4.37
搭建遇到的问题:
[root@localhost ~]# service php-fpm start
Starting php-fpm [15-May-2015 05:22:17] ERROR: unable to bind listening socket for address ‘127.0.0.1:9000‘: Address already in use (98)
[15-May-2015 05:22:17] ERROR: FPM initialization failed
failed
[root@localhost ~]# killall php-fpm
[root@localhost ~]# !ser
service php-fpm start
Starting php-fpm done
[root@localhost ~]# /usr/local/nginx/sbin/nginx -t
nginx: [emerg] "location" directive is not allowed here in /usr/local/nginx/conf/nginx.conf:65
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
#
#error_page 500 502 503 504 /50x.html;
location = /50x.html { //把这给注释之后就会报错
root html;
}
***********************
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /data/www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
include fastcgi_params;
}
[root@localhost ~]# vi +65 /usr/local/nginx/conf/nginx.conf
[root@localhost ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
扩展学习:
Nginx为什么比Apache Httpd高效:原理篇 http://www.toxingwang.com/linux-unix/linux-basic/1712.html
apache和nginx工作原理比较 http://www.server110.com/nginx/201402/6543.html
mod_php 和 mod_fastcgi以及php-fpm的比较 http://wenku.baidu.com/link?url= ... QzFJkh_AElC4Nc-LD03
概念了解:CGI,FastCGI,PHP-CGI与PHP-FPM http://www.nowamagic.net/librarys/veda/detail/1319/
标签:lnmp
原文地址:http://9950284.blog.51cto.com/9940284/1652076