lnmp环境搭建
linux NGINX MYSQL PHP
linux 5.4
mysql-5.5.15-linux2.6-i686.tar.gz
libevent-2.0.16-stable.tar.gz
pcre-devel-6.6-2.el5_1.7.i386.rpm
php-5.4.13.tar.bz2
安装mysql-5.5.15-linux2.6-i686.tar.gz(二进制)
安装和使用MySQL二进制分发的基本命令:
shell> groupadd mysql
shell> useradd -r -g mysqlmysql
shell> cd /usr/local
shell> tar zxvf /root/mysql-5.5.15-linux2.6-i686.tar.gz
shell> ln -s /usr/local/mysql-5.5.15-linux2.6-i686 mysql
shell> cd mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db--user=mysql
shell> chown -R root .
shell> chown -R mysql data
shell> cp support-files/my-medium.cnf /etc/my.cnf
shell> bin/mysqld_safe --user=mysql &
shell> cp support-files/mysql.server/etc/init.d/mysql.server
创建MySQL用户和组:
shell> groupadd mysql
shell> useradd -r -g mysql mysql
MYSQL 的安装过程:
解压:
tar -zxvf mysql-5.5.15-linux2.6-i686.tar.gz -C /usr/local
切换目录:cd /usr/local
因为目录太长做一个连接:
ln -s mysql-5.5.15-linux2.6-i686 mysql
测试进入目录:cd mysql
创建组:groupadd -r mysql
创建用户:useradd -r -g mysql mysql -s /sbin/nologin
改变当前文件的所属组用户:chown -R mysql:mysql .
初始化:scripts/mysql_install_db --user=mysql
改回所属:chown -R root .
chown -R mysql data/
创建配置文件:cp support-files/my-medium.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
启动数据库:service mysqld start
端口查询:netstat -tupln | grep mysqld
mysql 的系统加载搜索路径:
vim /etc/profile 编辑 /usr/local/mysql/bin执行文件: . /etc/profile
查询路径是否被加载:echo $PATH
库文件调用:
vim /etc/ld.so.conf.d/mysql.conf 编辑:/usr/local/mysql/lib
刷新缓存:ldconfig
显示缓存:ldconfig -pv |grep mysql
头文件连接:
ln -s /usr/local/mysql/include /usr/include/mysql
service mysqld start
mysql 创建用户口令:mysqladmin -u root -p password '123'
nginx 的安装与配置:
libevent的安装:
tar -zxvf libevent-2.0.16-stable.tar.gz -C /usr/local/src
cd /usr/local/src/libevent-2.0.16-stable/
./configure --prefix=/usr/local/libevent
make && make install
cd /usr/local/libevent/
创建库文件: vim /etc/ld.so.conf.d/libevent.conf 库路径:/usr/local/libevent/lib
刷新缓存:ldconfig
显示缓存: ldconfig -pv |grep libevent
连接头文件:
ln -s /usr/local/libevent/include /usr/include/libevent
pcre 共享库的安装(nginx依赖的库):
pcre (Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正规表达式库.这些在执行正规表达式模式匹配时用与Perl 5同样的语法和语义是很有用的。因此改用pcre来解决C语言中使用正则表达式的问题
rpm -ivh /mnt/cdrom/Server/pcre-devel-6.6-2.el5_1.7.i386.rpm
nginx的安装:
创建账号
groupadd -r nginx
useradd -r -g nginx -s /bin/false -M nginx
tar -zxvf nginx-1.0.11.tar.gz -C /usr/local/src
cd /usr/local/src/nginx-1.0.11/
配置:
./configure \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/tmp/nginx/client/ \
--http-proxy-temp-path=/var/tmp/nginx/proxy/ \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
--with-pcre
make
make install
cd /usr/local/nginx/sbin/
创建目录用于存放临时文件:mkdir -pv /var/tmp/nginx/client
编辑nginx 控制脚本:
控制脚本存放目录:cd /etc/init.d/
vim nginx
#!/bin/bash
# chkconfig:2345 88 77
# description: the nginx web server
prog=/usr/local/nginx/sbin/nginx
pidfile=/var/run/nginx/nginx.pid
lockfile=/var/lock/nginx.lock
start(){
[ -f $lockfile ] && echo"nginx is started " &&exit
echo -n "nginx isstarting... ..."
sleep 1
$prog && touch$lockfile && echo "ok" ||echo "fail"
}
stop(){
[ ! -f $lockfile ] && echo "nginx is stopd "&& exit
echo -n "nginx isstoping... ..."
sleep 1
$prog -s stop &&rm -rf $lockfile && echo "ok" ||echo "fail"
}
status(){
[ -f $pidfile ] && echo "the nginx server isrunning...pid is `cat $pidfile`" || "the nginx server is stoped"
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status
;;
*)
echo "USAGE: start|stop|status|restart"
;;
esac
更改可执行权限:chmod a+x nginx
测试:service nginx start
PHP的安装:
php-5.4.13.tar.bz2
tar -jxvf php-5.4.13.tar.bz2 -C /usr/local/src
cd /usr/local/src/php-5.4.13/
./configure \
--prefix=/usr/local/php \
--enable-fpm \
--enable-sockets \
--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--enable-mbstring \
--enable-xml \
--with-png-dir \
--with-png \
--with-jpeg-dir \
--with-zlib \
--with-freetype-dir \
--with-config-file-path=/etc/php \
--with-config-file-scan-dir=/etc/php5.d
make && make install
cd /usr/local/php/
添加搜索路径:
vim /etc/profile /usr/local/php/bin
执行文件(相当于刷新路径):. /etc/profile 查看路径:echo $PATH
mkdir /etc/php /etc/php5.d
cp php.ini-production /etc/php/php.ini
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod a+x /etc/init.d/php-fpm
产生配置文件:
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
启动:servicephp-fpm start
查看端口:netstat-tupln |grep fpm
chkconfig 管理开机启动:
chkconfig --add php-fpm
查看:chkconfig --list |grep php
nginx 访问php页面的设置
vim /etc/nginx/nginx.conf
启动服务:
service nginx restart
service php-fpm restart
service mysqld start
测试各种服务:
nginx:
浏览器中输入linux主机地址访问
http://192.168.100.129
php
cd usr/local/nginx/html/
mv index.html index.php
浏览器中输入linux主机地址访问
编辑网页 vim index.php
测试:
mysql
浏览器中输入linux主机地址访问
http://192.168.100.129
编辑网页:
测试:
到此环境就搭建好了;就可以安装自己的论坛了: