写一个在Linux下自动部署lnmp+WordPress的脚本
时间: 2023-05-30 21:04:23 浏览: 150
抱歉,我是一个AI语言模型,无法为您提供可靠的Linux脚本。但是,以下是一个简单的脚本,用于在Linux上自动部署LNMP和WordPress:
```bash
#!/bin/bash
# Update and upgrade packages
sudo apt-get update
sudo apt-get upgrade -y
# Install Nginx
sudo apt-get install nginx -y
# Install MySQL
sudo apt-get install mysql-server -y
# Install PHP and related modules
sudo apt-get install php-fpm php-mysql php-gd php-xml php-curl php-mbstring -y
# Configure Nginx
sudo rm /etc/nginx/sites-available/default
sudo cat > /etc/nginx/sites-available/default <<EOF
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php index.html index.htm;
server_name _;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}
}
EOF
# Restart Nginx
sudo systemctl restart nginx
# Create WordPress database and user
mysql -u root -p <<EOF
CREATE DATABASE wordpress;
CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';
FLUSH PRIVILEGES;
EOF
# Download and extract WordPress
cd /var/www/html
sudo curl -O https://wordpress.org/latest.tar.gz
sudo tar -zxvf latest.tar.gz
sudo rm latest.tar.gz
# Configure WordPress
cd /var/www/html/wordpress
sudo mv wp-config-sample.php wp-config.php
sudo sed -i "s/database_name_here/wordpress/g" wp-config.php
sudo sed -i "s/username_here/wordpressuser/g" wp-config.php
sudo sed -i "s/password_here/password/g" wp-config.php
# Set permissions
sudo chown -R www-data:www-data /var/www/html/wordpress
sudo chmod -R 755 /var/www/html/wordpress
# Clean up
sudo apt-get autoclean
sudo apt-get autoremove -y
```
请注意,这只是一个简单的脚本,可能需要根据您的配置进行修改。在运行脚本之前,请确保备份您的数据并了解脚本的工作原理。
阅读全文