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
Configuration
Copy the configuration file cp support-files / my-default.cnf /etc/my.cnf
Modify the file vim /etc/my.conf
# 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 vim /etc/init.d/mysqld
Datadir to find datadir = / data / mysql
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
Install httpd
错误问题 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
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
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
重新加载 /usr/local/apache2.4/bin/apachectl -graceful
创建网站根目录并创建 index.html文件
mkdir -p /data/wwwroot/147.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>
<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>