在Ubuntu上部署WordPress通常需要安装LAMP(Linux、Apache、MySQL、PHP)软件堆栈。以下是在Ubuntu上部署WordPress的步骤:
sudo apt update
sudo apt upgrade
sudo apt install apache2
sudo apt install mysql-server
sudo apt install php libapache2-mod-php php-mysql
mysql -u root -p
CREATE DATABASE wordpress;
CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
cd /var/www/html
sudo wget https://wordpress.org/latest.tar.gz
sudo tar -xzvf latest.tar.gz
sudo mv wordpress/wp-config-sample.php wordpress/wp-config.php
sudo nano wordpress/wp-config.php
在配置文件中,更新以下数据库连接信息:
define('DB_NAME', 'wordpress');
define('DB_USER', 'wordpressuser');
define('DB_PASSWORD', 'password');
define('DB_HOST', 'localhost');
sudo chown -R www-data:www-data /var/www/html/wordpress
sudo chmod -R 755 /var/www/html/wordpress
sudo nano /etc/apache2/sites-available/wordpress.conf
在文件中输入以下内容:
<VirtualHost *:80>
ServerAdmin admin@example.com
DocumentRoot /var/www/html/wordpress
ServerName example.com
ServerAlias www.example.com
<Directory /var/www/html/wordpress/>
Options FollowSymlinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
启用WordPress站点:
sudo a2ensite wordpress.conf
sudo a2enmod rewrite
sudo systemctl restart apache2
以上就是在Ubuntu LAMP上部署WordPress的基本步骤。在实际应用中,可能需要根据具体需求进行进一步的配置和优化。