zoukankan      html  css  js  c++  java
  • 138

    LAMP环境搭建与配置

        

    安装:

    一定要去官网下载更完整,无修改,无病毒,无后门

    安装MYSQL

    解压 tar -zxvf mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz

    移动位置 mv mysql-5.6.43-linux-glibc2.12-x86_64 /usr/local/mysql

    创建用户 useradd -s /sbin/nologin mysql

    创建存放数据库文件的目录 mkdir -p /data/mysql

    更改权限 chown -R mysql:mysql /data/mysql

    安装 ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql

    所遇问题:
    1.-bash: ./scripts/mysql_install_db: /usr/bin/perl: bad interpreter: No such file or directory
    yum -y install perl-Module-Install
    2.Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: libaio.so.1:
    cannot open shared object file: No such file or directory
    yum -y install libaio.so libaio-devel

    配置

    复制配置文件 cp support-files/my-default.cnf /etc/my.cnf

    修改文件 vim /etc/my.conf

    [mysqld]

    # Remove leading # and set to the amount of RAM for the most important data
    # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
    # innodb_buffer_pool_size = 128M

    # Remove leading # to turn on a very important data integrity option: logging
    # changes to the binary log between backups.
    # log_bin

    # These are commonly set, remove the # and set as required.
    basedir = /usr/local/mysql
    datadir = /data/mysql
    # port = .....
    # server_id = .....
    # socket = .....

    # Remove leading # to set options mainly useful for reporting servers.
    # The server defaults are faster for transactions and fast SELECTs.
    # Adjust sizes as needed, experiment to find the optimal values.
    # join_buffer_size = 128M
    # sort_buffer_size = 2M
    # read_rnd_buffer_size = 2M

    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

    复制启动脚本修改属性  cp support -files/mysql.server /etc/init.d/mysqld

    修改脚本的权限 chmod 755 /etc/init.d/mysqld

    修改脚本 vim /etc/init.d/mysqld

    找到datadir 改为 datadir = /data/mysql

    把 mysqld 服务添加到系统服务列表中 chkconfig --add mysqld
    设置开机自启 chkconfig mysqld on
    启动 mysqld 服务 service mysqld start
    Starting MySQL.Logging to '/data/mysql/tangtao.err'.
    . SUCCESS!
    验证
    ps aux |grep mysqld
    netstat -lnp|grep 3306

     安装apache

    httpd是依赖apr和apr-util,不安装就无法工作

    安装apr

    解压tar -zxvf apr-1.6.5.tar.gz

    编译 ./configure --prefix=/usr/local/apr

     安装 make && make install

    安装apr-util

    解压tar-zxvf apr-util-1.6.5.tar.gz
    编译./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
    安装 make && make install

    安装httpd

    解压 tar -zxvf httpd-2.4.39.tar.gz
    编译 ./configure--with-apr = /usr/local/apr --with-apr-util=/usr/local/apr util--enable-so --enable-mods-shared=most

    错误问题 configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
    解 yum -y install pcre-devel pcre

    安装 make && make instal

    安装php

    解压tar -zxvf php-5.6.36.tar.gz
    编译./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif
    错误-解决
    configure: error: xml2-config not found. Please check your libxml2 installation.
    yum -y install libxml2 libxml2-devel
    configure: error: Cannot find OpenSSL's <evp.h>
    yum -y install openssl openssl-devel
    configure: error: Please reinstall the BZip2 distribution
    yum -y install bzip2 bzip2-devel
    configure: error: jpeglib.h not found
    yum -y install libjpeg libjpeg-devel
    configure: error: png.h not found.
    yum -y install libpng-devel libpng
    configure: error: freetype-config not found.
    yum -y install freetype freetype-devel
    configure: error: mcrypt.h not found. Please reinstall libmcrypt.
    yum -y install epel-release
    yum -y install libmcrypt-devel
    安装make && make install

    复制配置文件cp php.ini-production /usr/local/php/etc/php.ini配置httpd支持php

    vim /usr/local/apache2/conf/httpd.conf

    搜索ServerName

    将这行的#号去掉ServerName www.example.com:80

    将<Directory />

    AllowOverride none

    Require all denied

    </Directory>

    改为<Directory />

    AllowOverride none

    Require all granted

    </Directory>

    在AddType application/x-gzip .gz .tgz下
    添加这一行AddType application/x-httpd-php .php

    将<IfModule dir_module>
    DirectoryIndex index.html index.html
    </IfModule>

    改为<IfModule dir_module>
    DirectoryIndex index.html index.php
    </IfModule>

    测试LAMP是否成功

    启动httpd之前先检测配置文件是否正确

     使用curl命令测试

     测试是否正常解析PHP

     编写一个脚本

    vim /usr/local/apache2/htodcs/1.php

    <?php

      echo localhost"php解析正常"

    >

    curl localhost/1.php

    php解析正常

    配置默认虚拟主机

    vim /usr/local/apache2/conf/extart/httpd-vhosts.conf

    <VirtualHost *:80>                   --限制虚拟主机80端口
    ServerAdmin webmaster@dummy-hiost.examp.com   
    DocumentRoot "/data/wwwroot/147.com"         --根目录
    ServerName 147.com                  --网站的域名
    ServerAlias www.147.com                   --第二个域名 可以在后面加多个 用空格分开
    ErrorLog "logs/147.com-error_log"           --错误日志
    CustomLog "logs/147.com-access_log" common       --访问日志
    </VirtualHost>

    <VirtualHost *:80>
    DocumentRoot "/data/wwwroot/www.258.com"
    ServerName www.258.com
    <Directory /data/wwwroot/www.258.com>
    </VirtualHost>

    测试/usr/local/apache2.4/bin/apachectl -t 

    Syntax OK

    重新加载 /usr/local/apache2.4/bin/apachectl -graceful

    创建网站根目录并创建 index.html文件

    mkdir -p /data/wwwroot/147.com

    mkdir -p /data/wwwroot/www.258.com

    echo "147.com" >/data/wwwroot/147.com/index.html  网站默认的主页就是index.html

    echo "258.com" >/data/wwwroot/www.258.com/index.html

    测试/usr/local/apache2.4/bin/apachectl -t 

    Syntax OK

    重新加载 /usr/local/apache2.4/bin/apachectl -graceful

    curl -x127.0.0.1:80+网址 会去访问

     用户认证

    vim /usr/local/apache2/conf/extart/httpd-vhosts.conf

    配置为:

    <VirtualHost *:80>
    DocumentRoot "/data/wwwroot/www.258.com"
    ServerName www.258.com
    <Directory /data/wwwroot/www.258.com>    --指定的目录
    AllowOverride AuthConfig        --打开认证的开关
    AuthName "258.com user auth"       --自定义的名字
    AuthType Basic              --认证的类型
    AuthUserFile /data/.htpasswd        --指定密码文件位置
    require valid-user              --指定需要认证的用户为全部可用用户
    </Directory>
    </VirtualHost>

    创建密码 /usr/local/apache2.4/bin/htpasswd -cm /data/.htpasswd

    htpasswd为创建用户的工具 -c是创建 -m加密方式为MD5

    测试 重新加载

    完成后去真实电脑修改hosts文件 C :WindowsSystem32driversetchosts

    浏览器访问www.258.com

    配置域名跳转

    <VirtualHost *:80>
    DocumentRoot "/data/wwwroot/www.258.com"
    ServerName www.258.com
    ServerAlias 258.com
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www.258.com$
    RewriteRule ^/(.*)$ http://www.258.com/$1 [R=301,L]
    </IfModule>
    </VirtualHost>

    测试重新加载文件
    查看是否有加载 rewrite 模块/usr/local/apache2/bin/apachectl -M |grep rewrite
    没有输出需要配置rewrite 模块 在vim /usr/local/apache2/conf/httpd.conf      --搜索rewrite
    #LoadModule rewrite_module modules/mod_rewrite.so去掉#
    再次检测 有输出 rewrite_module (shared)
    curl测试 
    curl -x127.0.0.1:80 -I 258.com
    HTTP/1.1 301 Moved Permanently
    Date: Tue, 24 Dec 2019 02:17:50 GMT
    Server: Apache/2.4.39 (Unix) PHP/5.6.36
    Location: http://www.258.com/
    Content-Type: text/html; charset=iso-8859-1
    配置访问日志
    vim /usr/local/apache2/conf/extra/httpd-vhosts.conf 
     
    <VirtualHost *:80>
    DocumentRoot "/data/wwwroot/www.258.com"
    ServerName www.258.com
    ServerAlias 258.com
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www.258.com$
    RewriteRule ^/(.*)$ http://www.258.com/$1 [R=301,L]
    </IfModule>
    CustomLog "logs/www.258.com-access_log" combined
    </VirtualHost>
     测试重新加载
    查看   tail /usr/local/apache2/logs/www.258.com-access_log

    <VirtualHost *:80>
    DocumentRoot "/data/wwwroot/www.258.com"
    ServerName www.258.com
    <Directory /data/wwwroot/www.258.com>
    </VirtualHost>
    /usr/local/apache2.4/bin/apachectl -t
    <VirtualHost *:80>
    DocumentRoot "/data/wwwroot/www.258.com"
    ServerName www.258.com
    ServerAlias 258.com
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www.258.com$
    RewriteRule ^/(.*)$ http://www.258.com/$1 [R=301,L]
    </IfModule>
    SetEnvIf Request_URI ".*.gif$" img
    SetEnvIf Request_URI ".*.jpg$" img
    SetEnvIf Request_URI ".*.png$" img
    SetEnvIf Request_URI ".*.bmp$" img
    SetEnvIf Request_URI ".swf$" img
    SetEnvIf Request_URI ".*.js$" img
    SetEnvIf Request_URI ".*.css$" img
    CustomLog "|/usr/local/apache2/bin/rotatelogs -l logs/www.258.com-access_%Y%m%d.log 86400" combined env=!image-request
    </VirtualHost>

    测试重新加载
    创建 jpg与txt测试
    touch /data/wwwroot/www.258.com/1.jpg
    touch /data/wwwroot/www.258.com/1.txt
    curl -x127.0.0.1:80 -I www.258.com/1.jpg
    curl -x127.0.0.1:80 -I www.258.com/1.txt
    tail /usr/local/apache2/logs/www.258.com-access_20191224.log
    127.0.0.1 - - [24/Dec/2019:09:13:33 +0800] "HEAD HTTP://258.com/ HTTP/1.1" 301 - "-" "curl/7.29.0"
    127.0.0.1 - - [24/Dec/2019:09:07:44 +0800] "GET HTTP://www.258.com/ 1.php HTTP/1.1" 200  "-" "curl/7.29.0
    配置防盗链
     
     
     
     
     
  • 相关阅读:
    Mix and Build(简单DP)
    Is It A Tree?(并查集)
    Paths on a Grid(简单组合数学)
    Code(组合数学)
    Round Numbers(组合数学)
    Inviting Friends(二分+背包)
    Communication System(dp)
    Human Gene Functions
    Pearls
    敌兵布阵(线段树HDU 1166)
  • 原文地址:https://www.cnblogs.com/Job123/p/12088009.html
Copyright © 2011-2022 走看看