linux的lnmp的搭建
1、MySQL安装
安装mysql-5.1.40
cd /usr/local/src
wget https://cdn.mysql.com/archives/mysql-5.1/mysql-5.1.40-linux-x86_64-glibc23.tar.g
tar -zxvf mysql-5.1.40-linux-x86_64-glibc23
useradd mysql -s /sbin/nologin
mv mysql-5.1.40-linux-x86_64-glibc23 /usr/local/mysql
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
cp my-medium.cnf /etc/my.cnf
cp mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
/etc/init.d/mysqld start
ps aux|grep mysql
netstat -lnp
(1)cd /usr/local/src
(2)wget https://cdn.mysql.com/archives/mysql-5.1/mysql-5.1.40-linux-x86_64-glibc23.tar.gz 去官网查询最新的mysql 下载地址;
(3)tar -zxvf mysql-5.1.40-linux-x86_64-glibc23 解压下载下来的文件:
(4)useradd mysql -s /sbin/nologin 创建mysql用户,禁止登录;
mv mysql-5.1.40-linux-x86_64-glibc23 /usr/local/mysql拷贝文件到/usr/local/mysql目录下
mkdir -p /data/mysql 创建mysql数据目录;
chown -R mysql:mysql /data/mysql 设置mysql数据目录属性;
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql 进行mysql的初始化;
(5)cd support-files/
cp my-medium.cnf /etc/my.cnf 拷贝标准配置文件;
(6)cp mysql.server /etc/init.d/mysqld 拷贝标准启动脚本
脚本的basedir、datadir:
basedir=/usr/local/mysql
datadir=/data/mysql
(7)chkconfig --add mysqld 添加maysql服务;
chkconfig mysqld on 设置mysql服务开机启动;
/etc/init.d/mysqld start 启动 mysql服务;
ps aux|grep mysql 查看mysql进程;
netstat -lnp 查看3306端口是否开启;
2、PHP-5.3.28安装(大致同lamp,个别参数有变化)
cd /usr/local/src
wget http://am1.php.net/distributions/php-5.2.28.tar.gz
tar -zxvf php-5.3.28.tar.gz
cd php-5.3.28
useradd php-fpm -s /sbin/nologin
./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-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-ftp --enable-exif --disable-ipv6 --with-curl
make & make install
cp php.ini-development /usr/local/php-fpm/etc/php.ini
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chkconfig -add php-fpm
chkconfig php-fpm on
chmod 755 /etc/init.d/php-fmp
cp /usr/local/php-fpm/etc/{php-fpm.conf.default,php#-fpm.conf}
service php-fpm start
3、安装nginx-1.6.3
cd /usr/loacal/src
wget http://nginx.org/download/nginx-1.6.3.tar.gz
tar -zxvf nginx-1.6.3.tar.gz
cd nginx-1.6.3
./configure --prefix=/usr/local/nginx
make & make install
启动nginx:
/usr/local/nginx/sbin/nginx
4、编写nginx启动脚本
vim /etc/init.d/nginx //加入如下内容
#!/bin/bash
#nx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/run/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
保存后:
chkconfig --add nginx
chkconfig nginx on
chmod 755 /etc/init.d/nginx
/etc/init.d/nginx start
5、配置解析PHP
vim /usr/local/nginx/conf/nginx.conf 修改如下的配置,其中/data/www是之前lamp安装的discuz目录:
location / {
root /data/www;
index index.html index.htm index.php;
}
在修改PHP解析的段,去掉#,更改root、fastcgi_param项:
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 -t
重新加载nginx:/usr/local/nginx/sbin/nginx -s reload
vim /data/www/phpinfo.php
增加
浏览器访问192.168.60.119/phpinfo.php (192.168.60.119是主机ip)