部署LAMP

  • A+
所属分类:建站
高性能企业级服务器首台5折

LAMPLinux+Apache+MySQL/MariaDB+Perl/PHP/Python,是一组常用来搭建动态网站或者服务器的开源软件。它们本身都是各自独立的程序,但是因为常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台。

部署方式

您可以使用三种方式在云服务器ECS上部署LAMP:

  • 镜像部署:方便快捷,适合不太了解Linux命令的用户。
  • 一键安装包部署:适合对Linux命令有基本了解的用户。
  • 手动部署:可以满足用户个性化部署需求,适合对Linux命令有基本了解的用户。

本文介绍如何在云服务器ECS上手动部署LAMP。

软件版本说明

本文操作的镜像和软件版本说明如下 :

  • 操作系统:CentOS 7.2 64位
  • Apache:2.4.23
  • MySQL:5.7.17
  • PHP:7.0.12

前提条件

在部署之前,需要确认:

准备工作

设置防火墙

CentOS 7.2系统默认开启防火墙firewalld。您可以关闭firewalld放行80、22等端口。

说明:您也可以参考 firewalld 官方文档 在防火墙里放行这些端口。

  1. 运行命令关闭防火墙。
    1. 1
      <span class="pln">systemctl stop firewalld</span><span class="pun">.</span><span class="pln">service</span>
  2. 运行命令关闭防火墙开机自启动。
    1. 1
      <span class="pln">systemctl disable firewalld</span><span class="pun">.</span><span class="pln">service</span>

安装vim和unzip

下载软件用于编辑和解压缩文件。运行命令:

  1. 1
    <span class="pln">yum install </span><span class="pun">-</span><span class="pln">y vim unzip</span>

操作步骤

按以下步骤部署LAMP。

