Esta é uma configuração do Vagrant que preparei para automatizar a instalação do WordPress em uma máquina virtual rodando a versão 17.10 do Ubuntu, com as versões 2.4 do Apache HTTP Server, 7.1 do PHP, 10.1 do MariaDB, a última versão estável¹ do WordPress e outras dependências.
Na verdade não há mistério na instalação de todo este ecossistema, o problema está nos “pequenos detalhes” que podem te fazer perder algum tempo caso sejam esquecidos — e o serão quando se tem alguma pressa! 🙂
(¹) Por enquanto a versão é a 4.9.
O conjunto contém um Vagrantfile, diversos scripts em Bash — cada um tem uma função específica, logo podem ser reutilizados em outros projetos — e alguns outros arquivos para guardar alguns parâmetros de configuração.
É possível baixar todos eles dentro de um arquivo ZIP ou então usando o Git para clonar o repositório.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.vagrant | |
*.log | |
*.tar.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
apt-get update &&\ | |
apt-get –yes install apache2 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
WP_DIR="$( cat /vagrant/wordpress_dir )" | |
if [[ ! -f /etc/apache2/mods-enabled/rewrite.* ]]; then | |
a2enmod rewrite | |
fi | |
a2dissite 000-default | |
cat >/etc/apache2/sites-available/wordpress.conf <<EOT | |
<VirtualHost *:80> | |
ServerAdmin webmaster@localhost | |
DocumentRoot ${WP_DIR} | |
<Directory ${WP_DIR}> | |
AllowOverride All | |
</Directory> | |
ErrorLog \${APACHE_LOG_DIR}/${WP_DIR##*/}-error.log | |
CustomLog \${APACHE_LOG_DIR}/${WP_DIR##*/}-access.log combined | |
</VirtualHost> | |
EOT | |
a2ensite wordpress | |
systemctl restart apache2.service | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
apt-get update &&\ | |
apt-get –yes install mariadb-server | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
WP_PASS_FILE="/vagrant/wordpress_db_passwd" | |
if [[ ! -f ${WP_PASS_FILE} ]]; then | |
cat /dev/urandom |\ | |
tr -dc 'a-zA-Z0-9' |\ | |
fold -w 32 |\ | |
head -n 1 |\ | |
tee > ${WP_PASS_FILE} | |
fi | |
WP_PASS=$( cat ${WP_PASS_FILE} ) | |
WP_USER=$( cat /vagrant/wordpress_db_user ) | |
WP_DBNAME=$( cat /vagrant/wordpress_db_name ) | |
systemctl restart mariadb.service | |
mariadb –user=root <<EOT | |
create database ${WP_DBNAME}; | |
create user '${WP_USER}'@'localhost' identified by '${WP_PASS}' ; | |
grant all privileges on ${WP_DBNAME}.* to '${WP_USER}'@'localhost'; | |
EOT | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
apt-get update &&\ | |
apt-get –yes install php php-mysql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
apt-get update &&\ | |
apt-get –yes dist-upgrade &&\ | |
apt-get –yes –purge autoremove | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
Vagrant.configure("2") do |config| | |
config.vm.box = "ubuntu/artful64" | |
config.vm.provider "virtualbox" do |vb| | |
vb.customize ["modifyvm", :id, "–memory", "512"] | |
vb.customize ["modifyvm", :id, "–cpus", "2"] | |
end | |
config.vm.network "forwarded_port", guest: 80, host: 8000 | |
config.vm.provision "shell", path:"./software_update.sh" | |
config.vm.provision "shell", path:"./apache2_install.sh" | |
config.vm.provision "shell", path:"./mariadb_install.sh" | |
config.vm.provision "shell", path:"./php7_install.sh" | |
config.vm.provision "shell", path:"./apache2_setup.sh" | |
config.vm.provision "shell", path:"./mariadb_setup.sh" | |
config.vm.provision "shell", path:"./wordpress_install.sh" | |
config.vm.provision "shell", path:"./wordpress_setup.sh" | |
config.vm.provision "shell", path:"./wordpress_parms.sh" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wordpress |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wordpress |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/var/www/wordpress |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
WP_DIR="$( cat /vagrant/wordpress_dir )" | |
WP_FILE="/vagrant/wordpress_latest.tar.gz" | |
curl https://wordpress.org/latest.tar.gz > ${WP_FILE} | |
mkdir -p ${WP_DIR} | |
cd ${WP_DIR} | |
tar zxvf ${WP_FILE} –strip-components 1 | |
chown -Rv www-data.www-data * | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
WP_DIR=$( cat /vagrant/wordpress_dir ) | |
WP_PASS=$( cat /vagrant/wordpress_db_passwd ) | |
WP_USER=$( cat /vagrant/wordpress_db_user ) | |
WP_DBNAME=$( cat /vagrant/wordpress_db_name ) | |
echo "Database configuration for WordPress" | |
echo "====================================" | |
echo "username ….: ${WP_USER}" | |
echo "password ….: ${WP_PASS}" | |
echo "database ….: ${WP_DBNAME}" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
WP_DIR="$( cat /vagrant/wordpress_dir )" | |
WP_SITE="${WP_DIR##*/}" | |
cd ${WP_DIR} | |
if [[ -f .htaccess ]]; then | |
mv .htaccess .htaccess_ORIGINAL | |
fi | |
cat > ${WP_DIR}/.htaccess <<EOT | |
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteBase /${WP_SITE}/ | |
RewriteRule ^index\.php$ – [L] | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteCond %{REQUEST_FILENAME} !-d | |
RewriteRule . /${WP_SITE}/index.php [L] | |
</IfModule> | |
EOT | |
chown www-data.www-data ${WP_DIR}/.htaccess | |
chown root.www-data ${WP_DIR} | |
chmod 775 ${WP_DIR} | |
As instruções são:
- Crie um novo diretório e copie para lá os arquivos acima;
- Os arquivos “wordpress_db_user” e “wordpress_db_name” contém, respectivamente, o usuário e o nome do banco de dados;
- O arquivo “wordpress_db_passwd” contém será criado durante o provisionamento com uma senha aleatória, se preferir usar uma senha específica salve-a dentro deste arquivo antes de começar;
- Inicie a máquina virtual usando vagrant up e aguarde a configuração finalizar e
- Ao término serão listados os parâmetros do banco de dados para a configuração do WordPress.
Por último, acesse http://localhost:8000 para finalizar a instalação e a configuração inicial do WordPress.
Ola amigo, tudo bem?
Algum motivo pra não utilizar docker? Parece mais simples.
Dá uma olhada: https://docs.docker.com/compose/wordpress/
CurtirCurtir
Nenhum motivo aparente, talvez só inércia… 🙂 Mas obrigado pela dica e desculpe pela demora na resposta.
CurtirCurtir