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*
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章