linux学习之LNMP系统架构的搭建

LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构。Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统。代表版本有:debian、centos、ubuntu、fedora、gentoo等。Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。Mysql是一个小型关系型数据库管理系统。PHP是一种在服务器端执行的嵌入HTML文档的脚本语言。这四种软件均为免费开源软件,组合到一起,成为一个免费、高效、扩展性强的网站服务系统。—-摘自百度百科

1、nginx的安装

下载nginx-1.4.2.tar.gz[root@lnmp ~]# tar zxf nginx-1.4.2.tar.gz[root@lnmp ~]# cd nginx-1.4.2[root@lnmp ~]# cd nginx-1.4.2/src/core/[root@lnmp core]# vim nginx.h#define NGINX_VER "weifang" NGINX_VERSION 自定义名称版本号[root@lnmp core]# cd ../../auto/cc/[root@lnmp cc]# vim gcc# debug#CFLAGS="$CFLAGS -g" 关闭调试功能yum install -y gcc makeyum install -y pcre-develyum install -y openssl-devel[root@lnmp nginx-1.4.2]# ./configure –prefix=/usr/local/lnmp/nginx –with-http_ssl_module –with-http_stub_status_module 源码编译安装,指定安装路径[root@lnmp nginx-1.4.2]# make && make install[root@lnmp ~]# cd /usr/local/lnmp/nginx/[root@lnmp nginx]# cd conf/[root@lnmp conf]# vim nginx.conf添加更改worker_processes 2;events { use epoll; worker_connections 1024;}[root@lnmp conf]# ln -s /usr/local/lnmp/nginx/sbin/nginx /usr/local/sbin/ 做软链接[root@lnmp conf]# nginx -t[root@lnmp conf]# nginx 开启nginx 可以访问IP查看发布内容,发布路径为/usr/local/lnmp/nginx/html/[root@lnmp conf]# netstat -antlp 查看状态

2、mysql的安装

lftp i:~> get pub/docs/lamp/update/lnmp/mysql-5.5.12.tar.gz[root@lnmp ~]# tar zxf mysql-5.5.12.tar.gz[root@lnmp mysql-5.5.12]# yum install -y cmake[root@lnmp mysql-5.5.12]# yum install -y ncurses-devel[root@lnmp mysql-5.5.12]# yum install -y gcc-c++[root@lnmp mysql-5.5.12]# yum install -y bisoncmake安装说明-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \#安装目录-DMYSQL_DATADIR=/usr/local/mysql/data \#数据库存放目录-DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysql.sock \ #Unix socket 文件路径-DWITH_MYISAM_STORAGE_ENGINE=1 \#安装 myisam 存储引擎-DWITH_INNOBASE_STORAGE_ENGINE=1 \#安装 innodb 存储引擎-DWITH_ARCHIVE_STORAGE_ENGINE=1 \#安装 archive 存储引擎-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \#安装 blackhole 存储引擎-DWITH_PARTITION_STORAGE_ENGINE=1 \#安装数据库分区-DENABLED_LOCAL_INFILE=1 \#允许从本地导入数据-DWITH_READLINE=1 \#快捷键功能-DWITH_SSL=yes \#支持 SSL-DDEFAULT_CHARSET=utf8 \#使用 utf8 字符-DDEFAULT_COLLATION=utf8_general_ci \#校验字符-DEXTRA_CHARSETS=all \#安装所有扩展字符集-DMYSQL_TCP_PORT=3306 \#MySQL 监听端口这里使用/usr/local/lnmp/mysql这个路径,存储引擎使用默认一个[root@lnmp mysql-5.5.12]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all[root@lnmp mysql-5.5.12]# make && make install数据库的初始化[root@lnmp mysql-5.5.12]# cd /usr/local/lnmp/mysql/[root@lnmp mysql]# useradd -M -d /usr/local/lnmp/mysql/data/ -s /sbin/nologin mysql 创建用户,制定目录,不允许登录[root@lnmp mysql]# chown -R mysql.mysql * 暂时更改权限[root@lnmp mysql]# cd support-files/[root@lnmp support-files]# cp mysql.server /etc/init.d/mysqld 复制启动脚本[root@lnmp support-files]# cp my-medium.cnf /etc/my.cnf 复制配置文件[root@lnmp support-files]# cd ../scripts/[root@lnmp scripts]# ./mysql_install_db –user=mysql –basedir=/usr/local/lnmp/mysql/ –datadir=/usr/local/lnmp/mysql/data/ 初始化数据库[root@lnmp scripts]# cd ../bin/ 存放的是命令,给root用户的PATH加入这个路径[root@lnmp bin]# vim ~/.bash_profile 要给所有用户加的话vim /etc/profilePATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin[root@lnmp bin]# source ~/.bash_profile[root@lnmp bin]# echo $PATH 查看是否生效[root@lnmp bin]# cd ../data/[root@lnmp data]# ls 这时候就有数据了mysql mysql-bin.000001 mysql-bin.000002 mysql-bin.index performance_schema test[root@lnmp data]# cd ..[root@lnmp mysql]# chown root * -R[root@lnmp mysql]# chown mysql data/ -R 权限修改[root@lnmp mysql]# /etc/init.d/mysqld start 启动mysql[root@lnmp mysql]# mysql_secure_installation 初始设置密码等数据库密码 mmmmmm

