部署前准备;
nginx的安装参考其他博文
本文只针对mysql+php
iptables和selinux不做配置,关掉
系统光盘作为yum源,配置yum文件
从网络获取源码包,ip地址能上网
mysql使用cmake编译安装的,先编译安装cmake
编译安装及配置mysql:
[[email protected] ~]# wget http://down1.chinaunix.net/distfiles/mysql-5.5.22.tar.gz
[[email protected] ~]# tar zxvf mysql-5.5.22.tar.gz -C /usr/src/
[[email protected] ~]# cd /usr/src/mysql-5.5.22/
[[email protected] mysql-5.5.22]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DSYSCONFDIR=/etc/
[[email protected] mysql-5.5.22]# make &&make install
[[email protected] mysql-5.5.22]# cp support-files/my-medium.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y
[email protected] mysql-5.5.22]# cp support-files/mysql.server /etc/init.d/mysqld
[[email protected] mysql-5.5.22]# chmod +x /etc/init.d/mysqld
[[email protected] mysql-5.5.22]# chkconfig --add mysqld
[[email protected] mysql-5.5.22]# echo "PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile
[[email protected] mysql-5.5.22]# source /etc/profile
[[email protected] mysql-5.5.22]# groupadd mysql
[[email protected] mysql-5.5.22]# useradd -M -s /sbin/nologin mysql -g mysql
[[email protected] mysql-5.5.22]# cd /usr/local/mysql/scripts/
[[email protected] scripts]# ./mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
Installing MySQL system tables...
OK
Filling help tables...
OK
[[email protected] scripts]# cd
[[email protected] ~]# /etc/init.d/mysqld start
Starting MySQL...[确定]
[[email protected] ~]# mysqladmin -uroot password 123123
[[email protected] ~]# mysql -uroot -p123123
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.22-log Source distribution
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
mysql> quit;
安装php:
[[email protected] ~]# yum -y install libxml2-devel gd-devel zlib-devel
[[email protected] ~]# wget http://cn2.php.net/distributions/php-5.4.36.tar.bz2
[[email protected] ~]# tar jxvf php-5.4.36.tar.bz2 -C /usr/src/
[[email protected] ~]# cd /usr/src/php-5.4.36/
[[email protected] php-5.4.36]# ./configure --prefix=/usr/local/php5 --with-gd --with-zlib --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php5 --enable-mbstring --enable-fpm --with-jpeg-dir=/usr/lib
[[email protected] php-5.4.36]# make &&make install
[[email protected] php-5.4.36]# ls /usr/local/php5/
bin etc include lib php sbin var
[[email protected] php-5.4.36]# cp php.ini-development /usr/local/php5/php.ini
[[email protected] ~]# ln -s /usr/local/php5/bin/* /usr/local/bin/
[[email protected] ~]# ln -s /usr/local/php5/sbin/* /usr/local/sbin/
安装ZendGuardLoader:
[[email protected] ~]# tar zxvf ZendGuardLoader-70429-PHP-5.4-linux-glibc23-x86_64.tar.gz
ZendGuardLoader-70429-PHP-5.4-linux-glibc23-x86_64/
ZendGuardLoader-70429-PHP-5.4-linux-glibc23-x86_64/php-5.4.x/
ZendGuardLoader-70429-PHP-5.4-linux-glibc23-x86_64/php-5.4.x/ZendGuardLoader.so
ZendGuardLoader-70429-PHP-5.4-linux-glibc23-x86_64/README.txt
[[email protected] ~]# cp ZendGuardLoader-70429-PHP-5.4-linux-glibc23-x86_64/php-5.4.x/ZendGuardLoader.so /usr/local/php5/
[[email protected] ~]#
编辑php.ini(/usr/local/php/etc )文件,在最后位置添加以下内容:
[[email protected] ~]# vi /usr/local/php5/php.ini
[Zend Guard]
zend_extension=/usr/local/php5/ZendGuardLoader.so
; Enables loading encoded scripts. The default value is On
zend_loader.enable=1
; Optional: following lines can be added your php.ini file for ZendGuardLoader configuration
zend_loader.disable_licensing=0
zend_loader.obfuscation_level_support=3
:wq
配置nginx支持php:
[[email protected] ~]# cd /usr/local/php5/etc/
[[email protected] etc]# vi php-fpm.conf ##新建配置文件
[global]
pid = run/php-fpm.pid
[www]
listen = 127.0.0.1:9000
user = nginx
group = nginx
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
[[email protected] ~]# /usr/local/sbin/php-fpm ##启动php-fpm
[[email protected] ~]# netstat -utpln |grep php
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 5587/php-fpm
编写启动LNMP脚本:
[[email protected] ~]# vi /etc/init.d/lnmp
#!/bin/bash
# chkconfig: 35 95 30
# description: This script is for LNMP Management!
NGF=/usr/local/nginx/sbin/nginx
NGP=/usr/local/nginx/logs/nginx.pid
FPMF=/usr/local/php5/sbin/php-fpm
FPMP=/usr/local/php5/var/run/php-fpm.pid
case $1 in
start)
$NGF &&echo "nginx is starting! "
$FPMF && echo "php-fpm is starting! "
;;
stop)
kill -QUIT $(cat $NGP) &&echo "nginx is stoped! "
kill -QUIT $(cat $FPMP) &&echo "php-fpm is stoped! "
;;
restart)
$0 stop
$0 start
;;
reload)
kill -HUP $(cat $NGP)
kill -HUP $(cat $FPMP)
;;
status)
netstat -utpln |grep nginx &>/dev/null
if [ $? -eq 0 ]
then
echo "nginx is running! "
else
echo "nginx is not running! "
fi
netstat -upltn |grep php-fpm &>/dev/null
if [ $? -eq 0 ]
then
echo "php-fpm is runing! "
else
echo "php-fpm is not running! "
fi
;;
*)
echo "Usage $0 {start|stop|status|restart}"
exit 1
;;
esac
:wq
[[email protected] ~]# chmod +x /etc/init.d/lnmp
[[email protected] ~]# chkconfig --add lnmp
[[email protected] ~]# /etc/init.d/lnmp status
nginx is running!
php-fpm is runing!