• 在centos6中编译安装httpd-2.4/搭建LAMP


    首先确保centos6安装平台安装一下环境:

    #yum groupinstall "Development  Tools" "Server Platform Development" -y

    找到apr-1.5.0.tar.bz2进行解压

    #tar xf apr-1.5.0.tar.bz2

    #cd apr-1.5.0

    #./configure --prefix=/usr/local/apr  //为了避免编译安装把之前系统自带的给覆盖,这里改变了apr的安装目录

    # make && make install

    安装apr的组件apr-util

    #tar xf apr-util-1.5.3.tar.bz2 

    #cd apr-util-1.5.3

    #./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr  //--with这里是针对apr进行编译

    #make && make install

    #yum install  pcre-devel

    以上是安装httpd-2.4的前提

    # groupadd -r apache  //添加apache系统组

    # useradd -r -g apache apahce //添加系统用户apache

    #tar xf httpd-2.4.6.tar.bz2

    # ./configure --prefix=/usr/local/apache --sysconf=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork

     --prefix=/usr/local/apache  //指明安装路径,将来想卸载时,可以直接把目录删掉

    --sysconf=/etc/httpd24   //配置文件,系统rpm包自动安装的在/etc/httpd/目录下,为了避免冲突

    --enable-so  //支持动态模块加载机制

    --enable-rewrite  //支持URL重写机制

    --with-zlib //支持compress传输值,是一个压缩库

    --with-pcre  //pcre是perl扩展的正则表达式,一般利用URL重写时都会用到pcre,此处需要先安装pcre-devel  #yum install prcre-devel -y

    --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/     // 此处指明http安装依赖到的apr和apr-util,这里要指明apr安装的路径

    --enable-modules=most   //支持大多数常用的模块

    --enable-mpms-shared=all   //把所有支持mpm机制共享模块都编译进来,

    --with-mpm=prefork  //默认使用prefork

     # make && make install

    #rpm -qc httpd

    启动服务:

    1、 /usr/local/apache/bin/apachectl

    或者

    2、#vim /etc/profile.d/httpd.sh  

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

    #source /etc/profile.d/httpd.sh   //重读这个配置文件

    #echo $PATH  //可以看到/usr/local/apache/bin/apachectl在前面

    #which apachectl

    #apachectl start // 启动httpd

    #ss -tnl //查看80端口是否开启

    AH00557: httpd: apr_sockaddr_info_get() failed for bogon

    AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message

    开启apache时报上面的错误。这里需要把httpd.conf的#ServerName www.example.com:80前面的符号#去掉即

    /etc/rc.d/init.d/functions脚本文件

    为编译安装的httpd配置服务脚本  #cd /etc/rc.d/init.d/httpd文件  这个脚本好好读一读

    #cd /etc/rc.d/init.d/

    #cp httpd httpd24  //把系统自带的httpd服务脚本复制一份进行修改,当作编译安装的httpd24的服务脚本

    #vim httpd24

    apachectl=/usr/local/apache/bin/apachectl  //httpd的编译安装路径
    httpd=/usr/local/apache/bin/httpd  //httpd的默认程序
    prog=httpd
     pidfile=${PIDFILE-/var/run/httpd/httpd24.pid}
     lockfile=${LOCKFILE-/var/lock/subsys/httpd24}

    #chkconfig --add httpd24  //将httpd加进到服务列表中去

    #chkconfig --list httpd24

    #chkconfig httpd24 on  //设置在2345开机启动

    #service httpd start

    #ss -tnl  // 查看是否有80端口

     

    centos7的展示

    鉴于上面的配置需要改动以下地方:

    #vim /etc/httpd/conf.modules.d/00-mpm.conf

    1 # Select the MPM module which should be used by uncommenting exactly
    2 # one of the following LoadModule lines:
    3
    4 # prefork MPM: Implements a non-threaded, pre-forking web server
    5 # See: http://httpd.apache.org/docs/2.4/mod/prefork.html
    6 LoadModule mpm_prefork_module modules/mod_mpm_prefork.so  //是prefork模式
    7
    8 # worker MPM: Multi-Processing Module implementing a hybrid
    9 # multi-threaded multi-process web server
    10 # See: http://httpd.apache.org/docs/2.4/mod/worker.html
    11 #
    12 #LoadModule mpm_worker_module modules/mod_mpm_worker.so
    13
    14 # event MPM: A variant of the worker MPM with the goal of consuming
    15 # threads only for connections with active processing
    16 # See: http://httpd.apache.org/docs/2.4/mod/event.html
    17 #
    18 #LoadModule mpm_event_module modules/mod_mpm_event.so

     

    #vim /etc/httpd/conf/httpd.conf

    156 <RequireAll>
    157 Require not ip 192.168.108.163//这个要去掉
    158 Require all granted
    159 </RequireAll>

    下面开始搭建LAMP服务器

    1、首先安装php php-mysql(php链接MySQL的驱动) mariadb-server,

    #yum install php php-mysql mariadb 

    #rpm -ql mariadb-server

    /usr/lib/systemd/system/mariadb.service  //这个文件可以启动文件

    #systemctl start mariadb.service

    #ss -tnl   //查看3306端口是否启动

    #mysql  //使用MySQL客户端

    #rpm -ql php   //这里php作为apache的子模块

    /etc/httpd/conf.d/php.conf
    /etc/httpd/conf.modules.d/10-php.conf
    /usr/lib64/httpd/modules/libphp5.so
    /usr/share/httpd/icons/php.gif
    /var/lib/php/session

     php和apache结合有三种模式:

    httpd+php:

           modules  //把php作为apache的子模块进行运行,无需子进程

           cgi  //很少用,但用python和Perl代替php时,就用CGI

           fastcgi(也称为fpm方式)

    #systemctl start httpd.service  

    #httpd -M  // 查看是否安装了php模块

           cgi_module (shared)
           php5_module (shared)

    #cd /www/htdocs  //根据上面的配置修改

    #mv index.html index.php

    #vim index.php

        <?php

        phpinfo();

       ?>

    在浏览器中输入IP地址192.168.。。。。就可以看到php 的测试页面了

    下面测试php是否可以链接MySQL服务器?

    #vim index.php  修改此文档

    <?php
         $link=mysql_connect('127.0.0.1','mysql','');    //$link创建链接,条用mysql_connect()的函数,这是php-mysql驱动提供的调用,指明地址,对应的用户名是mysql,密码为空
         if ($link)  //用if做判断
              echo "success";
         else
              echo "fail";

       mysql_close();  //调用结束接口,关闭连接
     ?>

     再次刷新网页,显示:

    success

    #systemctl stop mariadb.service  //关闭mysql服务器,刷新网页,显示:

    fail

    这是LAMP组合就安装完毕

    在centos6中搭建LAMP服务

     #apachectl stop   //停掉之前编译安装的apache

    #ss -tnl  // 查看是否还有80端口

    #chkconfig httpd --list

    #service httpd start  //开启系统自动安装的httpd

    #yum install httpd php php-devel mysql-server -y

    #service httpd restart   //查看有没有 php5_module (shared)模块

    #service mysqld start   //开启mysql

    #mysql // 用mysql客户端链接或者

    #ss -tnl  // 查看3306端口

    #vim /var/www/html/index.php

     <?php
         $conn = mysqli_connect('127.0.0.1','root','');
            if ($conn)
                 echo "yes";
            else
                 echo "failure";

          mysqli_close();
         ?>

    在浏览器中输入ip就可以了

    # 关闭SELINUX
    chkconfig --level 12345 iptables off

    chkconfig --level 12345 ip6tables off

    service iptables stop

    service ip6tables stop

    查看SELinux状态:

    1、/usr/sbin/sestatus -v      ##如果SELinux status参数为enabled即为开启状态

    SELinux status:                 enabled

    2、getenforce                 ##也可以用这个命令检查

    关闭SELinux:

    1、临时关闭(不用重启机器):

    setenforce 0                  ##设置SELinux 成为permissive模式

                                  ##setenforce 1 设置SELinux 成为enforcing模式

    2、修改配置文件需要重启机器:

    修改/etc/selinux/config 文件

    将SELINUX=enforcing改为SELINUX=disabled

    基于LAMP创建wordpress


    在https://cn.wordpress.org/txt-download/网页中下载wordpress,

    #unzip wordpress-4.9.4-zh_CN.zip

    #cp wordpress /var/www/html中

    #cp wp-config-sample.php  wp-config.php  

    #vim wp-config.php  //修改如下

     define('DB_NAME', 'wpdb');

     /** MySQL数据库用户名 */
     define('DB_USER', 'wpuser');

     /** MySQL数据库密码 */
     define('DB_PASSWORD', 'wppasswd');

     

    #mysql  //添加数据块用户和密码

    MariaDB [(none)]> GRANT ALL ON wpdb.* TO 'wpuser'@'localhost' IDENTIFIED BY 'wpasswd';
    Query OK, 0 rows affected (0.00 sec)

    MariaDB [(none)]> GRANT ALL ON wpdb.* TO 'wpuser'@'127.0.0.1' IDENTIFIED BY 'wpasswd';
    Query OK, 0 rows affected (0.00 sec)

    MariaDB [(none)]> CREATE DATABASE wpdb;

    MariaDB [(none)]> FLUSH PRIVIEGES;

    这是在浏览器中输入IP/wordpress就可以了

    安装phpMyAdmin

    #unzip phpMyAdmin-4.8.1-all-languages.zip

    #cp -a phpMyAdmin-4.8.1-all-languages /www/htdocs  //因为之前把DocumentRoot的目录更改到/www/htdocs

    #cd /www/htdocs/phpMyAdmin-4.8.1-all-languages

    #cp config.sample.inc.php config.inc.php

    #tr -d 'a-zA-Z0-9' < /dev/urandom | hand -30 | md5sum

    #vim config.inc.php //添加随机密码

    $cfg['blowfish_secret'] = '3b52aefc4e2347d4b7648c3950ba412f'; 

    #ln -sv phpMyAdmin-4.8.1-all-languages phpMyAdmin  //为了访问方便

    在数据库中添加用户和密码

    在浏览器中输入IP/phpMyAdmin

    出现mbstring错误

    #yum remove php-common

    #yum install php-mbstring

     

  • 相关阅读:
    大家一起写mvc(二)
    大家一起写mvc(一)
    jquery读取XML 生成页面文件
    jquery点击区域显示或隐藏DIV,点击非该DIV的地方隐藏该DIV
    struts2 iterator排序
    解决JS传参中文乱码
    关于解决 请求被中止:无法建立SSL / TLS安全通道
    查看sqlserver被锁的表以及如何解锁
    查询sqlserver数据库视图、存储过程等包含特定的字符串
    C#中查询字符串中是否包含指定字符/串,使用IndexOf还是Contains?
  • 原文地址:https://www.cnblogs.com/hanshanxiaoheshang/p/9178402.html
Copyright © 2020-2023  润新知