Thumbnail
Category: Server

Kinh nghiệm VPS Linux

Date: August 13, 2022
40 views

1. Cài web server

Cài web server: https://vietnix.vn/cai-dat-apache-web-server-tren-centos-7/

Lưu ý ở bước bật cổng 80, 443. Trước khi bật hãy bật firewall bằng lệnh sau:


sudo systemctl enable firewalld


Các bước làm: chạy lần lượt các câu lệnh sau:


sudo yum update httpd
sudo yum install httpd
sudo systemctl enable firewalld
systemctl restart firewalld
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
sudo systemctl start httpd
sudo systemctl status httpd


  1. cập nhật httpd package index cục bộ để nhận những thay đổi mới nhất
  2. cài đặt các gói
  3. Bật firewalld
  4. Restart filewalld
  5. Bật cổng 80
  6. Bật cổng 443
  7. Reload firewall
  8. Start apache
  9. Check status apache

2. Cài git

https://www.digitalocean.com/community/tutorials/how-to-install-git-on-centos-7

Các bước thực hiện: Chạy lần lượt các câu lệnh sau:


sudo yum install git
git --version
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --list


  1. Cài đặt git
  2. Check git đã cài đặt
  3. Cấu hình user.name
  4. Cấu hình user.mail
  5. Check config

3. Cài mysql

Phần 1, 2


https://support.cloudzone.vn/knowledge-base/huong-dan-dat-lai-mat-khau-root-cua-mysql-hoac-mariadb-tren-centos-7/

Cài PhpMyAdmin 

https://wiki.tino.org/install-phpmyadmin-centos-7/ (Mục install PhpMyAdmin CentOS 7 – Apache)

Lưu ý: Những chữ PhpMyAdmin => phpMyAdmin (chữ đầu không viết hoa)

https://arrowtran.com/2020/01/03/sua-loi-you-dont-have-permission-to-access-phpmyadmin-on-this-server/


. CàiCác bước thực hiện:


Cài PHP


rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum install php70w php70w-fpm php70w-opcache
php -v
systemctl enable php-fpm


Đối với các phiên bản PHP thấp hơn muốn cấp lên PHP 7 thì cần thận trọng cân nhắc để đảm bảo việc update không ảnh hưởng tới hoạt động ổn định của hệ thống sau khi nâng cấp. Trong trường hợp bạn vẫn muốn nâng cấp, bạn có thể thực hiện:


yum install yum-plugin-replace
yum replace php-common --replace-with=php70w-common


Tiếp tục cài MySQL:


wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum update -y
sudo yum install -y  mysql-server
sudo systemctl start mysqld
systemctl enable mysqld
// đổi mật khẩu mysql
mysql --version
sudo systemctl stop mysql
sudo mysqld_safe --skip-grant-tables --skip-networking &
service mysqld start
mysql -u root
FLUSH PRIVILEGES;
// Phiên bản MySQL 5.7.6 và mới hơn
	ALTER USER 'root'@'localhost' IDENTIFIED BY 'password mới';
// Với các phiên bản cũ hơn
	SET PASSWORD FOR 'root'@'localhost' = PASSWORD('password mới');
exit
sudo kill `cat /var/run/mysqld/mysqld.pid`
sudo systemctl start mysql
mysql -u root -p


Tiếp theo cài PhpMyAdmin


sudo yum install phpMyAdmin
sudo vi /etc/httpd/conf.d/phpMyAdmin.conf


<Directory /usr/share/phpMyAdmin/>
   AddDefaultCharset UTF-8


   <IfModule mod_authz_core.c>
     # Apache 2.4
     <RequireAny>
       #Require ip 127.0.0.1
       #Require ip ::1
       Require all granted
     </RequireAny>
   </IfModule>
   <IfModule !mod_authz_core.c>
     # Apache 2.2
     Order Deny,Allow
     Deny from All
     Allow from 127.0.0.1  // ========> change to ip server
     Allow from ::1
   </IfModule>
</Directory>


Change dòng 16 thành ip server


sudo systemctl restart httpd.service
sudo systemctl restart httpd


Truy cập ip/phpmyadmin để check hoạt động không?

4. Kinh nghiệm

4.1 Access denied khi kết nối database bằng ứng dụng khác


// thay username and password tương ứng
GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY 'Password' with grant option; 


FLUSH PRIVILEGES;


Tham khảo: https://stackoverflow.com/questions/8380797/enable-remote-mysql-connection-error-1045-28000-access-denied-for-user

Cách khác vào db bằng phpmyadmin và check quyền chỗ host phải là % không? Nếu còn localhost thì ứng dụng khác không kết nối vào được.


Copyright © 2025 All Right Reserved