zoukankan      html  css  js  c++  java
  • CentOS7.2 安装部署 LAMP(Linux+Apache+Mysql+Php)

    摘自:https://help.aliyun.com/document_detail/50774.html?spm=5176.doc44620.6.623.HqVrsz

    更新时间:2017-03-14 11:22:11

    简介

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

    部署及环境

    系统平台:CentOS 7.2

    Apache版本:2.4.23

    Mysql 版本:5.7.17

    Php版本:7.0.12

    安装前准备

    CentOS 7.2系统默认开启了防火墙,需关闭后外部才可访问本机的80、21等端口。

    关闭防火墙:

      systemctl stop firewalld.service

    关闭防火墙开机自启动:

      systemctl disable firewalld.service

    安装vim及unzip:

      yum install -y vim unzip

    编译安装apache准备

    编译安装apache前需要安装apr、apr-util和pcre软件包和相关依赖包。

    安装编译环境  

      yum install -y gcc gcc-c++ autoconf libtool

    安装apr
    1. cd /usr/local/src/
    2. wget http://oss.aliyuncs.com/aliyunecs/onekey/apache/apr-1.5.0.tar.gz
    3. tar zxvf apr-1.5.0.tar.gz
    4. cd apr-1.5.0
    5. ./configure --prefix=/usr/local/apr #安装目录
    6. make && make install
    安装apr-util
    1. cd /usr/local/src/
    2. wget http://oss.aliyuncs.com/aliyunecs/onekey/apache/apr-util-1.5.3.tar.gz
    3. tar zxvf apr-util-1.5.3.tar.gz
    4. cd apr-util-1.5.3
    5. ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr #安装目录 及apr安装路径
    6. make && make install
    安装pcre
    1. cd /usr/local/src/
    2. wget http://zy-res.oss-cn-hangzhou.aliyuncs.com/pcre/pcre-8.38.tar.gz
    3. tar zxvf pcre-8.38.tar.gz
    4. cd pcre-8.38
    5. ./configure --prefix=/usr/local/pcre #安装目录
    6. make && make install
    编译安装Apache
    1. cd /usr/local/src/
    2. wget http://zy-res.oss-cn-hangzhou.aliyuncs.com/apache/httpd-2.4.23.tar.gz
    3. tar zxvf httpd-2.4.23.tar.gz
    4. cd httpd-2.4.23
    5. ./configure
    6. --prefix=/usr/local/apache --sysconfdir=/etc/httpd #安装目录及配置文件所在目录
    7. --enable-so --enable-cgi --enable-rewrite
    8. --with-zlib --with-pcre=/usr/local/pcre #pcre所在目录
    9. --with-apr=/usr/local/apr #apr所在目录
    10. --with-apr-util=/usr/local/apr-util #apr-util所在目录
    11. --enable-mods-shared=most --enable-mpms-shared=all
    12. --with-mpm=event
    13. make && make install
    修改httpd.conf配置文件参数
    1. cd /etc/httpd/
    2. vim httpd.conf

    1.找到Directory参数,注释掉Require all denied添加Require all granted。

    2.找到ServerName参数,添加ServerName localhost:80 然后,按Esc键后输入:wq保存退出。

    设置PidFile路径

      vim /etc/httpd/httpd.conf

    在配置文件最后添加以下内容:

      PidFile "/var/run/httpd.pid"

    启动Apache服务并验证
    1. cd /usr/local/apache/bin/
    2. ./apachectl start
    3. netstat -tnlp #查看服务是否开启

    在本地浏览器中输入云服务器的公网IP地址验证,出现下图表示安装成功。

    设置开机自启

    在rc.local文件中添加/usr/local/apache/bin/apachectl start,然后输入:wq保存退出。

      vim /etc/rc.d/rc.local

    设置环境变量

      vi /root/.bash_profile

    在PATH=$PATH:$HOME/bin添加参数为:

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

    然后输入:wq保存退出,执行:

      source /root/.bash_profile

    编译安装MySQL前预准备

    首先检查系统中是否存在使用rpm安装的mysql或者mariadb,如果有需要先删除后再编译安装。

    1. rpm -qa | grep mysql #由下至上依次卸载
    2. rpm -qa | grep mariadb
    3. rpm -e xxx #一般使用此命令即可卸载成功
    4. rpm -e --nodeps xxx #卸载不成功时使用此命令强制卸载

    卸载完以后用 rpm -qa|grep mariadb 或者 rpm -qa|grep mysql 查看结果。

    安装mysql
    1. yum install -y libaio-* #安装依赖
    2. mkdir -p /usr/local/mysql
    3. cd /usr/local/src
    4. wget http://zy-res.oss-cn-hangzhou.aliyuncs.com/mysql/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
    5. tar -xzvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
    6. mv mysql-5.7.17-linux-glibc2.5-x86_64/* /usr/local/mysql/
    建立mysql组和用户,并将mysql用户添加到mysql组
    1. groupadd mysql
    2. useradd -g mysql -s /sbin/nologin mysql
    初始化mysql数据库

      /usr/local/mysql/bin/mysqld --initialize-insecure --datadir=/usr/local/mysql/data/ --user=mysql

    更改mysql安装目录的属主属组
    1. chown -R mysql:mysql /usr/local/mysql
    2. chown -R mysql:mysql /usr/local/mysql/data/
    3. chown -R mysql:mysql /usr/local/mysql
    设置开机自启
    1. cd /usr/local/mysql/support-files/
    2. cp mysql.server /etc/init.d/mysqld
    3. chmod +x /etc/init.d/mysqld # 添加执行权限
    4. vim /etc/rc.d/rc.local

    添加/etc/init.d/mysqld start到rc.local文件中,然后输入:wq保存退出。

    设置环境变量

      vi /root/.bash_profile

    在PATH=$PATH:$HOME/bin添加参数为:

      PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib

    然后输入:wq保存退出,输入:

      source /root/.bash_profile

    启动MySQL数据库

      /etc/init.d/mysqld start

    修改Mysql的root用户密码

    初始化后mysql为空密码可直接登录,为了保证安全性需要修改mysql的root用户密码。

      mysqladmin -u root password 'xxxx'

    测试登录MySQL数据库

      mysql -uroot -p密码 #-p和密码之间无空格

     

    编译安装php

    依赖安装:

    1. yum install php-mcrypt libmcrypt libmcrypt-devel libxml2-devel openssl-devel libcurl-devel libjpeg.x86_64 libpng.x86_64 freetype.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64 libjpeg-turbo-devel libmcrypt-devel mysql-devel -y
    2. wget http://zy-res.oss-cn-hangzhou.aliyuncs.com/php/php-7.0.12.tar.gz
    3. tar zxvf php-7.0.12.tar.gz
    4. cd php-7.0.12
    5. ./configure
    6. --prefix=/usr/local/php
    7. --with-mysql=mysqlnd --with-openssl
    8. --with-mysqli=mysqlnd
    9. --enable-mbstring
    10. --with-freetype-dir
    11. --with-jpeg-dir
    12. --with-png-dir
    13. --with-zlib --with-libxml-dir=/usr
    14. --enable-xml --enable-sockets
    15. --with-apxs2=/usr/local/apache/bin/apxs
    16. --with-mcrypt --with-config-file-path=/etc
    17. --with-config-file-scan-dir=/etc/php.d
    18. --enable-maintainer-zts
    19. --disable-fileinfo
    20. make && make install
    复制配置文件
    1. cd php-7.0.12
    2. cp php.ini-production /etc/php.ini
    编辑apache配置文件httpd.conf,以apache支持php
    1. vim /etc/httpd/httpd.conf

    在配置文件最后添加如下二行:

    1. AddType application/x-httpd-php .php
    2. AddType application/x-httpd-php-source .phps

    定位到 DirectoryIndex index.html

    修改为:

    1. DirectoryIndex index.php index.html
    重启apache服务
    1. /usr/local/apache/bin/apachectl restart
    测试是否能够正常解析PHP
    1. cd /usr/local/apache/htdocs/
    2. vim index.php #添加如下内容
    3. <?php
    4. phpinfo();
    5. ?>

    访问云服务器的公网IP/index.php,出现如下页面表示解析成功。

    安装phpmyadmin

    1. mkdir -p /usr/local/apache/htdocs/phpmyadmin
    2. cd /usr/local/src/
    3. wget http://oss.aliyuncs.com/aliyunecs/onekey/phpMyAdmin-4.1.8-all-languages.zip
    4. unzip phpMyAdmin-4.1.8-all-languages.zip
    5. mv phpMyAdmin-4.1.8-all-languages/* /usr/local/apache/htdocs/phpmyadmin

    访问ip/phpmyadmin即可访问到phpmyadmin登录页面,输入mysql的用户名以及密码即可登录。

     

     

     

     

  • 相关阅读:
    HDU6808 Go Running(未解决问题
    K
    E
    D
    B
    I
    HDU 2255 奔小康赚大钱 (KM算法模板)
    hdu 1150 Machine Schedule(二分图模板题)
    ACM-ICPC 2018 焦作赛区网络预赛G Give Candies(欧拉降幂)
    ACM-ICPC 2018 焦作赛区网络预赛 L:Poor God Water(杜教BM)
  • 原文地址:https://www.cnblogs.com/Beyron/p/6561335.html
Copyright © 2011-2022 走看看