Đầu tiên phải cập nhật hệ thống trước.
sudo apt update && sudo apt upgrade
sudo apt install tasksel
sudo tasksel install lamp-server
Vậy là xong rồi đó. Truy cập http://localhost/ xem kết quả.
sudo a2enmod rewrite
sudo systemctl restart apache2
Bước này chủ yếu là để đặt mật khẩu cho tài khoản root.
sudo mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
Cài đặt plugin kiểm duyệt mật khẩu:
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: N
Mình dùng trên local thôi nên chọn No cho nó nhanh, cài trên server thì chọn Yes, nó sẽ ra các tùy chọn như bên dưới:
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
Đặt mật khẩu cho tài khoản root.
Please set the password for root here.
New password:
Re-enter new password:
Estimated strength of the password: 100
Xác nhận lưu mật khẩu.
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
Một số tùy chỉnh bảo mật khác.
By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Success.
Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
Success.
By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Success.
All done!
Gỡ bỏ plugin VALIDATE PASSWORD nếu ở trên lỡ chọn Yes:
mysql -h localhost -u root -p
mysql> uninstall plugin validate_password;
mysql> exit;
sudo systemctl restart mysql
Đặt mật khẩu tài khoản root nếu đang trống:
sudo mysql -u root
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YOURPASSWORDHERE';
mysql> exit;
Dùng để tạo tên miền ảo, và đưa thư mục www
ra ngoài home
, tránh các vấn đề do phân quyền.
cd /usr/local/bin
sudo wget -O virtualhost https://github.com/lelinhtinh/virtualhost/raw/master/virtualhost.sh
sudo chmod +x virtualhost
Cách dùng:
sudo virtualhost [create | delete] [domain]
Adminer là trình quản lý database, chức năng tương tự phpMyAdmin nhưng nhẹ và nhanh hơn nhiều.
sudo virtualhost create adminer.test
cd ~/www/adminer
wget -O index.php https://www.adminer.org/latest-mysql-en.php
Truy cập http://adminer.test/ để sử dụng.