在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的基本步驟。在實際應用中,可能需要根據具體需求進行進一步的配置和優化。