步骤1. 编译安装Apache

  1. 运行命令安装相关依赖包。
    1. 1
      <span class="pln">yum install </span><span class="pun">-</span><span class="pln">y gcc gcc</span><span class="pun">-</span><span class="pln">c</span><span class="pun">++</span><span class="pln"> autoconf libtool</span>
  2. 依次运行以下命令安装apr。
    1. 1
      <span class="pln">cd </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">src</span><span class="pun">/</span>
    2. 1
      <span class="pln">wget http</span><span class="pun">:</span><span class="com">//oss.aliyuncs.com/aliyunecs/onekey/apache/apr-1.5.0.tar.gz</span>
    3. 1
      <span class="pln">tar zxvf apr</span><span class="pun">-</span><span class="lit">1.5</span><span class="pun">.</span><span class="lit">0.tar</span><span class="pun">.</span><span class="pln">gz</span>
    4. 1
      <span class="pln">cd apr</span><span class="pun">-</span><span class="lit">1.5</span><span class="pun">.</span><span class="lit">0</span>
    5. 1
      <span class="pun">./</span><span class="pln">configure </span><span class="pun">--</span><span class="pln">prefix</span><span class="pun">=</span><span class="str">/usr/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">apr</span>
    6. 1
      <span class="pln">make </span><span class="pun">&amp;&amp;</span><span class="pln"> make install</span>
  3. 依次运行以下命令安装apr-util。
    1. 1
      <span class="pln">cd </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">src</span><span class="pun">/</span>
    2. 1
      <span class="pln">wget http</span><span class="pun">:</span><span class="com">//oss.aliyuncs.com/aliyunecs/onekey/apache/apr-util-1.5.3.tar.gz</span>
    3. 1
      <span class="pln">tar zxvf apr</span><span class="pun">-</span><span class="pln">util</span><span class="pun">-</span><span class="lit">1.5</span><span class="pun">.</span><span class="lit">3.tar</span><span class="pun">.</span><span class="pln">gz</span>
    4. 1
      <span class="pln">cd apr</span><span class="pun">-</span><span class="pln">util</span><span class="pun">-</span><span class="lit">1.5</span><span class="pun">.</span><span class="lit">3</span>
    5. 1
      <span class="pun">./</span><span class="pln">configure </span><span class="pun">--</span><span class="pln">prefix</span><span class="pun">=</span><span class="str">/usr/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">apr</span><span class="pun">-</span><span class="pln">util </span><span class="pun">--</span><span class="kwd">with</span><span class="pun">-</span><span class="pln">apr</span><span class="pun">=</span><span class="str">/usr/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">apr</span>
    6. 1
      <span class="pln">make </span><span class="pun">&amp;&amp;</span><span class="pln"> make install</span>
  4. 依次运行以下命令安装pcre。
    1. 1
      <span class="pln">cd </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">src</span><span class="pun">/</span>
    2. 1
      <span class="pln">wget http</span><span class="pun">:</span><span class="com">//zy-res.oss-cn-hangzhou.aliyuncs.com/pcre/pcre-8.38.tar.gz </span>
    3. 1
      <span class="pln">tar zxvf pcre</span><span class="pun">-</span><span class="lit">8.38</span><span class="pun">.</span><span class="pln">tar</span><span class="pun">.</span><span class="pln">gz</span>
    4. 1
      <span class="pln">cd pcre</span><span class="pun">-</span><span class="lit">8.38</span>
    5. 1
      <span class="pun">./</span><span class="pln">configure </span><span class="pun">--</span><span class="pln">prefix</span><span class="pun">=</span><span class="str">/usr/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">pcre</span>
    6. 1
      <span class="pln">make </span><span class="pun">&amp;&amp;</span><span class="pln"> make install</span>
  5. 依次运行以下命令编译安装Apache。
    1. 1
      <span class="pln">cd </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">src</span><span class="pun">/</span>
    2. 1
      <span class="pln">wget http</span><span class="pun">:</span><span class="com">//zy-res.oss-cn-hangzhou.aliyuncs.com/apache/httpd-2.4.23.tar.gz </span>
    3. 1
      <span class="pln">tar zxvf httpd</span><span class="pun">-</span><span class="lit">2.4</span><span class="pun">.</span><span class="lit">23.tar</span><span class="pun">.</span><span class="pln">gz</span>
    4. 1
      <span class="pln">cd httpd</span><span class="pun">-</span><span class="lit">2.4</span><span class="pun">.</span><span class="lit">23</span>
    5. 1
      <span class="pun">./</span><span class="pln">configure \</span>
    6. 1
      <span class="pun">--</span><span class="pln">prefix</span><span class="pun">=</span><span class="str">/usr/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">apache </span><span class="pun">--</span><span class="pln">sysconfdir</span><span class="pun">=</span><span class="str">/etc/</span><span class="pln">httpd \</span>
    7. 1
      <span class="pun">--</span><span class="pln">enable</span><span class="pun">-</span><span class="pln">so </span><span class="pun">--</span><span class="pln">enable</span><span class="pun">-</span><span class="pln">cgi </span><span class="pun">--</span><span class="pln">enable</span><span class="pun">-</span><span class="pln">rewrite \</span>
    8. 1
      <span class="pun">--</span><span class="kwd">with</span><span class="pun">-</span><span class="pln">zlib </span><span class="pun">--</span><span class="kwd">with</span><span class="pun">-</span><span class="pln">pcre</span><span class="pun">=</span><span class="str">/usr/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">pcre \</span>
    9. 1
      <span class="pun">--</span><span class="kwd">with</span><span class="pun">-</span><span class="pln">apr</span><span class="pun">=</span><span class="str">/usr/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">apr \</span>
    10. 1
      <span class="pun">--</span><span class="kwd">with</span><span class="pun">-</span><span class="pln">apr</span><span class="pun">-</span><span class="pln">util</span><span class="pun">=</span><span class="str">/usr/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">apr</span><span class="pun">-</span><span class="pln">util \</span>
    11. 1
      <span class="pun">--</span><span class="pln">enable</span><span class="pun">-</span><span class="pln">mods</span><span class="pun">-</span><span class="pln">shared</span><span class="pun">=</span><span class="pln">most </span><span class="pun">--</span><span class="pln">enable</span><span class="pun">-</span><span class="pln">mpms</span><span class="pun">-</span><span class="pln">shared</span><span class="pun">=</span><span class="pln">all \</span>
    12. 1
      <span class="pun">--</span><span class="kwd">with</span><span class="pun">-</span><span class="pln">mpm</span><span class="pun">=</span><span class="kwd">event</span>
    13. 1
      <span class="pln">make </span><span class="pun">&amp;&amp;</span><span class="pln"> make install</span>
  6. 修改httpd.conf配置文件参数:
    1. 运行 
      1
      cd /etc/httpd/

       切换到/etc/httpd/目录。

    2. 运行 
      1
      vim httpd.conf

       打开httpd.conf文件,按 

      1
      i

       键进入编辑模式。

    3. 找到 
      1
      Directory

       参数,注释掉 

      1
      Require all denied

      ,并添加 

      1
      Require all granted


      修改Directory参数

    4. 找到 
      1
      ServerName

       参数,添加 

      1
      ServerName localhost:80


      修改ServerName参数

    5. 设置 
      1
      PidFile

       路径:在文件最后添加 

      1
      PidFile "/var/run/httpd.pid"

    6. 按 
      1
      Esc

       键退出编辑模式,输入 

      1
      :wq

       保存并关闭 httpd.conf 文件。

  7. 依次执行以下命令启动Apache服务并验证。
    1. 1
      <span class="pln">cd </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">apache</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span>
    2. 1
      <span class="pun">./</span><span class="pln">apachectl start</span>
    3. 1
      <span class="pln">netstat </span><span class="pun">-</span><span class="pln">tnlp                             </span><span class="com">#查看服务是否开启</span>

    如果返回以下结果,说明Apache服务已经成功启动。

    Apache服务正常开启
    在本地机器的浏览器中输入ECS实例公网IP地址,如果出现如图所示信息,说明Apache服务安装成功。

    Apache 安装成功

  8. 设置开机自启动。
    1. 运行 
      1
      vim /etc/rc.d/rc.local

       打开rc.local文件,按 

      1
      i

       进入编辑模式。

    2. 添加 
      1
      /usr/local/apache/bin/apachectl start


      编辑rc.local文件

    3. 按 
      1
      Esc

       键退出编辑模式,输入 

      1
      :wq

       保存并关闭rc.local文件。

  9. 设置环境变量。
    1. 运行 
      1
      vi /root/.bash_profile

       打开文件,按 

      1
      i

       进入编辑模式。

    2. 将 
      1
      PATH=$PATH:$HOME/bin

       修改为 

      1
      PATH=$PATH:$HOME/bin:/usr/local/apache/bin

    3. 按 
      1
      Esc

       键退出编辑模式,输入 

      1
      :wq

       保存并关闭文件。

    4. 运行 
      1
      source /root/.bash_profile

       重新执行文件。

