Last active
March 30, 2019 09:16
-
-
Save glaucomorais/9c9c057dfebe55e4a328 to your computer and use it in GitHub Desktop.
Basic Vagrant with CentOS + Nginx + PHP-FPM + MySQL bootstrap
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 | |
echo "Mudando o fuso-horario" | |
mv /etc/localtime /etc/localtime.bak | |
ln -fs /usr/share/zoneinfo/America/Sao_Paulo /etc/localtime | |
echo "Obtendo os repositorios EPEL e Remi" | |
rpm -Uvh --quiet http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm | |
rpm -Uvh --quiet http://rpms.famillecollet.com/enterprise/remi-release-6.rpm | |
echo "Habilitando o repositorio Remi" | |
sed -i '5 c enabled=1' /etc/yum.repos.d/remi.repo | |
sed -i '23 c enabled=1' /etc/yum.repos.d/remi.repo | |
echo "Escrevendo configuracao do repositorio Nginx" | |
cat > /etc/yum.repos.d/nginx.repo <<EOL | |
[nginx] | |
name=nginx repo | |
baseurl=http://nginx.org/packages/centos/\$releasever/\$basearch/ | |
gpgcheck=0 | |
enabled=1 | |
EOL | |
echo "Atualizando e instalando pacotes" | |
yum update -y -q | |
yum install -y -q \ | |
php-cli php-fpm php-common php-mbstring php-xml php-gd \ | |
php-imagick php-opcache php-memcache php-mcrypt php-intl \ | |
php-pdo php-apc php-mysqlnd nginx mysql mysql-server \ | |
dkms | |
echo "Alterando a configuracao do PHP" | |
sed -i '/display_errors.*=.*Off/c display_errors = On' /etc/php.ini | |
sed -i '/;date.timezone.*=/c date.timezone = America/Sao_Paulo' /etc/php.ini | |
sed -i '/;cgi\.fix_pathinfo.*=.*1/c cgi.fix_pathinfo = 0' /etc/php.ini | |
sed -i '/expose_php.*=.*On/c expose_php = Off' /etc/php.ini | |
sed -i '/Local Variables/i development = 1\n' /etc/php.ini | |
echo "Criando pastas e links necessarios" | |
mkdir -p /vagrant/logs/nginx | |
rm -rf /var/www/html | |
ln -fs /vagrant/web /var/www/html | |
echo "Copiando as configuracoes" | |
cp -f /vagrant/vagrant/conf/nginx.conf /etc/nginx/conf.d/default.conf | |
echo "Adicionando os usuarios nginx e apache ao grupo vagrant" | |
usermod -a -G vagrant nginx | |
usermod -a -G vagrant apache | |
echo "Habilitando o Nginx e o PHP-FPM para iniciarem automaticamente" | |
chkconfig nginx on | |
chkconfig php-fpm on | |
chkconfig mysqld on | |
echo "Iniciando servicos" | |
service nginx start | |
service php-fpm start | |
service mysqld start | |
echo "Permitindo acesso remoto ao MySQL" | |
mysql -uroot -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION" | |
mysql -uroot -e "FLUSH PRIVILEGES" | |
echo "Pronto." |
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
server { | |
listen 80; | |
server_name localhost; | |
charset utf-8; | |
access_log /vagrant/logs/nginx/access.log; | |
error_log /vagrant/logs/nginx/error.log; | |
root /var/www/html; | |
index index.html index.htm index.php; | |
location / { | |
try_files $uri /$uri /index.php?$args; | |
sendfile off; | |
} | |
location ~ \.php$ { | |
include fastcgi_params; | |
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name; | |
fastcgi_pass 127.0.0.1:9000; | |
try_files $uri =404; | |
sendfile off; | |
} | |
location ~ /\.(ht|git) { | |
deny all; | |
} | |
} |
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 | |
if !(pgrep nginx > /dev/null); then | |
service nginx start | |
fi |
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 = "centos-65-x64" | |
config.vm.network "forwarded_port", guest: 3306, host: 3306 | |
config.vm.network "private_network", ip: "192.168.56.101" | |
config.vm.provider "virtualbox" do |vb| | |
vb.memory = 512 | |
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"] | |
end | |
config.vm.provision "shell", path: "vagrant/bootstrap.sh" | |
config.vm.provision "shell", path: "vagrant/nginx_check.sh", run: "always" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment