138

LAMP environment to build and configure

    

 

installation:

Must go to the official website to download more complete, without modification, no virus, no back door

Install MYSQL

Extracting tar -zxvf mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz

Movement position mv mysql-5.6.43-linux-glibc2.12-x86_64 / usr / local / mysql

Create a user useradd -s / sbin / nologin mysql \

Create a database file to hold the directory mkdir -p / data / mysql

Change the permissions chown -R mysql: mysql / data / mysql

Installation ./scripts/mysql_install_db --user = mysql --datadir = / data / mysql

Problems encountered:
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

Configuration

Copy the configuration file cp support-files / my-default.cnf /etc/my.cnf

Modify the file 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

Copy the startup script to modify the properties cp support -files / mysql.server /etc/init.d/mysqld

Modify the script permissions chmod 755 /etc/init.d/mysqld

Modify the script vim /etc/init.d/mysqld

Datadir to find datadir = / data / mysql

Mysqld service system to add to the list of services chkconfig --add mysqld
Set boot from Kai chkconfig mysqld on
Start mysqld service mysqld start service
Starting MySQL.Logging to '/data/mysql/tangtao.err'.
. SUCCESS!
verification
ps aux | grep mysqld
netstat -lnp | grep 3306

 

 Install apache

httpd is dependent apr and apr-util, do not install will not work

Installation apr

Extracting tar -zxvf apr-1.6.5.tar.gz

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

 安装 make && make install

Installation apr-util

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

Install httpd

Extracting 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

Install php

Extracting 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
Error - solved
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

Copy the configuration file cp php.ini-production /usr/local/php/etc/php.ini httpd configuration support php

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

Search ServerName

These lines remove the # ServerName www.example.com:80

The <Directory />

AllowOverride none

Require all denied

</Directory>

To <Directory />

AllowOverride none

Require all granted

</Directory>

In AddType application / x-gzip .gz .tgz
add this line AddType application / x-httpd-php .php

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

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

If successful test LAMP

Before starting the first test httpd configuration file is correct

 

 Use the curl command to test

 

 Whether the tests are normal parse PHP

 Write a script

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

<?php

  echo localhost "php parse normal"

>

curl localhost/1.php

php parse normal

Configuring the default virtual host

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

<VirtualHost *: 80> - 80 port restrictions Web Hosting
ServerAdmin [email protected]   
DocumentRoot "/data/wwwroot/147.com" - the root directory
ServerName 147.com - website domain
ServerAlias www. 147.com - the second domain may be separated by a space behind the increase plurality
ErrorLog "logs / 147.com-error_log" - error log
CustomLog "logs / 147.com-access_log" common - access log
</ 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 :Windows\System32\drivers\etc\hosts

浏览器访问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
配置防盗链
 
 
 
 
 

Guess you like

Origin www.cnblogs.com/Job123/p/12088009.html
138
138
138