Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A quick Vagrant file to get started with PHP 7.2
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = '2'
@script = <<SCRIPT
# Fix for https://bugs.launchpad.net/ubuntu/+source/livecd-rootfs/+bug/1561250
if ! grep -q "ubuntu-xenial" /etc/hosts; then
echo "127.0.0.1 ubuntu-xenial" >> /etc/hosts
fi
# Install dependencies
add-apt-repository ppa:ondrej/php
apt-get update
apt-get install -y apache2 git curl php7.2 php7.2-bcmath php7.2-bz2 php7.2-cli php7.2-curl php7.2-intl php7.2-json php7.2-mbstring php7.2-opcache php7.2-soap php7.2-sqlite3 php7.2-xml php7.2-xsl php7.2-zip libapache2-mod-php7.2
# Configure Apache
echo "<VirtualHost *:80>
DocumentRoot /var/www/public
AllowEncodedSlashes On
<Directory /var/www/public>
Options +Indexes +FollowSymLinks
DirectoryIndex index.php index.html
Order allow,deny
Allow from all
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>" > /etc/apache2/sites-available/000-default.conf
a2enmod rewrite
service apache2 restart
if [ -e /usr/local/bin/composer ]; then
/usr/local/bin/composer self-update
else
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
fi
# Reset home directory of vagrant user
if ! grep -q "cd /var/www" /home/ubuntu/.profile; then
echo "cd /var/www" >> /home/ubuntu/.profile
fi
echo "** [PHP] Run the following command to install dependencies, if you have not already:"
echo " vagrant ssh -c 'composer install'"
echo "** [PHP] Visit http://localhost:8080 in your browser for to view the application **"
SCRIPT
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = 'ubuntu/xenial64'
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.synced_folder '.', '/var/www'
config.vm.provision 'shell', inline: @script
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", "1024"]
vb.customize ["modifyvm", :id, "--name", "php7.2 app"]
end
end
@grafxflow

This comment has been minimized.

Copy link

@grafxflow grafxflow commented Mar 28, 2020

It would be nice to add this code in order to allow php <? shorthand.

# Allow the php shorthand <? from <?php
sed -i 's,^short_open_tag =.*$,short_open_tag = On,' /etc/php/7.2/apache2/php.ini
@jblac

This comment has been minimized.

Copy link

@jblac jblac commented Oct 4, 2020

@grafxflow PHP short_tags shouldn't be enabled actually. They are deprecated in 7.4 and removed in 8.0 - so adding it in, renders this file un-updatable from a dependency standpoint. But, even using them should be considered a bad practice (and it is against PSR so it is a bad practice) as using them pretty much ensures that you CANNOT upgrade PHP when the later versions come out.

@DragonBe

This comment has been minimized.

Copy link
Owner Author

@DragonBe DragonBe commented Oct 4, 2020

I agree with @jblac as using short tags is considered a bad practice. Since I never use them I never bothered to look at the setting. But feel free to modify this Vagrant file to your likings once you have pulled it in.

To be fair: by the end of next month support for PHP 7.2 has reached its end, so I might as well shut this gist down or upgrade to PHP 7.4 or even 8.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.