How To Configure Apache Virtual Hosts In Ubuntu 18.04 LTS(more about install mysql php)

一、install apache and configure Virtual Hosts
1.

sudo apt update
sudo apt upgrade

sudo apt-get install apache2
检查是否running sudo systemctl status apache2

run the following command to allow incoming HTTP and HTTPS

sudo ufw allow in "Apache Full"

or If you don’t want to allow https traffic, but only http (80) traffic, run:

sudo ufw app info "Apache"

安装完访问localhost ,如果出现下图则成功
在这里插入图片描述
2. 在 /var/www/html 下创建文件,例如 index.php

sudo chown -R ronghuang:domain\ users index.php

接下来,使用命令设置对Apache根目录的读取权限: sudo chmod -R 755 /var/www/html/

3.Copy the default virtual host file called 000-default.conf contents to the new virtual host files like below.

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/one.conf

修改配置:sudo vi /etc/apache2/sites-available/one.conf,只要修改第二个ServerName和DocumentRoot就可以,其他只是名字。
在这里插入图片描述
After making the necessary changes, disable the default virtual host config file i.e 000.default.conf, and enable all newly created virtual host config files as shown below.

sudo a2dissite 000-default.conf
sudo a2ensite one.conf

4.Virtual hosts

sudo vi /etc/hosts
sudo systemctl restart apache2

在这里插入图片描述
二、Install MySQL
1.sudo apt install mysql-server
检查是否running sudo systemctl status mysql
2.设置密码 sudo mysql_secure_installation , 这里别选择yes,选了后它会验证密码强度,选其他任意键设置自己想要的密码,再设置完密码后, just type y and hit ENTER. This will remove anonymous user, disallow root user login remotely and remove test database.
3. CHANGE AUTHENTICATION METHOD FOR MYSQL ROOT USER

sudo mysql -uroot -proot
SELECT user,authentication_string,plugin,host FROM mysql.user;

As you see, mysql root user uses auth_socket plugin for authentication.
在这里插入图片描述

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';  //换成你的密码
FLUSH PRIVILEGES;

在这里插入图片描述
三、Install PHP

sudo apt install php libapache2-mod-php php-mysql
sudo vi /var/www/html/info.php
<?php
phpinfo();
?>
sudo systemctl restart apache2
sudo vi /etc/apache2/mods-enabled/dir.conf  //修改优先访问的后缀

Move the “index.php” file to first. Once you made the changes, your dir.conf file will look like below.

<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>
sudo systemctl restart apache2

INSTALL PHP MODULES

sudo apt-get install php*
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值