LNMP安装与启动脚本编写

本文详细介绍如何从零开始在Linux环境下安装并配置MySQL、PHP及Nginx,形成完整的LAMP(Linux, Apache/NGINX, MySQL, PHP)网站运行环境。文章包括下载源文件、编译安装、配置启动脚本等步骤。

1、安装mysql

1
cd /usr/local/src/

下载mysql:

1
wget http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.72-linux-x86_64-glibc23.tar.gz

解压:

1
tar zxvf/usr/local/src/mysql-5.1.72-linux-x86_64-glibc23.tar.gz

更改命名:

1
mv mysql-5.1.72-linux-x86_64-glibc23  /usr/local/mysql

设置mysql用户:

1
useradd -s /sbin/nologin mysql

创建目录与目录所属:

1
2
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql

编译:

1
cd /usr/local/mysql
1
./scripts/mysql_install_db --user=mysql  --datadir=/data/mysql

拷贝配置文件:

1
cp support-files/my-large.cnf /etc/my.cnf

设置启动脚本:

1
cp support-files/mysql.server  /etc/init.d/mysqld
1
chmod 755 /etc/init.d/mysqld
1
2
3
vim /etc/init.d/mysqld   #修改datadir
         {basedir=/usr/local/mysql
         {datadir=/data/mysql
1
2
3
chkconfig --add mysqld
chkconfig mysqld on
service mysqld start

 

2、php安装

下载:

1
wget http://cn2.php.net/distributions/php-5.4.37.tar.bz2

解压:

1
tar jxf php-5.4.37.tar.bz2

创建账户:

1
useradd -s /sbin/nologin php-fpm

编译:

1
cd php-5.4.37
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
./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
1
make && make install

拷贝配置文件:

1
cp php.ini-production/usr/local/php  /etc/php.ini

配置启动项:

1
2
3
4
5
cp /usr/local/src/php-5.4.37/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm
chkconfig --add php-fpm
service php-fpm start
chkconfig php-fpm on


配置php-fpm配置文件:

1
mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

 

3、安装nginx

下载:

1
wget http://nginx.org/download/nginx-1.6.3.tar.gz

解压:

1
tar zxvf nginx-1.6.3.tar.gz

编译:

1
2
3
4
cd nginx-1.6.3
./configure   --prefix=/usr/local/nginx   --with-pcre
make
make install

启动nginx: 

1
/usr/local/nginx/sbin/nginx

编写nginx启动脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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
       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

 

保存后:

1
2
3
chmod 755 /etc/init.d/nginx
chkconfig --add nginx
chkconfig nginx on


本文转自 sykmiao 51CTO博客,原文链接:http://blog.51cto.com/syklinux/1740062,如需转载请自行联系原作者
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值