3、php的安装

准备工作,安装libiconv-1.13.1.tar.gz 加强系统对支持字符编码转换的功能libmcrypt-2.5.8.tar.bz2 mcrypt mhash是php加密算法扩展库mhash-0.9.9.9.tar.bz2mcrypt-2.6.8.tar.gzlftp i:/pub/docs/lamp/update/lnmp> get libiconv-1.13.1.tar.gz libmcrypt-2.5.8.tar.bz2 mhash-0.9.9.9.tar.bz2 mcrypt-2.6.8.tar.gz[root@lnmp ~]# tar zxf libiconv-1.13.1.tar.gz[root@lnmp ~]# cd libiconv-1.13.1[root@lnmp libiconv-1.13.1]# ./configure –prefix=/usr/local/lnmp/modules/libiconv[root@lnmp libiconv-1.13.1]# make && make install[root@lnmp ~]# tar jxf libmcrypt-2.5.8.tar.bz2[root@lnmp ~]# cd libmcrypt-2.5.8[root@lnmp libmcrypt-2.5.8]# ./configure –prefix=/usr/local/lnmp/modules/libmcrypt[root@lnmp libmcrypt-2.5.8]# make && make install[root@lnmp libmcrypt-2.5.8]# cd libltdl/ 安装扩展[root@lnmp libltdl]# ./configure –prefix=/usr/local/lnmp/modules/libmcrypt/ –enable-ltdl-install[root@lnmp libltdl]# make && make install[root@lnmp ~]# tar jxf mhash-0.9.9.9.tar.bz2[root@lnmp ~]# cd mhash-0.9.9.9[root@lnmp mhash-0.9.9.9]# ./configure –prefix=/usr/local/lnmp/modules/mhash[root@lnmp mhash-0.9.9.9]# make && make install[root@lnmp ~]# tar zxf mcrypt-2.6.8.tar.gz[root@lnmp ~]# cd mcrypt-2.6.8[root@lnmp mcrypt-2.6.8]# ln -s /usr/local/lnmp/modules/mhash/lib/* /usr/local/lib/[root@lnmp mcrypt-2.6.8]# ln -s /usr/local/lnmp/modules/mhash/include/* /usr/local/include/[root@lnmp mcrypt-2.6.8]# vim /etc/ld.so.conf 开机加载include ld.so.conf.d/*.conf/usr/local/lnmp/modules/libmcrypt/lib//usr/local/lnmp/modules/mhash/lib//usr/local/lib/[root@lnmp mcrypt-2.6.8]# ldconfig[root@lnmp mcrypt-2.6.8]# ./configure –prefix=/usr/local/lnmp/modules/mcrypt –with-libmcrypt-prefix=/usr/local/lnmp/modules/libmcrypt/[root@lnmp mcrypt-2.6.8]# make && make installphp的安装lftp i:~> get pub/docs/lamp/update/lnmp/php-5.4.12.tar.bz2[root@lnmp ~]# tar jxf php-5.4.12.tar.bz2[root@lnmp ~]# cd php-5.4.12[root@lnmp php-5.4.12]# useradd -M -d /usr/local/lnmp/nginx/ -s /sbin/nologin nginx[root@lnmp php-5.4.12]# yum install -y curl-devel libxml2-devel libjpeg-devel libpng-devel freetype-devel gmp-devel net-snmp-devel[root@lnmp php-5.4.12]# ./configure –prefix=/usr/local/lnmp/php –with-config-file-path=/usr/local/lnmp/php/etc –with-openssl –with-snmp –with-gd –with-zlib –with-curl –with-libxml-dir –with-png-dir –with-jpeg-dir –with-freetype-dir –with-pear –with-gettext –with-gmp –enable-inline-optimization –enable-soap –enable-ftp –enable-sockets –enable-mbstring –with-mysqli=/usr/local/lnmp/mysql/bin/mysql_config –enable-fpm –with-fpm-user=nginx –with-fpm-group=nginx –with-mcrypt=/usr/local/lnmp/modules/libmcrypt/ –with-mhash=/usr/local/lnmp/modules/mhash/避免之后与数据库的关联而重编译新模块,在这里参数再加上–with-php-config=/usr/local/lnmp/php/bin/php-config –with-mysql=/usr/local/lnmp/mysql/ –with-mysql-sock=/usr/local/lnmp/mysql/data/mysql.sock[root@lnmp php-5.4.12]# make[root@lnmp php-5.4.12]# make install

