设为首页 收藏本站
查看: 1249|回复: 1

[经验分享] Centos6.6用yum快速安装LA(N)MP

[复制链接]

尚未签到

发表于 2019-2-16 13:48:52 | 显示全部楼层 |阅读模式
  本文主要介绍在CentOS6.6下用yum快速搭建LAMP或LNMP环境

  基本流程:

    1.安装apche或nginx
    2.安装mysql
    3.安装php
    4.测试环境
  流程一:安装apache或nginx

  

  1)关闭SELINUX

  修改配置文件,重启服务后永久生效。
  sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
  命令行设置立即生效。
  setenforce 0
网易官方源
centos6.x
cd /etc/yum.repos.d/
mv CentOS-Base.repo CentOS-Base.repo.$(date +%F)
wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
yum clean all
yum makecache  更多国内知名yum源可参考:http://blog.运维网.com/13707680/2104644

  2)安装Apache:

  yum -y install httpd
  yum -y install httpd-manual mod_ssl mod_perl mod_auth_mysql
  /etc/init.d/httpd start
  netstat -tnlp|grep 80
  安装nginx:
  Centos6系统库中默认是没有nginx的rpm包的,所以我们需要先更新下rpm依赖库
  1)使用yum安装nginx,安装nginx库

  rpm -Uvh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
  2)使用下面命令安装nginx
  yum -y install nginx
  [root@localhost ~]# nginx -v

  nginx version: nginx/1.14.0
  3)启动nginx
  /etc/init.d/nginx start 或 service nginx start
  4 ) 防火墙允许通过80端口
  vim /etc/sysconfig/iptables
  -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
  /etc/init.d/iptables restart
  流程二:安装mysql
  1)安装Mysql,先更新yum源。yum源下载地址,根据自己需要的版本选择相应的源
  https://dev.mysql.com/downloads/repo/yum/
  2)这里版本是6.x系列的,所以选择linux 6 下载
  wget https://repo.mysql.com//mysql57-community-release-el6-11.noarch.rpm
  3)安装mysql的yum源
  rpm -Uvh mysql57-community-release-el6-11.noarch.rpm  或 yum -y localinstall mysql57-community-release-el6-11.noarch.rpm
  4)查看mysql源是否成功
  [root@localhost yum.repos.d]# ls /etc/yum.repos.d/|grep mysql
  mysql57-community-release-el6-11.noarch.rpm
  mysql-community.repo
  mysql-community-source.repo
  5)安装mysql

  yum -y install mysql-community-server
  [root@localhost ~]# mysql -V
  mysql  Ver 14.14 Distrib 5.7.22, for Linux (x86_64) using  EditLine wrapper
  6)开启mysql,并更改默认密码
  /etc/init.d/mysqld start
  netstat -tnlp |grep 3306
  chkconfig mysqld on
  [root@localhost yum.repos.d]# grep 'temporary password' /var/log/mysqld.log
  2018-05-10T22:59:11.434638Z 1 [Note] A temporary password is generated for root@localhost: OScMFRu&j75Q
  mysql -uroot -p"OScMFRu&j75Q"
  ALTER USER 'root'@'localhost' IDENTIFIED BY 'ywxi123';
  mysql -uroot -p"ywxi123"
  7)防火墙允许通过3306端口
  -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
  service iptables restart
  流程三:安装php
  

  1)更新yum源

  rpm -Uvh http://ftp.iij.ad.jp/pub/linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
  rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
  2)安装PHP

  yum -y install --enablerepo=remi --enablerepo=remi-php56 php php-bcmath php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-gd php-xml php-memcache php-redis php-fpm php-mysql php-common php-mssql
  3)配置php.ini文件,关闭php信息头
  sed 's#expose_php = On#expose_php = Off#g' /etc/php.ini -i
  [root@localhost html]# php -v
  PHP 5.6.36 (cli) (built: Apr 25 2018 10:11:47)
  4)启动php,并开机自启
  /etc/init.d/php-fpm start
  chkconfig php-fpm on
  流程四:环境测试
  

  1)LNMP环境测试准备
  编辑/etc/nginx/conf.d/default.conf,在所支持的主页面格式中添加php格式的主页,类似如下:
  [root@localhost conf.d]# cat default.conf
  server {
  listen       80;
  server_name  localhost;
  #charset koi8-r;
  #access_log  /var/log/nginx/host.access.log  main;
  location / {
  root   /usr/share/nginx/html;
  index index.php index.html index.htm;
  }
  #error_page  404              /404.html;
  # redirect server error pages to the static page /50x.html
  #
  error_page   500 502 503 504  /50x.html;
  location = /50x.html {
  root   /usr/share/nginx/html;
  }
  # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  #
  #location ~ \.php$ {
  #    proxy_pass   http://127.0.0.1;
  #}
  # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  #
   location ~ \.php$ {
          root           /usr/share/nginx/html;
          fastcgi_pass   127.0.0.1:9000;
          fastcgi_index  index.php;
          fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html/$fastcgi_script_name;
          include        fastcgi_params;
      }
  # deny access to .htaccess files, if Apache's document root
  # concurs with nginx's one
  #
  #location ~ /\.ht {
  #    deny  all;
  #}
  }
  [root@localhost html]# cat /usr/share/nginx/html/index.php
  
  chown -R nginx.nginx /usr/share/nginx/html/
  http://192.168.1.22/index.php 访问到如下页面证明LNMP环境搭建成功

  

  2)LAMP环境测试准备
  /etc/init.d/nginx stop
  /etc/init.d/httpd start
  [root@localhost html]# cat /var/www/html/index.php

  
  chown -R apache.apache /var/www/html
  http://192.168.1.22/index.php 访问到如下页面证明LAMP环境搭建成功






运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-673237-1-1.html 上篇帖子: ThinkServer RS260安装CentOS操作实录 下篇帖子: Centos7系统安装docker18.03
累计签到:42 天
连续签到:15 天
发表于 2019-2-16 22:04:26 | 显示全部楼层
好文章,收藏了

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表