LNMP是指Linux、Nginx、MySQL和PHP的组合,常用于搭建网站服务器。以下是CentOS上部署LNMP网站的详细流程:
sudo yum install epel-release -y
sudo yum install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx
sudo systemctl status nginx
sudo yum install mariadb-server mariadb -y
sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo mysql -u root -p
在MariaDB shell中执行:CREATE DATABASE wordpress;
CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
sudo yum install php php-fpm -y
/etc/php-fpm.d/www.conf
文件,设置user
和group
为nginx
:user = nginx
group = nginx
sudo systemctl start php-fpm
sudo systemctl enable php-fpm
sudo systemctl status php-fpm
/etc/nginx/conf.d/
目录下,例如php.conf
:server {
listen 80;
server_name example.com;
root /var/www/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
sudo systemctl restart nginx
/var/www/html
)。wp-config.php
文件,设置数据库信息:define('DB_NAME', 'wordpress');
define('DB_USER', 'wordpressuser');
define('DB_PASSWORD', 'password');
define('DB_HOST', 'localhost');
以上是CentOS上部署LNMP网站的基本流程。根据具体需求,可能还需要配置SSL证书、设置缓存、优化性能等。