编辑lnmp安装,为了以后使用方便,若要将nmp分开到不同server上,只需要将安装目录创建,安装命令没有变化
1 环境初始化
#系统环境 [[email protected] ~]# cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) [[email protected] ~]# uname -a Linux anyux 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux #关闭selinux firewall [[email protected] ~]# getenforce Disabled [[email protected] ~]# systemctl status firewalld.service ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: inactive (dead) Docs: man:firewalld(1)
1.1创建目录
#源码包存放位置 mkdir -p /server/tools #程序安装位置 mkdir /application/
2安装nginx
2.1 下载及准备安装
http://www.nginx.org
#进入存放位置 cd /server/tools/ wget http://nginx.org/download/nginx-1.10.3.tar.gz # 解压 tar xf nginx-1.10.3.tar.gz # 创建用户 useradd www -u 1014 -s /sbin/nologin -M # 解除依赖 yum install -y openssl-devel pcre-devel
2.2 nginx编译安装
cd nginx-1.10.3/ # 配置安装选项 ./configure --prefix=/application/nginx-1.10.3 --user=www --group=www --with-http_stub_status_module --with-http_ssl_module # --prefix=/application/nginx-1.10.3 指定安装位置 # --user=www --group=www 指定运行用户 # --with-http_stub_status_module 开启http_stub_status_module模块 # --with-http_ssl_module 开启http_stub_status_module模块 # 编译 安装 make && make install # 创建软链接 方便使用及版本迁移 ln -s /application/nginx-1.10.3/ /application/nginx # 清除 /application/nginx/conf/nginx.conf 注释信息 egrep -v "#|^$" /application/nginx/conf/nginx.conf.default >/application/nginx/conf/nginx.conf # 启动测试 /application/nginx/sbin/nginx # 检查nginx服务状态 # 也可以在浏览器输入IP地址查看 curl -s -I -w %{http_code}"\n" -o /dev/null 10.0.0.127 200 # 返回值 200 表示成功 查看http状态码了解更多详情 # -o(小写字母O):将文件保存为命令行中指定的文件名的文件中 此处定向到为空 # -s: 取消默认curl信息头 # -w %{http_code}: 输出http状态码的内容 # 10.0.0.127: web服务器IP地址 # 检查服务是不开启 ps -ef | grep nginx # 检查80端口 netstat -lntup | grep 80
3安装php
# 解决依赖 yum install -y zlib-devel openssl-devel pcre-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libivonv-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel bzip2-devel readline-devel recode recode-devel libtidy libtidy-devel libmcrypt-devel mhash mcrypt # libiconv 安装包需要自己下载 cd /server/tools/ # 解压 tar xf libiconv-1.14.tar.gz cd libiconv-1.14/ # 配置安装选项 指定安装位置 ./configure --prefix=/usr/local/libiconv # 编译 安装 make && make install # 如果上面的安装出错 使用下载 libiconv rpm包使用 链接:https://pan.baidu.com/s/1eR1LB8I 密码:rnr2 cd /server/tools # http://php.net/get/php-5.5.32.tar.gz/from/a/mirror 下载php源码的位置 # 下载php5.5.32 wget http://110.96.193.6:82/1Q2W3E4R5T6Y7U8I9O0P1Z2X3C4V5B/php.net/distributions/php-5.5.32.tar.gz # 解压 tar xf php-5.5.32.tar.gz cd cd php-5.5.32/ # # 配置安装选项 ./configure --prefix=/application/php-5.5.32 --with-mysql=mysqlnd --with-mysqli=mysqlnd --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-soap --enable-short-tags --enable-static --with-xsl --with-fpm-user=www --with-fpm-group=www --enable-ftp --enable-opcache=no # 编译 安装 make && make install # 检查 echo $? # 返回0 表示成功 # 创建php软件链接 ln -s /application/php-5.5.32/ /application/php # 配置php-fpm.conf mkdir /application/php/etc/ -p cp /server/tools/php-5.5.32/sapi/fpm/php-fpm.conf /application/php/etc/ # 配置php.ini mkdir /application/php/lib/ -p \cp /server/tools/php-5.5.32/php.ini-production /application/php/lib/php.ini
4 配置 nginx 解析php脚本
vim /application/nginx/conf/nginx.conf # 在server模块中加入 index.php location / { root html; index index.php index.html index.htm; } # 在server模块中添加 location ~* .*\.(php|php5)?$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } # 检查nginx配置状态 /application/nginx/sbin/nginx -t # 重启nginx /application/nginx/sbin/nginx -s reload # 启动php-ftp程序 /application/php/sbin/php-fpm # 输入phpinfo echo -e ‘<?php \n phpinfo();\n ?>‘ > /application/nginx/html/index.php
5 mysql安装(二进制安装)
# 下载mysql
# 地址一:mysql官网上查找
https://dev.mysql.com/downloads/mirrors/
# 地址二:搜狐镜像
http://mirrors.sohu.com/mysql/
# 选择一个可用的版本 mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz
# 安装CentOS7系统软件需要解决libaio依赖 yum install -y libaio # 解压 tar xf /server/tools/mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz # 创建目录 mkdir -p /application/mysql5.6.34
# 移动目录文件 mv /server/tools/mysql-5.6.34-linux-glibc2.5-x86_64/* /application/mysql5.6.34/
# 创建软链接 ln -s /application/mysql5.6.34/ /application/mysql # 创建用户 useradd -s /sbin/nologin -M mysql -u 1015 # 修改权限 chown -R mysql.mysql /application/mysql # 初始化数据库 /application/mysql/scripts/mysql_install_db --basedir=/application/mysql --datadir=/application/mysql/data/ --user=mysql # 替换启动脚本中的内容 sed -i ‘s#/usr/local/mysql#/application/mysql#g‘ /application/mysql/bin/mysqld_safe /application/mysql/support-files/mysql.server # 复制启动脚本 \cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld # 复制配置文件 \cp /application/mysql/support-files/my-default.cnf /etc/my.cnf # 复制客户端 \cp /application/mysql/bin/mysql /etc/init.d/mysql # 创建软链接 ln -s /application/mysql/bin/mysql /bin/mysql # 启动服务 /etc/init.d/mysqld start # 链接测试 mysql
6 编写php连接mysql测试页面
#使用mysql函数连接 cat >/application/nginx/html/mysql.php <<‘EOF‘ <?php $link=mysql_connect("localhost","root","")or die(mysql_error()); var_dump($link); ?> EOF #使用mysqli对象连接 cat >/application/nginx/html/mysqli.php <<‘EOF‘ <?php $link=new mysqli("localhost","root","")or die(mysql_error()); var_dump($link); ?> EOF #$connection = new PDO("mysql:dbname=$db;host=$host", $username, $password); cat >/application/nginx/html/mysql_pdo.php <<‘EOF‘ <?php $link = new PDO("mysq:dbname=mysql;host=localhost", ‘root‘, ‘‘) or die(mysql_error()); var_dump($link); ?> EOF
7 安装 thinkphp-3.2.3
# 下载地址 wget http://www.thinkphp.cn/download/610.html -O thinkphp3.2.3_full.zip # 创建指定thinkphp目录 mkdir -p /application/nginx/html/thinkphp # 解压到指定目录 unzip thinkphp3.2.3_full.zip -d /application/nginx/html/thinkphp # 授权 chown -R www.www /application/nginx/html/ # thinkphp连接mysql.user数据库 //数据库配置信息 cat >/application/nginx/html/thinkphp/Application/Common/Conf/config.php <<‘EOF‘ <?php return array( //‘配置项‘=>‘配置值‘ ‘DB_TYPE‘ => ‘mysql‘, // 数据库类型 ‘DB_HOST‘ => ‘localhost‘, // 服务器地址 ‘DB_NAME‘ => ‘mysql‘, // 数据库名 ‘DB_USER‘ => ‘root‘, // 用户名 ‘DB_PWD‘ => ‘‘, // 密码 ‘DB_PORT‘ => 3306, // 端口 ‘DB_PREFIX‘ => ‘‘, // 数据库表前缀 ‘DB_CHARSET‘=> ‘utf8‘, // 字符集 ‘DB_DEBUG‘ => TRUE, // 数据库调试模式 开启后可以记录SQL日志 3.2.3新增 // 开启路由 ‘URL_ROUTER_ON‘ => true, ); ?> EOF # 查看连接数据库 此示例仅使用mysql方式连接数据库,读者可以使用其他方式连接 cat > /application/nginx/html/thinkphp/Application/Home/Controller/IndexController.class.php <<‘EOF‘ <?php namespace Home\Controller; use Think\Controller; class IndexController extends Controller { public function index(){ $User = D(‘User‘); $list = $User->getField(‘Host,User,password‘,":"); dump($list); } } EOF