LAMP(Linux, Apache, MySQL, PHP)是搭建个人博客平台的经典技术组合。以下是详细步骤:
sudo apt update && sudo apt upgrade -y
(Ubuntu/Debian)ssh username@your_server_ip
# Ubuntu/Debian
sudo apt install apache2 -y
# CentOS/RHEL
sudo yum install httpd -y
sudo systemctl start httpd
sudo systemctl enable httpd
验证安装: - 访问服务器IP地址,应看到Apache默认页面
# Ubuntu/Debian
sudo apt install mysql-server -y
sudo mysql_secure_installation
# CentOS/RHEL
sudo yum install mariadb-server -y
sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo mysql_secure_installation
# Ubuntu/Debian
sudo apt install php libapache2-mod-php php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip -y
# CentOS/RHEL
sudo yum install php php-mysqlnd php-gd php-mbstring php-xml php-pear php-fpm -y
验证PHP安装:
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
访问 http://your_server_ip/info.php
查看PHP信息
cd /tmp
wget https://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
sudo mv wordpress /var/www/html/blog
sudo chown -R www-data:www-data /var/www/html/blog
sudo chmod -R 755 /var/www/html/blog
sudo mysql -u root -p
CREATE DATABASE wordpress;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'your_strong_password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
cd /var/www/html/blog
cp wp-config-sample.php wp-config.php
nano wp-config.php
修改以下内容:
define('DB_NAME', 'wordpress');
define('DB_USER', 'wpuser');
define('DB_PASSWORD', 'your_strong_password');
define('DB_HOST', 'localhost');
sudo nano /etc/apache2/sites-available/blog.conf
添加以下内容:
<VirtualHost *:80>
ServerAdmin admin@example.com
ServerName yourdomain.com
ServerAlias www.yourdomain.com
DocumentRoot /var/www/html/blog
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
启用站点:
sudo a2ensite blog.conf
sudo a2enmod rewrite
sudo systemctl restart apache2
http://your_server_ip/blog
或 http://yourdomain.com
安装SSL证书(使用Let's Encrypt):
sudo apt install certbot python3-certbot-apache -y
sudo certbot --apache -d yourdomain.com -d www.yourdomain.com
限制PHP执行权限:
sudo nano /etc/php/7.4/apache2/php.ini
修改:
disable_functions = exec,passthru,shell_exec,system,proc_open,popen
expose_php = Off
定期更新系统:
sudo apt update && sudo apt upgrade -y
数据库备份:
mysqldump -u wpuser -p wordpress > wordpress_backup_$(date +%F).sql
文件备份:
tar -czvf wordpress_files_$(date +%F).tar.gz /var/www/html/blog
现在你已经成功使用LAMP搭建了一个个人博客平台!你可以开始自定义主题、安装插件和发布内容了。