Mysql wordpress trên linux

WordPress được biết đến như một CMS [Content Management System] miễn phí và dễ sử dụng nhất trên thế giới. WordPress được viết bằng ngôn ngữ PHP và sử dụng cơ sở dữ liệu MySQL. Trong bài viết này HCĐ sẽ hướng dẫn bạn cách cài đặt WordPress trên Ubuntu sử dụng LAMP stack [Linux + Apache + MySQL + PHP]

1. Chuẩn bị

Một máy chạy HĐH Ubuntu có cấu hình tối thiểu

  • 1 GB RAM
  • 1 CPU
  • 1 Interface
  • 10 GB ổ cứng

Lưu ý: Server của bạn cần có internet cho việc cài đặt

Bước 1. Cài đặt Apache

sudo apt update -y
sudo apt install apache2 -y

Khởi động dịch vụ apache2 và cho phép dịch vụ tự khởi động lại khi bạn khởi động lại máy

sudo systemctl start apache2.service
sudo systemctl enable apache2.service

Bước 2. Cài đặt MariaDB

Bạn có thể sử dụng MySQL hoặc MariaDB. Trong hướng dẫn này sẽ sử dụng MariaDB

sudo apt install mariadb-server mariadb-client -y

Khởi động dịch vụ mariadb và cho phép dịch vụ tự khởi động lại khi bạn khởi động lại máy

sudo systemctl start mariadb
sudo systemctl enable mariadb

Thiết lập cấu hình ban đầu cho cơ sở dữ liệu

sudo mysql_secure_installation

Thiết lập password cho user root và không cho phép user root đăng nhập từ xa để đảm bảo an toàn cho cơ sở dữ liệu

Enter current password for root [enter for none]:
Set root password? [Y/n] y
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y

Đăng nhập thử để kiểm tra

sudo mysql -u root -p

Sau đó nhập mật khẩu vừa đặt ở bên trên

[email protected]:~# sudo mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 49
Server version: 10.1.47-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.04
Copyright [c] 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [[none]]> exit
Bye
[email protected]:~#

Bước 3. Cài đặt PHP

Cài đặt PHP và các extensiton sử dụng cho WordPress

sudo apt install -y php libapache2-mod-php php-cli php-fpm php-json php-pdo php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath

Bước 4. Tạo database cho WordPress

Đăng nhập vào MariaDB

sudo mysql -u root -p

Tạo database

CREATE DATABASE wordpress;

Tạo user

CREATE USER 'wordpress'@'localhost' IDENTIFIED BY '[email protected]';

Gán quyền sử dụng cơ sở dữ liệu cho user

GRANT ALL ON wordpress.* TO 'wordpress'@'localhost' WITH GRANT OPTION;

Lưu lại và thoát khỏi cơ sở dữ liệu

FLUSH PRIVILEGES;
exit

Bước 5. Download mã nguồn WordPress

sudo apt-get install -y wget unzip
cd /var/www/html
wget //wordpress.org/latest.zip

Giải nén

unzip latest.zip
mv wordpess/* .
rm -f index.html

Bước 6. Cấu hình WordPress

Tạo file cấu hình

cd /var/www/html
cp wp-config-sample.php wp-config.php

Khai báo thông tin cơ sở dữ liệu vừa tạo ở bước 4

sed -i -e "s/database_name_here/"wordpress"/g" /var/www/html/wp-config.php
sed -i -e "s/username_here/"wordpress"/g" /var/www/html/wp-config.php
sed -i -e "s/password_here/"[email protected]"/g" /var/www/html/wp-config.php

Bước 7. Thiết lập cấu hình ban đầu cho trang web

Trên trình duyệt truy cập địa chỉ của server

//

Truy cập nếu thấy kết quả như sau là đã thành công

Khai báo thông tin ban đầu cho website của bạn

Đăng nhập với username và password bạn tạo ở bên trên

Sau khi đăng nhập bạn đã vào được trang quản trị của của wordpress

Đến đây việc cài đặt một website sử dụng WordPress đã hoàn tất.

Bài Viết Liên Quan

Chủ Đề