Este guia explica como instalar WordPress no seu VPS Linux. WordPress é o CMS mais popular do mundo.
⚠️ Aviso importante
Importante: Para sites WordPress, recomendamos o alojamento web Infrawire (estabilidade, backups automáticos, suporte especializado, atualizações geridas, segurança e desempenho otimizado).
Se preferir um ambiente dedicado não partilhado com controlo total, pode instalar WordPress num VPS Infrawire. Este guia explica como.
📋 Pré-requisitos
- VPS Linux com acesso root ou sudo
- Pelo menos 1 GB de RAM (2 GB recomendado)
- Pelo menos 10 GB de espaço livre
- Domínio apontando para o IP do VPS
- Portas 80 e 443 abertas na firewall
💡 Recomendação de infraestrutura
Para desempenho ótimo, recomendamos o nosso VPS NVMe ou VPS High Performance para tráfego elevado.
🔧 Método 1: Instalação com LAMP (Apache)
Passo 1: Atualizar o sistema
Bashsudo apt update sudo apt upgrade -y
Passo 2: Instalar Apache
Bashsudo apt install -y apache2 sudo systemctl start apache2 sudo systemctl enable apache2 sudo systemctl status apache2
Passo 3: Instalar MySQL
Bashsudo apt install -y mysql-server sudo systemctl start mysql sudo systemctl enable mysql sudo mysql_secure_installation
Passo 4: Criar base de dados WordPress
Bashsudo mysql -u root -p
SQL1CREATE DATABASE wordpress_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; 2CREATE USER 'wordpress_user'@'localhost' IDENTIFIED BY 'YourSecurePassword123!'; 3GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wordpress_user'@'localhost'; 4FLUSH PRIVILEGES; 5EXIT;
Importante: Substitua YourSecurePassword123! por uma palavra-passe forte e única.
Passo 5: Instalar PHP
Bashsudo apt install -y php php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip libapache2-mod-php php -v
Para PHP 8.1 (recomendado):
Bashsudo apt install -y php8.1 php8.1-mysql php8.1-curl php8.1-gd php8.1-mbstring php8.1-xml php8.1-xmlrpc php8.1-soap php8.1-intl php8.1-zip libapache2-mod-php8.1
Passo 6: Descarregar WordPress
Bash1cd /tmp 2curl -O https://wordpress.org/latest.tar.gz 3tar xzf latest.tar.gz 4sudo cp -r wordpress/* /var/www/html/ 5sudo chown -R www-data:www-data /var/www/html 6sudo chmod -R 755 /var/www/html
Passo 7: Configurar WordPress
Bashcd /var/www/html sudo cp wp-config-sample.php wp-config.php sudo nano wp-config.php
PHPdefine( 'DB_NAME', 'wordpress_db' ); define( 'DB_USER', 'wordpress_user' ); define( 'DB_PASSWORD', 'YourSecurePassword123!' ); define( 'DB_HOST', 'localhost' );
Gere chaves únicas em: https://api.wordpress.org/secret-key/1.1/salt/
Passo 8: Configurar Apache
Bashsudo a2enmod rewrite sudo nano /etc/apache2/sites-available/000-default.conf
Apache1<Directory /var/www/html> 2 Options Indexes FollowSymLinks 3 AllowOverride All 4 Require all granted 5</Directory>
Bashsudo systemctl restart apache2
Passo 9: Concluir via interface web
- Abra o browser em
http://YOUR_IPouhttp://yourdomain.com - Siga o assistente de instalação WordPress
🔧 Método 2: Instalação com LEMP (Nginx)
Instale Nginx, MySQL (passos 3–4 do LAMP) e PHP-FPM:
Bashsudo apt install -y nginx php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip sudo apt install -y php8.1-fpm php8.1-mysql php8.1-curl php8.1-gd php8.1-mbstring php8.1-xml php8.1-xmlrpc php8.1-soap php8.1-intl php8.1-zip
Descarregue WordPress (passo 6 do LAMP) e configure Nginx:
Bashsudo nano /etc/nginx/sites-available/wordpress
Nginx1server { 2 listen 80; 3 listen [::]:80; 4 server_name yourdomain.com www.yourdomain.com; 5 root /var/www/html; 6 index index.php index.html index.htm; 7 8 location / { 9 try_files $uri $uri/ /index.php?$args; 10 } 11 12 location ~ \.php$ { 13 include snippets/fastcgi-php.conf; 14 fastcgi_pass unix:/var/run/php/php8.1-fpm.sock; 15 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 16 include fastcgi_params; 17 } 18 19 location ~ /\.ht { 20 deny all; 21 } 22}
Bashsudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/ sudo nginx -t sudo systemctl restart nginx
Configure wp-config.php (passo 7 do LAMP) e conclua via interface web.
🔒 Proteger WordPress
Bashsudo find /var/www/html -type f -exec chmod 644 {} \; sudo find /var/www/html -type d -exec chmod 755 {} \; sudo chmod 600 /var/www/html/wp-config.php
Certificado SSL:
Bashsudo apt install -y certbot python3-certbot-apache # Nginx: sudo apt install -y certbot python3-certbot-nginx sudo certbot --apache -d yourdomain.com -d www.yourdomain.com sudo certbot renew --dry-run
Firewall:
Bashsudo ufw allow 'Apache Full' # Nginx: sudo ufw allow 'Nginx Full'
Em wp-config.php:
PHPdefine('DISALLOW_FILE_EDIT', true);
❓ Problemas comuns
"Error establishing a database connection"
- Verifique credenciais em
wp-config.php - MySQL ativo:
sudo systemctl status mysql - Teste:
mysql -u wordpress_user -p wordpress_db
Erro 404 nos permalinks (Apache)
Bashsudo a2enmod rewrite sudo systemctl restart apache2
📞 Precisa de ajuda?
Contacte o suporte Infrawire. Para uma experiência WordPress com suporte dedicado e backups, considere o nosso alojamento web WordPress.
Nota: Um VPS oferece controlo total; o alojamento gerido simplifica a manutenção.