138
Posted job123
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
配置
复制配置文件 cp support-files/my-default.cnf /etc/my.cnf
修改文件 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
复制启动脚本修改属性 cp support -files/mysql.server /etc/init.d/mysqld
修改脚本 vim /etc/init.d/mysqld
找到datadir 改为 datadir = /data/mysql
安装apache
httpd是依赖apr和apr-util,不安装就无法工作
安装apr
解压tar -zxvf apr-1.6.5.tar.gz
编译 ./configure --prefix=/usr/local/apr
安装 make && make install
安装apr-util
安装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
安装php
复制配置文件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是否成功
使用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
重新加载 /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 :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>
<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>