标签:lnmp
关闭防火墙:
[root@CentOS64_DB ~]# service iptables stop
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
[root@CentOS64_DB ~]# set enforce 0
安装相关依赖包:
[root@CentOS64_DB ~]# yum -y install wget gcc-c++ ncurses ncurses-devel cmake make perl bison openssl openssl-devel gcc* libxml2 libxml2-devel curl-devel libjpeg* libpng* freetype* pcre-devel
[root@CentOS64_DB ~]# mkdir -p /usr/local/src/
[root@CentOS64_DB ~]# cd /usr/local/src/
[root@CentOS64_DB src]# ll
total 47080
-rw-r--r--. 1 root root 32821451 May 16 2014 mysql-5.6.16.tar.gz
-rw-r--r--. 1 root root 721002 May 16 2014 nginx-1.3.1.tar.gz
-rw-r--r--. 1 root root 14596605 May 16 2014 php-5.4.13.tar.gz
[root@CentOS64_DB src]# tar xf nginx-1.3.1.tar.gz
[root@CentOS64_DB src]# cd nginx-1.3.1
[root@CentOS64_DB nginx-1.3.1]# ./configure --prefix=/usr/local/nginx
Configuration summary + using system PCRE library + OpenSSL library is not used + md5: using system crypto library + sha1: using system crypto library + using system zlib library nginx path prefix: "/usr/local/nginx" nginx binary file: "/usr/local/nginx/sbin/nginx" nginx configuration prefix: "/usr/local/nginx/conf" nginx configuration file: "/usr/local/nginx/conf/nginx.conf" nginx pid file: "/usr/local/nginx/logs/nginx.pid" nginx error log file: "/usr/local/nginx/logs/error.log" nginx http access log file: "/usr/local/nginx/logs/access.log" nginx http client request body temporary files: "client_body_temp" nginx http proxy temporary files: "proxy_temp" nginx http fastcgi temporary files: "fastcgi_temp" nginx http uwsgi temporary files: "uwsgi_temp" nginx http scgi temporary files: "scgi_temp" |
[root@CentOS64_DB nginx-1.3.1]# make && make install
[root@CentOS64_DB nginx-1.3.1]# cd /usr/local/nginx/
[root@CentOS64_DB nginx]# vim /etc/init.d/nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
# Source function library.
.
/etc/rc
.d
/init
.d
/functions
# Source networking configuration.
.
/etc/sysconfig/network
# Check that networking is up.
[
"$NETWORKING"
=
"no"
] &&
exit
0
nginx=
""
/usr/local/nginx/sbin/nginx
prog=$(
basename
$nginx)
NGINX_CONF_FILE=
"/usr/local/nginx/conf/nginx.conf"
[ -f
/etc/sysconfig/nginx
] && .
/etc/sysconfig/nginx
lockfile=
/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`nginx -V 2>&1 |
grep
"configure arguments:"
|
sed
‘s/[^*]*--user=\([^ ]*\).*/\1/g‘
-`
options=`$nginx -V 2>&1 |
grep
‘configure arguments:‘
`
for
opt
in
$options;
do
if
[ `
echo
$opt |
grep
‘.*-temp-path‘
` ];
then
value=`
echo
$opt |
cut
-d
"="
-f 2`
if
[ ! -d
"$value"
];
then
# echo "creating" $value
mkdir
-p $value &&
chown
-R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] ||
exit
5
[ -f $NGINX_CONF_FILE ] ||
exit
6
make_dirs
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
sleep
1
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/null
2>&1
}
case
"$1"
in
start)
rh_status_q &&
exit
0
$1
;;
stop)
rh_status_q ||
exit
0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q ||
exit
7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q ||
exit
0
;;
*)
echo
$
"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit
2
esac
[root@CentOS64_DB nginx]# chmod +x /etc/init.d/nginx
[root@CentOS64_DB nginx]# chkconfig --add nginx
[root@CentOS64_DB nginx]# chkconfig nginx on
[root@CentOS64_DB nginx]# service nginx start
Starting nginx: [ OK ]
[root@CentOS64_DB nginx]# netstat -anlp | grep :80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 12248/nginx
[root@CentOS64_DB nginx]#
[root@CentOS64_DB nginx]# cd /usr/local/src/
[root@CentOS64_DB src]# groupadd mysql
[root@CentOS64_DB src]# useradd -r -g mysql mysql
[root@CentOS64_DB src]# tar xf mysql-5.6.16.tar.gz
[root@CentOS64_DB src]# cd mysql-5.6.16
[root@CentOS64_DB mysql-5.6.16]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
[root@CentOS64_DB mysql-5.6.16]# make && make install
[root@CentOS64_DB mysql-5.6.16]# chown -R mysql.mysql /usr/local/mysql/
[root@CentOS64_DB mysql-5.6.16]# cd /usr/local/mysql/scripts/
[root@CentOS64_DB scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
[root@CentOS64_DB scripts]# cd /usr/local/mysql/support-files/
[root@CentOS64_DB support-files]# cp mysql.server /etc/rc.d/init.d/mysql
[root@CentOS64_DB support-files]# cp my-default.cnf /etc/my.cnf
cp: overwrite `/etc/my.cnf‘? y
[root@CentOS64_DB support-files]# chkconfig --add mysql
[root@CentOS64_DB support-files]# chkconfig mysql on
[root@CentOS64_DB support-files]# service mysql start
Starting MySQL... SUCCESS!
[root@CentOS64_DB support-files]# ln -s /usr/local/mysql/bin/* /usr/bin/
[root@CentOS64_DB support-files]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.16 Source distribution Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement. mysql> |
./configure --prefix=/usr/local/php #指定安装目录 --enable-fpm #必须,执行后会生成可执行的fpm ATPI --with-mysql=/usr/local/mysql/ #指定mysql的安装路径 --with-mysqli=/usr/local/mysql/bin/mysql_config #这两参数是为了整合mysql --with-gd #php连接gd库,要确认系统已安装libpng跟libpng-devel包 |
[root@CentOS64_DB support-files]# cd /usr/local/src/
[root@CentOS64_DB src]# tar xf php-5.4.13.tar.gz
[root@CentOS64_DB src]# cd php-5.4.13
[root@CentOS64_DB php-5.4.13]# ./configure --prefix=/usr/local/php --enable-fpm --with-mysql=/usr/local/mysql/ --with-mysqli=/usr/local/mysql/bin/mysql_config --with-gd
[root@CentOS64_DB php-5.4.13]# make && make install
Build complete. Don‘t forget to run ‘make test‘. Installing PHP CLI binary: /usr/local/php/bin/ Installing PHP CLI man page: /usr/local/php/php/man/man1/ Installing PHP FPM binary: /usr/local/php/sbin/ Installing PHP FPM config: /usr/local/php/etc/ Installing PHP FPM man page: /usr/local/php/php/man/man8/ Installing PHP FPM status page: /usr/local/php/php/fpm/ Installing PHP CGI binary: /usr/local/php/bin/ Installing build environment: /usr/local/php/lib/php/build/ Installing header files: /usr/local/php/include/php/ Installing helper programs: /usr/local/php/bin/ program: phpize program: php-config Installing man pages: /usr/local/php/php/man/man1/ page: phpize.1 page: php-config.1 Installing PEAR environment: /usr/local/php/lib/php/ [PEAR] Archive_Tar - installed: 1.3.7 [PEAR] Console_Getopt - installed: 1.3.0 [PEAR] Structures_Graph- installed: 1.0.4 [PEAR] XML_Util - installed: 1.2.1 [PEAR] PEAR - installed: 1.9.4 Wrote PEAR system config file at: /usr/local/php/etc/pear.conf You may want to add: /usr/local/php/lib/php to your php.ini include_path /usr/local/src/php-5.4.13/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin ln -s -f /usr/local/php/bin/phar.phar /usr/local/php/bin/phar Installing PDO headers: /usr/local/php/include/php/ext/pdo/ [root@CentOS64_DB php-5.4.13]# |
[root@CentOS64_DB php-5.4.13]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@CentOS64_DB php-5.4.13]# /usr/local/php/sbin/php-fpm
[root@CentOS64_DB php-5.4.13]# netstat -anlp | grep php-fpm
启用在nginx的配置文件nginx.conf里面子带有加载PHP的内容
[root@CentOS64_DB php-5.4.13]# 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; } |
[root@CentOS64_DB php-5.4.13]# cd /usr/local/nginx/html/
[root@CentOS64_DB html]# vim phpinfo.php
<?php phpinfo(); ?> |
[root@CentOS64_DB html]# service nginx reload
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
Reloading nginx: [ OK ]
[root@CentOS64_DB html]# vim index.php
<?php $link=mysql_connect(‘localhost‘,‘root‘,‘‘); if($link) echo "<center><h1>Connect MySQL Server Success.</h1></center>"; else echo "Connect MySQL Server Faile"; mysql_close(); ?> |
本文出自 “Jerry” 博客,请务必保留此出处http://alipay.blog.51cto.com/7119970/1582963
标签:lnmp
原文地址:http://alipay.blog.51cto.com/7119970/1582963