4、开启php

[root@lnmp php-5.4.12]# cp php.ini-production /usr/local/lnmp/php/etc/php.ini[root@lnmp php-5.4.12]# cd sapi/fpm/[root@lnmp fpm]# cp init.d.php-fpm /etc/init.d/php-fpm[root@lnmp fpm]# chmod +x /etc/init.d/php-fpm[root@lnmp fpm]# cd /usr/local/lnmp/php/etc/[root@lnmp etc]# vim php.ini 主配置文件加入下边两条cgi.fix_pathinfo=0date.timezone = Asia/Shanghai[root@lnmp etc]# cp php-fpm.conf.default php-fpm.conf[root@lnmp etc]# vim php-fpm.confpid = run/php-fpm.pid[root@lnmp etc]# /etc/init.d/php-fpm start

5、打开nginx的php功能

[root@lnmp etc]# cd ../../nginx/conf/[root@lnmp conf]# vim nginx.confuser nobody; location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi.conf; }[root@lnmp conf]# nginx -s reload编辑[root@lnmp conf]# vim ../html/index.php<?phpphpinfo()?>之后浏览http://192.168.0.142/index.php,就会出现动态页面信息,以后静态自己显示,动态交给php如果之前php安装忘记加载mysql模块解决这个问题[root@lnmp ~]# cd php-5.4.12/ext/mysql[root@lnmp mysql]# phpize[root@lnmp mysql]# ./configure –with-php-config=/usr/local/lnmp/php/bin/php-config –with-mysql=/usr/local/lnmp/mysql/ –with-mysql-sock=/usr/local/lnmp/mysql/data/mysql.sock[root@lnmp mysql]# make && make install然后 会在/usr/local/lnmp/php/lib/php/extensions/no-debug-non-zts-20100525/有mysql.so[root@lnmp ~]# vim /usr/local/lnmp/php/etc/php.ini 添加853 extension=mysql.so[root@lnmp ~]# /etc/init.d/php-fpm reload之后,会在php信息的mysql中出现MYSQL_INCLUDE no valueMYSQL_LIBS no value

6、论坛的搭建

nginx,php的执行者不能是网站的拥有者lftp i:~> get pub/docs/Discuz_X2.5_SC_UTF8.zip[root@lnmp ~]# yum install unzip -y[root@lnmp ~]# unzip Discuz_X2.5_SC_UTF8.zip[root@lnmp ~]# mv upload/ /usr/local/lnmp/nginx/html/bbs[root@lnmp ~]# cd /usr/local/lnmp/nginx/html/bbs/[root@lnmp bbs]# vim ../../conf/nginx.conf location / { root html; index index.php index.html index.htm; }[root@lnmp bbs]# nginx -s reload然后访问192.168.0.142/bbs [root@lnmp bbs]# chmod 777 data/ -R[root@lnmp bbs]# chmod 777 uc_* -R[root@lnmp bbs]# chmod 777 config/ -R数据库服务器 localhost数据库名 discuz数据库密码 mmmmmm管理员帐号 admin管理员密码 mmmmmm继续安装,结束。之后访问,解决管理员首页问题[root@lnmp bbs]# cd install/[root@lnmp install]# mv index.php /mnt/功能就可以使用了!为使该服务器重启可用[root@lnmp ~]# chkconfig php-fpm on[root@lnmp ~]# chkconfig mysqld on开机后,启动nginx

原来和文字沾上边的孩子从来都是不快乐的,

linux学习之LNMP系统架构的搭建

相关文章:

你感兴趣的文章:

标签云: