总结: ①安装VMware并部署centos系统(自己安) ②依次序安装nginx、MySQL、PHP ③测试配置Ngin+ PHP ④测试配置PHP & MySQL ⑤整体测试安装部署的网站(以iwebshop为例) |
lnmp简介 大约在2010年以前,互联网公司最常用的经典Web服务环境组合就是LAMP(即Linux、Apache、MySQL、PHP),近几年随着Nginx Web服务的逐渐流行,又出现了新的Web服务环境组合——LNMP或LEMP,其中LNMP为Linux、Nginx、MySQL、PHP等首字母的缩写,而LEMP中的E则表示Nginx。现在,LNMP已经逐渐成为国内大中型互联网公司网站的主流组合环境,因此,我们这次学习将以LNMP环境为基础,进行学习。 |
基本环境配置 因为我们安装的软件比较多,所以我们需要创建服务和软件的专用目录 基本环境配置 基本软件目录 mkdir /data/{server,soft} -p 注意: 为什么要创建专用目录呢? 因为东西多,我好找。 |
LNMP 之 N
Nginx是一个轻量级的Web软件,它有非常强大的功能,但是我们这里之学习他的最基本的web功能
(一)nginx简介
nginx的官方网站:http://nginx.orgNginx作为Web服务器的主要应用场景包括:·使用Nginx运行HTML、JS、CSS、小图片等静态数据(此功能类似Lighttpd软件)。·Nginx结合FastCGI运行PHP等动态程序(例如使用fastcgi_pass方式)。
(二)nginx安装
1.基本依赖环境部署
安装nginx软件的基本依赖软件
yum install openness-devel pcre-devel gcc -y
2.编译安装nginx
注意:编译安装nginx的时候,应该有一个专用的启动用户,我们把这个用户设置为 www
编译安装nginxtar xf nginx-1.10.2.tar.gz 解压安装包cd nginx-1.10.2 进入解压后的文件夹./configure –prefix=/data/server/nginx –user=www –group=www 安装路径为data/server,连接www用户makemake install
创建专用的启动用户wwwuseradd www -s /sbin/nologin -M
修改配置文件[root@localhost soft]# vim /data/server/nginx/conf/nginx.confuser www;注意:将user后面的nobody更改为www
3.检查效果
启动nginx
/data/server/nginx/sbin/nginx检查端口[root@localhost nginx-1.10.2]# netstat -tnulp | grep nginxtcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 42500/nginx
LNMP 之 M
(一)mysql简介
MySQL是互联网领域里非常重要的、深受广大用户欢迎的一款开源关系型数据库软件,由瑞典MySQL AB公司开发与维护。2006年,MySQL AB公司被SUN公司收购,2008年,SUN公司又被传统数据数据库领域大佬甲骨文(Oracle)公司收购。因此,MySQL数据库软件目前属于Oracle公司,但仍是开源的,Oracle公司收购MySQL的战略意图显而易见,其自身的Oracle数据库继续服务于传统大中型企业,而利用收购的MySQL抢占互联网领域数据库份额,完成其战略布局。MySQL是一种关系型数据库管理软件,关系型数据库的特点是将数据保存在不同的二维表中,并且将这些表放入不同的数据库中,而不是把所有数据统一放在一个大仓库里,这样的设计增加了MySQL的读取速度,灵活性和可管理性也得到了很大提高。访问及管理MySQL数据库的最常用标准化语言为SQL结构化查询语言。
(二) mysql安装
mysql的安装方法很多,最简单的而且最适用就是二进制方法安装。接下来我们使用mysql的二进制包来进行安装部署mysql
1.解压软件
解压软件
cd /data/soft/
tar xf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz -C /data/server/
cd /data/server/
ln -s mysql-5.6.35-linux-glibc2.5-x86_64 mysql
2.基本用户
创建专用用户
cd mysql
useradd -s /sbin/nologin -M mysql
3.初始化
初始化mysql数据库
/data/server/mysql/scripts/mysql_install_db –basedir=/data/server/mysql –datadir=/data/server/mysql/data/ –user=mysql
4.相关配置文件
数据库配置文件管理
mv /etc/my.cnf /etc/my.cnf-bak
cp /data/server/mysql/support-files/my-default.cnf /etc/my.cnf
数据库启动命令配置
cp /data/server/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
启动文件修改\
sed -i ‘s#/usr/local/mysql#/data/server/mysql#g’ /data/server/mysql/bin/mysqld_safe /etc/init.d/mysqld
数据库文件权限管理
chown -R mysql.mysql /data/server/mysql/
5.启动数据库
启动数据库前检查
netstat -tnulp | grep mysql
启动数据库
/etc/init.d/mysqld start
检查数据库启动状态
netstat -tnulp|grep mysqld
配置环境变量
vim /etc/profile
# 末尾添加这条配置
PATH=/data/server/mysql/bin:$PATH
让配置文件生效
source /etc/profile
测试进入数据库[root@localhost server]# mysqlWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.6.35 MySQL Community Server (GPL) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners. Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement. mysql> 将mysql服务设置为开机自启动服务chkconfig –add mysqldchkconfig mysqld on
LNMP 之 P
(一) 基本软件安装
安装基本依赖软件yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel -y 安装libiconv软件cd /data/softwget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gztar zxf libiconv-1.14.tar.gzcd libiconv-1.14./configure –prefix=/usr/local/libiconvmakemake install 安装其他软件包wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repoyum -y install libmcrypt-devel mhash mcrypt注释:这三个软件包,在本地的光盘镜像中没有,所以我们需要去网上下载
(二)php软件安装
安装phpcd /data/soft/tar xf php-5.3.29.tar.gzcd php-5.3.29 在解压后的PHP目录内执行ln -s /data/server/mysql/lib/libmysqlclient.so.18 /usr/lib64/touch ext/phar/phar.phar ./configure \–prefix=/data/server/php-5.3.29 \–with-mysql=/data/server/mysql \–with-pdo-mysql=mysqlnd \–with-iconv-dir=/usr/local/libiconv \–with-freetype-dir \–with-jpeg-dir \–with-png-dir \–with-zlib \–with-libxml-dir=/usr \–enable-xml \–disable-rpath \–enable-bcmath \–enable-shmop \–enable-sysvsem \–enable-inline-optimization \–with-curl \–enable-mbregex \–enable-fpm \–enable-mbstring \–with-mcrypt \–with-gd \–enable-gd-native-ttf \–with-openssl \–with-mhash \–enable-pcntl \–enable-sockets \–with-xmlrpc \–enable-zip \–enable-soap \–enable-short-tags \–enable-static \–with-xsl \–with-fpm-user=www \–with-fpm-group=www \–enable-ftp 编译时可能会出错,先执行上面的操作再编译安装makemake install
(三) php文件配置
创建目录,生成程序文件,这里失败的话/data/server下就不会有php的目录[root@localhost php-5.3.29]# ls /data/server/mysql mysql-5.6.35-linux-glibc2.5-x86_64 nginx php-5.3.29 创建一个软链接,方便使用,更新软件时,重新创建软链接即可cd /data/serverln -s php-5.3.29 php 把解压包内的php解析文件拷贝到php安装目录下cd /data/soft/php-5.3.29cp php.ini-production /data/server/php/lib/php.ini修改php.ini文件,开启session功能vim /data/server/php/lib/php.ini…[Session];Handler used to store/retrieve data.; http://php.net/session.save-handlersession.save_handler = files原内容:;session.save_path = “/tmp修改后内容:session.save_path = “/tmp复制php-fpm的配置文件,默认没有该文件但是有一个备份文件cd /data/server/php/etc/cp php-fpm.conf.default php-fpm.conf 启动php和nginx一样,使用程序目录下的启动命令来启动php,然后检查进程和端口号即可。[root@localhost etc]# /data/server/php/sbin/php-fpm[root@localhost etc]# netstat -tnulp | grep php-fpmtcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 35770/php-fpm [root@localhost etc]# ps aux | grep php-fpmroot 35770 0.0 0.1 222924 4380 ? Ss 22:15 0:00 php-fpm: master process (/data/server/php-5.3.29/etc/php-fpm.conf)www 35771 0.0 0.1 222924 4124 ? S 22:15 0:00 php-fpm: pool www www 35772 0.0 0.1 222924 4124 ? S 22:15 0:00 php-fpm: pool www root 35778 0.0 0.0 103316 844 pts/4 S+ 22:16 0:00 grep php-fpm
Nginx & PHP
测试Nginx与PHP之间的连通性
配置Nginx主配置文件
配置iwebshop虚拟主机配置文件
当用户是静态的请求就跳转到主页文件,php动态请求的话就交给PHP软件来除了
说明:利用nginx的location区块实现动态请求与静态请求的分别处理
[root@localhost etc]# vim /data/server/nginx/conf/nginx.conf# 在http配置段内容增加下面的内容 底部敲:set paste
server { listen 80; server_name iwebshop.itcast.com; #静态请求处理的location location / { root html/iwebshop; index index.php index.html index.htm; } #动态请求处理的location location ~* .*\.(php|ph:p5)?$ { root html/iwebshop; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } }
修改完配置文件后,检查语法并重启nginx服务
[root@localhost etc]# /data/server/nginx/sbin/nginx -tnginx: the configuration file /data/server/nginx/conf/nginx.conf syntax is oknginx: configuration file /data/server/nginx/conf/nginx.conf test is successful[root@localhost etc]# /data/server/nginx/sbin/nginx -s reload 配置域名解析[root@localhost html]# vim /etc/hosts…127.0.0.1 iwebshop.itcast.com 生成一个php测试文件生成一个php的测试文件到blog站点目录下cd /data/server/nginx/htmlmkdir iwebshopcd iwebshopvim test_info.php粘贴<?php phpinfo(); ?>
此时blog站点目录下应该有一个主页文件和php测试文件[root@localhost html]# ll /data/server/nginx/html/blog/total 4-rw-r–r–. 1 root root 20 Nov 3 22:22 test_info.php 测试nginx与php的连通性浏览器访问iwebshop.itcast.com/test_info.php
PHP & MySQL
测试PHP与MySQL之间连通性 进入mysqlMysql 创建数据库mysql -uroot -p123456 #登录数据库show databases; #查看数据库create database iwebshop; #创建一个数据库 创建数据库用户grant all on wordpress.* to iwebshop@’localhost’ identified by ‘123456’; flush privileges;select user,host from mysql.user; #创建一个用户iwebshop,权限为全部,并且设置允许登录的网段,和最后设置密码#flush privileges 创建完用户后,更新一下数据库的信息#查看数据库内的用户信息,和对应可以登录的主机 生成一个mysql的测试文件到blog的站点目录下,生成一个mysql测试文件[root@localhost nginx]# cd /data/server/nginx/html/iwebshop/[root@localhost blog]# vim test_mysql.php <?php//$link_id=mysql_connect(‘主机名‘,’用户‘,’密码‘);//mysql -u用户 -p密码 -h 主机$link_id=mysql_connect(‘localhost’,’iwebshop’,’123456′) or mysql_error();if($link_id){ echo “mysql successful by wangshusen !\n”; }else{ echo mysql_error(); }?> 测试PHP与MySQL的连通性访问http://iwebshop.itcast.com/test_mysql.php出现下面的内容就是测试成功
测试完毕后,就可以将我们刚才生成的两个文件删除掉了
cd /data/server/nginx/html/iwebshop
rm -f *.php
整体测试
上传iwebshop软件
cd /data/soft/
上传 iwebshop2.1.11090110_data.zip
转移博客到nginx的iwebshop目录中
unzip iwebshop2.1.11090110_data.zip
mv iwebshop/* /data/server/nginx/html/iwebshop/
查看文件效果
[root@localhost soft]# ls /data/server/nginx/html/iwebshop/
backup classes controllers favicon.ico index.php language license.txt runtime test_info.php upload
chart config docs image install lib plugins sitemaps.xsl test_mysql.php views
修改权限
chown -R www.www /data/server/nginx/html/iwebshop
注释:
因为我们给我们的nginx配置启动的用户是www,也就是说只有www用户能访问的到的文件才能访问
浏览器访问iwebshop.itcast.com/index.php
勾选“我同意上述条款和条件“后,点击“下一步“
看到绿色提示“您的…”,说明我们的基本环境是没有问题的,接下来点击“下一步“
接下来配置配置数据库,配置好登录数据的用户名和密码,点击开始检测
当提示信息为“数据库连接正确“,说明我们的数据库配置是没有任何问题的,接下来配置后台的登录信息
点击下一步
安装完成后,可以点击到前台查看效果
可以点击到后台查看效果
输入我们刚才配置的admin密码123456,然后输入验证码oyena,点击登录,查看效果
到现在为止,我们的iwebshop环境就部署完毕了