Install Apache using Ubuntu’s package manager, apt
:
sudo apt update
sudo apt install apache2
Install MySQL using Ubuntu’s package manager, apt
:
sudo apt install mysql-server
sudo mysql_secure_installation
Answer Y
for yes, or anything else to continue without enabling.
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Press y|Y for Yes, any other key for No:
If you answer “yes”, you’ll be asked to select a level of password validation. Keep in mind that if you enter 2
for the strongest level, you will receive errors when attempting to set any password which does not contain numbers, upper and lowercase letters, and special characters, or which is based on common dictionary words.
There are three levels of password validation policy:
LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1
Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
Log in to the MySQL console by typing:
sudo mysql
To exit the MySQL console, type:
mysql> exit
Install PHP using Ubuntu’s package manager, apt
:
sudo apt install php libapache2-mod-php php-mysql
Create the directory for your_domain as follows:
sudo mkdir /var/www/your_domain
sudo chown -R $USER:$USER /var/www/your_domain
sudo nano /etc/apache2/sites-available/your_domain.conf
/etc/apache2/sites-available/your_domain.conf
<VirtualHost *:80>
ServerName your_domain
ServerAlias www.your_domain
ServerAdmin webmaster@localhost
DocumentRoot /var/www/your_domain
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
a2ensite
to enable the new virtual host:
sudo a2ensite your_domain
a2dissite
to disable the new virtual host:
sudo a2dissite your_domain
Enable module Mod_ssl
:
a2enmod ssl
Enable module Mod_rewrite
:
a2enmod rewrite
To make sure your configuration file doesn’t contain syntax errors, run:
sudo apache2ctl configtest
Reload Apache so these changes take effect:
sudo systemctl reload apache2
Testing PHP processing on your Web Server:
nano /var/www/your_domain/info.php
/var/www/your_domain/info.php
<b><?php</b>
phpinfo();
To test this script, go to your web browser
http://server_domain_or_IP/info.php
Enter MySQL DB:
mysql -u root -p
Change root password:
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD ('newpassword');
Create new DATABASE:
mysql> CREATE DATABASE dbname;
Delete DATABASE:
mysql> DROP DATABASE dbname;
Show DATABASE:
mysql> SHOW DATABASES;
Export DATABASE:
mysqldump -h localhost -u root -p dbname >/root/dbname.sql
Import DATABASE:
mysql -h localhost -u root -p dbname </root/dbname.sql
Import to OTHER DATABASE:
mysqldump -h localhost -u root -p --routines --triggers dbname >/root/dbname.sql
mysql -h localhost -u root -p -A -D dbname </root/dbname.sql
Create new USER:
mysql> CREATE USER 'username'@'localhost' IDENTIFIED BY 'PASS?WORD99';
Rename USER:
mysql> RENAME USER 'username'@'localhost' TO 'username'@'8.8.8.8';
Show all USERS:
mysql> SELECT CONCAT (QUOTE(user),'@',QUOTE(host)) UserAccount FROM mysql.user;
Show all USERS authentication methods:
mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;
Grant privileges to USER on dbname:
mysql> GRANT ALL PRIVILEGES ON dbname . * TO 'username'@'localhost';
Activate privileges:
mysql> FLUSH PRIVILEGES;
Show users privileges on database:
mysql> select user from mysql.db where db='dbname';
Show users grants on database:
mysql> SHOW GRANTS FOR 'root'@'localhost';