一、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*