步骤2. 编译安装MySQL

  1. 依次执行以下命令检查系统中是否存在使用rpm安装的MySQL或者MariaDB。
    1. 1
      <span class="pln">rpm </span><span class="pun">-</span><span class="pln">qa </span><span class="pun">|</span><span class="pln"> grep mysql</span>
    2. 1
      <span class="pln">rpm </span><span class="pun">-</span><span class="pln">qa </span><span class="pun">|</span><span class="pln"> grep mariadb</span>

    如果已经安装,则运行以下任一个命令删除。

    1. 1
      <span class="pln">rpm </span><span class="pun">-</span><span class="pln">e </span><span class="pun">软件名</span>    <span class="com">#注意:这里的软件名必须包含软件的版本信息,如rpm -e mariadb-libs-5.5.52-1.el7.x86_64。一般使用此命令即可卸载成功。</span>
    2. 1
      <span class="pln">rpm </span><span class="pun">-</span><span class="pln">e </span><span class="pun">--</span><span class="pln">nodeps </span><span class="pun">软件名</span>   <span class="com">#卸载不成功时使用此命令强制卸载</span>

    卸载后,再用 

    1
    rpm -qa|grep mariadb

     或者 

    1
    rpm -qa|grep mysql

     查看结果。

  2. 依次运行以下命令安装 MySQL。
    1. 1
      <span class="pln">yum install </span><span class="pun">-</span><span class="pln">y libaio</span><span class="pun">-*</span>                         <span class="com">#安装依赖</span>
    2. 1
      <span class="pln">mkdir </span><span class="pun">-</span><span class="pln">p </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">mysql</span>
    3. 1
      <span class="pln">cd </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">src</span>
    4. 1
      <span class="pln">wget http</span><span class="pun">:</span><span class="com">//zy-res.oss-cn-hangzhou.aliyuncs.com/mysql/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz </span>
    5. 1
      <span class="pln">tar </span><span class="pun">-</span><span class="pln">xzvf mysql</span><span class="pun">-</span><span class="lit">5.7</span><span class="pun">.</span><span class="lit">17</span><span class="pun">-</span><span class="pln">linux</span><span class="pun">-</span><span class="pln">glibc2</span><span class="pun">.</span><span class="lit">5</span><span class="pun">-</span><span class="pln">x86_64</span><span class="pun">.</span><span class="pln">tar</span><span class="pun">.</span><span class="pln">gz</span>
    6. 1
      <span class="pln">mv mysql</span><span class="pun">-</span><span class="lit">5.7</span><span class="pun">.</span><span class="lit">17</span><span class="pun">-</span><span class="pln">linux</span><span class="pun">-</span><span class="pln">glibc2</span><span class="pun">.</span><span class="lit">5</span><span class="pun">-</span><span class="pln">x86_64</span><span class="com">/* /usr/local/mysql/</span>
  3. 依次运行以下命令建立mysql组和用户,并将mysql用户添加到mysql组。
    1. 1
      <span class="pln">groupadd mysql</span>
    2. 1
      <span class="pln">useradd </span><span class="pun">-</span><span class="pln">g mysql </span><span class="pun">-</span><span class="pln">s </span><span class="pun">/</span><span class="pln">sbin</span><span class="pun">/</span><span class="pln">nologin mysql</span>
  4. 运行命令初始化MySQL数据库
    1. 1
      <span class="str">/usr/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">mysql</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">mysqld </span><span class="pun">--</span><span class="pln">initialize</span><span class="pun">-</span><span class="pln">insecure </span><span class="pun">--</span><span class="pln">datadir</span><span class="pun">=</span><span class="str">/usr/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">mysql</span><span class="pun">/</span><span class="pln">data</span><span class="pun">/</span> <span class="pun">--</span><span class="pln">user</span><span class="pun">=</span><span class="pln">mysql</span>
  5. 更改MySQL安装目录的属性:
    1
    chown -R mysql:mysql /usr/local/mysql

  6. 依次运行以下命令设置开机自启动。
    1. 1
      <span class="pln">cd </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">mysql</span><span class="pun">/</span><span class="pln">support</span><span class="pun">-</span><span class="pln">files</span><span class="pun">/</span>
    2. 1
      <span class="pln">cp mysql</span><span class="pun">.</span><span class="pln">server  </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">init</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">mysqld</span>
    3. 1
      <span class="pln">chmod </span><span class="pun">+</span><span class="pln">x </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">init</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">mysqld             </span><span class="com"># 添加执行权限</span>
    4. 1
      <span class="pln">vim </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">rc</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">rc</span><span class="pun">.</span><span class="kwd">local</span>

    在 rc.local 文件中添加 

    1
    /etc/init.d/mysqld start

  7. 设置环境变量。
    1. 运行 
      1
      vi /root/.bash_profile

       打开文件,按 

      1
      i

       进入编辑模式。

    2. 将 
      1
      PATH=$PATH:$HOME/bin:/usr/local/apache/bin

       修改为 

      1
      PATH=$PATH:$HOME/bin:/usr/local/apache/bin:/usr/local/mysql/bin:/usr/local/mysql/bin

      说明:此处是在编译安装 Apache的环境变量的基础上再进行修改。

    3. 按 
      1
      Esc

       键退出编辑模式,输入 

      1
      :wq

       保存并关闭文件。

    4. 运行 
      1
      source /root/.bash_profile

       重新执行文件。

  8. 启动 MySQL 数据库
    1. 1
      <span class="str">/etc/</span><span class="pln">init</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">mysqld start</span>

    出现如下截图所示信息,表示MySQL启动成功。

    MySQL启动成功

  9. 修改MySQL的root用户密码:初始化后MySQL为空密码可直接登录,为了保证安全性需要修改MySQL的root用户密码。运行以下命令,并按界面提示设置密码。
    1. 1
      <span class="pln">mysqladmin </span><span class="pun">-</span><span class="pln">u root password</span>
  10. 测试登录MySQL数据库。
    1. 1
      <span class="pln">mysql </span><span class="pun">-</span><span class="pln">uroot </span><span class="pun">-</span><span class="pln">p                           </span><span class="com">#-p和密码之间无空格</span>

    成功登录MySQL数据库

  11. 运行 
    1
    \q

     退出MySQL。

步骤3. 编译安装 PHP

  1. 依次运行以下命令安装依赖。
    1. 1
      <span class="pln"> yum install php</span><span class="pun">-</span><span class="pln">mcrypt libmcrypt libmcrypt</span><span class="pun">-</span><span class="pln">devel  libxml2</span><span class="pun">-</span><span class="pln">devel  openssl</span><span class="pun">-</span><span class="pln">devel  libcurl</span><span class="pun">-</span><span class="pln">devel libjpeg</span><span class="pun">.</span><span class="pln">x86_64 libpng</span><span class="pun">.</span><span class="pln">x86_64 freetype</span><span class="pun">.</span><span class="pln">x86_64 libjpeg</span><span class="pun">-</span><span class="pln">devel</span><span class="pun">.</span><span class="pln">x86_64 libpng</span><span class="pun">-</span><span class="pln">devel</span><span class="pun">.</span><span class="pln">x86_64 freetype</span><span class="pun">-</span><span class="pln">devel</span><span class="pun">.</span><span class="pln">x86_64  libjpeg</span><span class="pun">-</span><span class="pln">turbo</span><span class="pun">-</span><span class="pln">devel   libmcrypt</span><span class="pun">-</span><span class="pln">devel   mysql</span><span class="pun">-</span><span class="pln">devel  </span><span class="pun">-</span><span class="pln">y</span>
    2. 1
      <span class="pln"> wget http</span><span class="pun">:</span><span class="com">//zy-res.oss-cn-hangzhou.aliyuncs.com/php/php-7.0.12.tar.gz</span>
    3. 1
      <span class="pln"> tar zxvf php</span><span class="pun">-</span><span class="lit">7.0</span><span class="pun">.</span><span class="lit">12.tar</span><span class="pun">.</span><span class="pln">gz</span>
    4. 1
      <span class="pln"> cd php</span><span class="pun">-</span><span class="lit">7.0</span><span class="pun">.</span><span class="lit">12</span>
    5. 1
       <span class="pun">./</span><span class="pln">configure \</span>
    6. 1
       <span class="pun">--</span><span class="pln">prefix</span><span class="pun">=</span><span class="str">/usr/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">php \</span>
    7. 1
       <span class="pun">--</span><span class="pln">enable</span><span class="pun">-</span><span class="pln">mysqlnd \</span>
    8. 1
       <span class="pun">--</span><span class="kwd">with</span><span class="pun">-</span><span class="pln">mysqli</span><span class="pun">=</span><span class="pln">mysqlnd </span><span class="pun">--</span><span class="kwd">with</span><span class="pun">-</span><span class="pln">openssl \</span>
    9. 1
       <span class="pun">--</span><span class="kwd">with</span><span class="pun">-</span><span class="pln">pdo</span><span class="pun">-</span><span class="pln">mysql</span><span class="pun">=</span><span class="pln">mysqlnd \</span>
    10. 1
       <span class="pun">--</span><span class="pln">enable</span><span class="pun">-</span><span class="pln">mbstring \</span>
    11. 1
       <span class="pun">--</span><span class="kwd">with</span><span class="pun">-</span><span class="pln">freetype</span><span class="pun">-</span><span class="pln">dir \</span>
    12. 1
       <span class="pun">--</span><span class="kwd">with</span><span class="pun">-</span><span class="pln">jpeg</span><span class="pun">-</span><span class="pln">dir \</span>
    13. 1
       <span class="pun">--</span><span class="kwd">with</span><span class="pun">-</span><span class="pln">png</span><span class="pun">-</span><span class="pln">dir \</span>
    14. 1
       <span class="pun">--</span><span class="kwd">with</span><span class="pun">-</span><span class="pln">zlib </span><span class="pun">--</span><span class="kwd">with</span><span class="pun">-</span><span class="pln">libxml</span><span class="pun">-</span><span class="pln">dir</span><span class="pun">=/</span><span class="pln">usr \</span>
    15. 1
       <span class="pun">--</span><span class="pln">enable</span><span class="pun">-</span><span class="pln">xml  </span><span class="pun">--</span><span class="pln">enable</span><span class="pun">-</span><span class="pln">sockets \</span>
    16. 1
       <span class="pun">--</span><span class="kwd">with</span><span class="pun">-</span><span class="pln">apxs2</span><span class="pun">=</span><span class="str">/usr/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">apache</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">apxs \</span>
    17. 1
       <span class="pun">--</span><span class="kwd">with</span><span class="pun">-</span><span class="pln">mcrypt  </span><span class="pun">--</span><span class="kwd">with</span><span class="pun">-</span><span class="pln">config</span><span class="pun">-</span><span class="pln">file</span><span class="pun">-</span><span class="pln">path</span><span class="pun">=/</span><span class="pln">etc \</span>
    18. 1
       <span class="pun">--</span><span class="kwd">with</span><span class="pun">-</span><span class="pln">config</span><span class="pun">-</span><span class="pln">file</span><span class="pun">-</span><span class="pln">scan</span><span class="pun">-</span><span class="pln">dir</span><span class="pun">=</span><span class="str">/etc/</span><span class="pln">php</span><span class="pun">.</span><span class="pln">d \</span>
    19. 1
       <span class="pun">--</span><span class="pln">enable</span><span class="pun">-</span><span class="pln">maintainer</span><span class="pun">-</span><span class="pln">zts \</span>
    20. 1
       <span class="pun">--</span><span class="pln">disable</span><span class="pun">-</span><span class="pln">fileinfo</span>
    21. 1
      <span class="pln"> make </span><span class="pun">&amp;&amp;</span><span class="pln"> make install</span>
  2. 运行命令复制配置文件。
    1. 1
      <span class="pln">cp php</span><span class="pun">.</span><span class="pln">ini</span><span class="pun">-</span><span class="pln">production </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">php</span><span class="pun">.</span><span class="pln">ini</span>
  3. 编辑Apache配置文件 httpd.conf,以Apache支持PHP。
    1. 运行 
      1
      vim /etc/httpd/httpd.conf

       打开文件,按 

      1
      i

       进入编辑模式。

    2. 在配置文件最后添加如下二行代码。
      1. 1
        <span class="typ">AddType</span><span class="pln"> application</span><span class="pun">/</span><span class="pln">x</span><span class="pun">-</span><span class="pln">httpd</span><span class="pun">-</span><span class="pln">php  </span><span class="pun">.</span><span class="pln">php </span>
      2. 1
        <span class="typ">AddType</span><span class="pln"> application</span><span class="pun">/</span><span class="pln">x</span><span class="pun">-</span><span class="pln">httpd</span><span class="pun">-</span><span class="pln">php</span><span class="pun">-</span><span class="pln">source  </span><span class="pun">.</span><span class="pln">phps</span>
    3. 定位到 
      1
      DirectoryIndex index.html

      ,修改为 

      1
      DirectoryIndex index.php index.html

      说明:如果文件中没有 

      1
      DirectoryIndex index.html

      ,则添加上述代码。

    4. 按 
      1
      Esc

       键退出编辑模式,输入 

      1
      :wq

       保存并关闭文件。

  4. 重启Apache服务:
    1. 1
      <span class="str">/usr/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">apache</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">apachectl restart</span>
  5. 测试是否能够正常解析PHP。
    1. 依次运行以下命令,找开index.php文件。
      1. 1
        <span class="pln">cd  </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">apache</span><span class="pun">/</span><span class="pln">htdocs</span><span class="pun">/</span>
      2. 1
        <span class="pln">vim index</span><span class="pun">.</span><span class="pln">php</span>
    2. 按 
      1
      i

       键进入编辑模式,并添加以下内容。

      1. 1
        <span class="pun">&lt;?</span><span class="pln">php</span>
      2. 1
        <span class="pln">phpinfo</span><span class="pun">();</span>
      3. 1
        <span class="pun">?&gt;</span>
    3. 按 
      1
      Esc

       键退出编辑模式,并输入 

      1
      :wq

       保存并关闭文件。

    4. 重启Apache服务:
      1. 1
        <span class="str">/usr/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">apache</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">apachectl restart</span>
    5. 在本地机器的浏览器里输入 
      1
      http://实例公网 IP/index.php


      如果出现以下页面表示PHP解析成功。PHP解析成功

步骤4. 安装phpMyAdmin

依次运行以下命令安装phpMyAdmin。

  1. 1
    <span class="pln">mkdir </span><span class="pun">-</span><span class="pln">p </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">apache</span><span class="pun">/</span><span class="pln">htdocs</span><span class="pun">/</span><span class="pln">phpmyadmin</span>
  2. 1
    <span class="pln">cd </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">src</span><span class="pun">/</span>
  3. 1
    <span class="pln">wget http</span><span class="pun">:</span><span class="com">//oss.aliyuncs.com/aliyunecs/onekey/phpMyAdmin-4.1.8-all-languages.zip</span>
  4. 1
    <span class="pln">unzip phpMyAdmin</span><span class="pun">-</span><span class="lit">4.1</span><span class="pun">.</span><span class="lit">8</span><span class="pun">-</span><span class="pln">all</span><span class="pun">-</span><span class="pln">languages</span><span class="pun">.</span><span class="pln">zip</span>
  5. 1
    <span class="pln">mv phpMyAdmin</span><span class="pun">-</span><span class="lit">4.1</span><span class="pun">.</span><span class="lit">8</span><span class="pun">-</span><span class="pln">all</span><span class="pun">-</span><span class="pln">languages</span><span class="com">/*  /usr/local/apache/htdocs/phpmyadmin</span>

在本地机器浏览器输入 

1
http://实例公网 IP/phpmyadmin

 访问phpMyAdmin登录页面。如果出现以下页面,说明phpMyAdmin安装成功。输入MySQL的用户名和密码即可登录。
phpMyAdmin 安装成功

相关链接

您可通过 云中沙箱平台 上体验本文档描述的操作。

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: