zoukankan      html  css  js  c++  java
  • centos7.0 安装 apache+mysql+php

    一、防火墙配置:centos7.0防火墙默认使用的是firewall,需要改为iptables


    (1)关闭firewall:
    [root@localhost] systemctl stop firewall.service #停止firewall服务,服务命令用systemctl而不是centos6.5及以下版本中使用的service
    [root@localhost] systemctl disable firewall.service #禁止firewall开机启动


    (2)安装iptables防火墙
    [root@localhost] yum install iptables-services
    [root@localhost] vi /etc/systemconfig/iptables #编辑防火墙配置文件

    *********************************************************************

    备注:有可能在 /etc/sysconfig/iptables
    备注:如果/etc/systemconfig/iptables无法找到,可以在命令行输入任意一
    条防火墙规则即可。例如:

    [root@localhost] iptables -P OUTPUT ACCEPT
    *********************************************************************

    (3) 新增防火墙规则
    在/etc/systemconfig/iptables中的 [commit]前加入 如下规则:


    (4)退出保存 重启 & 设置开机启动
    [root@localhost] systemctl restart iptables.service
    [root@localhost] systemctl enable iptables.service

    =============================================================================================

    第二步、关闭Selinux 【备注: 阿里云服务器不需要进行此操作】

    打开 /etc/selinux/config 配置文件
    [root@localhost] vi /etc/selinux/config

    进行如下操作:
    #SELINUX=enforcing #注释掉
    #SELINUXTYPE=targeted #注释掉
    SELINUX=disabled #增加
    :wq! #保存退出

    [root@localhost] setenforce 0 #使配置立即生效
    ==============================================================================================

    第三步 安装apache

    直接yum 即可

    [root@localhost] yum install httpd

    具体apache相关操作:
    systemctl start httpd.service
    systemctl restart httpd.service
    systemctl stop httpd.service
    systemctl enable httpd.service
    systemctl disable httpd.service
    =============================================================================================
    安装nginx

    下载对应当前系统版本的nginx包(package)
    # wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
    2.建立nginx的yum仓库
    # rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm
    3.下载并安装nginx
    # yum install nginx
    4.启动nginx服务
    systemctl start nginx.service
    5.配置
    默认的配置文件在 /etc/nginx 路径下,使用该配置已经可以正确地运行nginx;如需要自定义,修改其下的 nginx.conf 等文件即可。

    =============================================================================================

    第四步,安装mysql5.6

    进入mysql官方网站,选择"Downloads"菜单,然后依次选择 "commnunity"->"mysql yum repository".
    然后在界面上选择对应的版本,下载到本地。

    在本地通过 yum localinstall 直接执行

    [root@localhost] yum localinstall mysql57-community-release-el7-8.noarch.rpm
    [root@localhost] yum install mysql-community-server

    或者直接通过rpm进行安装

    [root@localhost] vi

    修改mysql root默认密码
    打开mysql配置文件
    [root@localhost] vi /etc/my.cnf

    在[mysqld]节点下 加入 skip-grant-tables=1,重启mysql服务

    [root@localhost] systemctl restart mysqld.service
    [root@localhost] mysql -u root

    mysql > update mysql.user set authentication_string=password('new password'),password_expired='N',
    password_last_changed=now() where user='root';
    mysql > flush privileges;
    mysql > exit

    退出 mysql,编辑 /etc/my.cnf 文件,删除 skip-grant-tables=1 的内容

    最后重启mysql服务

    【引用文章:http://www.mamicode.com/info-detail-1247383.html】

    =================================================================================================

    第五步、安装php

    centos7.2默认的PHP版本为5.4

    (1)查看当前PHP版本

    [root@localhost] # php -v

    (2)执行下面的命令升级软件仓库
    [root@localhost] # rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
    [root@localhost] # rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

    (3)执行下面的命令删除原来的PHP
    [root@localhost] # yum remove php-common

    (4)安装php5.6版本以及相应的PHP扩展
    [root@localhost] #

    相关服务:
    systemctl restart mysqld.service
    systemctl restart php-fpm.service

    ===================================================================================================

    六、安装ImageMagick
    ImageMagick是一套软件系列,主要用于图片的创建、编辑以及转换等

    [root@localhost] # yum install ImageMagick
    [root@localhost] # yum install ImageMagick-devel
    [root@localhost] # yum install php-devel #注:如果是通过rpm安装的php5.6版本,该命令应该为 yum install php56w-devel

    升级安装gcc
    [root@localhost] # yum install gcc gcc-c++

    最后安装php imagick扩展
    [root@localhost] # yum install imagick

    安装成功后,找到php扩展配置目录
    [root@localhost] # cd /etc/php.d/
    [root@localhost] # vi imagick.ini #通过vi命令新增imagick扩展文件,

    在imagick.ini中加入: extension=imagick.so

    完成后,重新php-fpm 和 nginx
    [root@localhost] # systemctl restart php-fpm.service
    [root@localhost] # systemctl restart nginx.service

    可以通过运行 phpinfo() 或者 php -m 查看是否安装成功

    ******************************************************************************
    升级imageMagick到7.0最新版本

    注:由于yum install 安装的版本为6.8的版本,6.9以下版本都存在致命漏洞,因此要升级到最新的7.0以上版本才可以。

    具体版本。进入imageMagick官方主页,下载最新的二进制安装包(rpm依赖包容易出错,建议用二进制包)

    [root@localhost] # wget http://www.imagemagick.org/download/ImageMagick-7.0.3-10.tar.gz
    [root@localhost] # tar -zxvf ImageMagick-7.0.3-10.tar.gz
    [root@localhost] # cd ImageMagick-7.0.3-10
    [root@localhost] # ./configure --prefix=/usr/local/ImageMagick
    [root@localhost] # make && make install

    ※ 同步更新php imagick扩展 (由于我们安装在/usr/local/ImageMagick目录下,所以进行pecl install imagick命令进行安装时,会提示找不到*.so文件,因此建议也执行二进制包进行安装)
    在http://pecl.php.net/package/imagick 网站上下载最新的imagick扩展包。

    [root@localhost] # wget http://pecl.php.net/get/imagick-3.4.3RC1.tgz
    [root@localhost] # tar -zxvf imagick-3.4.3RC1.tgz
    [root@localhost] # cd imagick-3.4.3RC1

    [root@localhost] # phpize
    [root@localhost] # ./configure --with-php-config=/usr/bin/php-config --with-imagick=/usr/local/ImageMagick
    [root@localhost] # make && make install

    到此,完成升级

    //查看版本
    [root@localhost] # convert --version


    ******************************************************************************


    ====================================================================================================

    七、安装redis,以及phpredis扩展

    (1) 在redis官网下载最新版本的redis,目前最近版本 redis.3.2.5
    [root@localhost] # wget http://download.redis.io/releases/redis-3.2.5.tar.gz

    (2) 将文件移动到 /usr/local/目录下
    [root@localhost] # mv redis3.2.5.tar.gz /usr/local/redis

    (3) 进入目录,运行 make test 或者 runtest 检查安装环境是否支持

    [root@localhost] # ./runtest
    如果出现 You need tcl 8.5 or newer in order to run the Redis test 错误,则需要安装最新的tcl8.5
    [root@localhost] # wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
    [root@localhost] # tar -zxvf tcl8.6.1-src.tar.gz -C /usr/local/
    [root@localhost] # cd /usr/local/tcl8.6.1/unix/
    [root@localhost] # ./configure
    [root@localhost] # make
    [root@localhost] # make install

    (4)回到redis目录,再运行 runtest 或者 make test没有错误的话,就可以运营 make
    [root@localhost] # make

    (5)安装phpredis扩展,下载地址:https://github.com/phpredis/phpredis
    第一种:通过git工具下载
    [root@localhost] # git clone https://github.com/phpredis/phpredis.git

    第二种: 直接下载压缩文件
    [root@localhost] # wget https://github.com/nicolasff/phpredis/archive/master.zip
    [root@localhost] # unzip master.zip

    如果系统没有安装git或者zip的话,要先安装
    [root@localhost] # yum install -y git
    [root@localhost] # yum install zip unzip

    (6) 进入phpredis目录,运行phpize,【如果没找到phpize,可以通过 whereis phpize 查找phpize安装目录】
    [root@localhost] # phpize
    [root@localhost] # whereis php-config
    php-config: /usr/bin/php-config /usr/share/man/man1/php-config.1.gz

    [root@localhost] # ./configure --with-php-config=/usr/bin/php-config
    [root@localhost] # make
    [root@localhost] # make install

    (7) 成功之后,进入php扩展目录,新增redis.ini扩展信息
    [root@localhost] # cd /etc/php.d/
    [root@localhost] # vi redis.ini

    extension=redis.so

    [root@localhost] # systemctl restart php-fpm.service
    [root@localhost] # systemctl restart nginx.service
    ===========================================================================================================

    Linux 64位安装nginx时出现以下错误:
    configure: error: no acceptable C compiler found in $PATH
    说明需要安装gcc,linux操作系统是新安装的,没有安装gcc库,安装命令如下:
    yum install gcc
    安装完gcc库即可

    ===========================================================================================================

    1、MySQL Error caused by sql_mode=only_full_group_by
    mysql5.7会有这个问题

    解决方案:

    在my.cnf中 [mysqld]节点下加入

    sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

    ===========================================================================================================

  • 相关阅读:
    肩部肌肉劳损zt
    大屏幕手机上网页字体显示很小的问题
    SWT的Display
    The connection to adb is down, and a severe error has occured.
    [ZT]使用tmpfs缓存文件提高性能
    Mutex
    javascript阻塞加载问题【转】
    IE参考
    2台电脑网线对接注意的事项
    重建索引
  • 原文地址:https://www.cnblogs.com/lianruihong/p/7655857.html
Copyright © 2011-2022 走看看