Step 1: Installing Nginx on CentOS 7
- Cài đặt thư viện EPEL và nginx
yum install epel-release nginx -y
- Kiểm tra phiên bản nginx đang sử dụng
nginx -v
- Kích hoạt Nginx
systemctl start nginx systemctl enable nginx
- Kiểm tra xem Nginx có đang chạy hay không bằng cách truy cập địa chỉ IP công cộng của máy chủ của bạn. Trang của bạn sẽ trông như thế này:
Step 2: Installing MySQL (MariaDB)
- Dùng lênh yum để cài đặt trực tiếp Mysql:
yum install mariadb-server mariadb -y
- Sau khi cài đặt xong, kích hoạt và khởi động dịch vụ MariaDB:
systemctl start mariadb systemctl enable mariadb
- Setup cài đặt các thông tin bảo mật bằng cách chạy lệnh sau:
mysql_secure_installation
Step 3: Installing PHP v7.4
- Chúng ta cần tải xuống và cài đặt một kho lưu trữ của CentOS gồm các gói cần thiết cho PHP và kích hoạt php74wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm rpm -Uvh remi-release-7.rpm yum install yum-utils -y yum-config-manager –enable remi-php74
- Cài đặt gói PHP:
yum --enablerepo=remi,remi-php74 install php-fpm php-common
- Cài đặt các mô-đun PHP phổ biến để đảm bảo dịch vụ hoạt động bình thường:
yum --enablerepo=remi,remi-php74 install php-opcache php-pecl-apcu php-cli php-pear php-pdo php-mysqlnd php-pgsql php-pecl-mongodb php-pecl-redis php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml
Step 4: Configuring Nginx to work with PHP 7
- Tạo tệp cấu hình Nginx
nano /etc/nginx/conf.d/default.conf
Thêm đoạn cấu hình sau:
server { listen 80; server_name your_server_ip; # note that these lines are originally from the "location /" block root /usr/share/nginx/html; index index.php index.html index.htm; location / { try_files $uri $uri/ =404; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ .php$ { try_files $uri =404; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
> Save lại và restart ngnix
systemctl restart nginx
- Cấu hình PHP-FPM:
vi /etc/php-fpm.d/www.conf
> Tìm và sửa các dòng sau:
user = apache to user = nginx
group = apache to group = nginx
listen.owner = nobody to listen.owner = nginx
listen.group = nobody to listen.group = nginx
> Thêm dòng sau phía dưới ;listen = 127.0.0.1:9000
listen = /var/run/php-fpm/php-fpm.sock
> Save lại và restart PHP-FPM
systemctl start php-fpm. service systemctl enable php-fpm.service