配置web服务器
apt install apache2 libapache-mod-php5 apache2-utils
如果启动Apache时出现如下报错:
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
解决方法之一:
在/etc/apache2/conf-enabled新建local-ServerName.conf文件,写入
ServerName localhost
sudo a2enconf local-ServerName
接着建立网站目录:
mkdir /var/www/WebsiteName
之后新建虚拟主机:
vim /etc/apache2/sites-available/WebsiteName.conf
虚拟机内容:
ServerAdmin test@qq.com#站长邮箱,网站出错时显示
ServerName test.com#站点名称
DocumentRoot /var/www/Test#站点根目录
Options FollowSymLinks#禁止访问www目录以外的目录
AllowOverride None#AllowOverride针对.htaccess文件,不允许其指令,Ubuntu中AllowOverride 默认为None
Options FollowSymLinks Multiviews#允许列目录(Indexes),符号链接Multiviews:内容协商的多重视图
AllowOverride None
Order allow,deny
allow from all
LogLevel warn#安全报警级别
ErrorLog ${APACHE_LOG_DIR}/error-HAD.log
CustomLog ${APACHE_LOG_DIR}/access-HAD.log combined
ServerSignature off#关闭服务器的出错生成的页脚信息如:Apache/2.4.7 (Ubuntu) Server at 172.16.183.148 Port 80
Alias /doc/ "/usr/share/doc/"#将/usr/share/doc/映射成网站的/doc/
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128#限制只允许本机访问或Allow from 10.0.0.0/8限制内网访问
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 10
安装php与数据库
apt install php5-mysql mariadb-server php5-mcrypt
mysql_insatll_db 创建数据库的目录结构
mysql_secure_installation 数据库安全配置
Enter current password for root (enter for none): //输入root安全密码按"n"
Change the root password? [y/n] n
Remove anonymouus users? [y/n] y //匿名用户 Y
Disall root login remtely? [y/n] y //root远程登陆 Y
Remove test datebase and access to it? [y/n] n 测试数据库 N,如果生产坏境的话需要散掉,如果渗透坏境的话可以留着
Reload privilage tables now? [y/n] y 权限 Y
完成配置
测试:
/var/www/html/$ sudo vi 1.php
然后可以访问http://localhost/1.php测试。
之后,把需要测试的环境放到/var/www/html即可. 或者更改虚拟主机配置文件均可.