July 21, 2015

With PHP 7 around the corner, we wanted to create a dev environment to test some apps and prepare for its arrival.
PHP 7 installation for CentOS is not difficult and can be found here. With the precompiled builds, we created a VM with the appropriate software to start testing WordPress: Apache2, MariaDB and PHP 7. For this VM, we used Vagrant and VirtualBox.
VM setup involves two files: Vagrantfile, with centos.sh as a provisioner.

Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(“2”) do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# refer to the online documentation at vagrantup.com.
# Every Vagrant virtual environment requires a box to build off of. We use CentOS.
config.vm.box = “chef/centos-7.0”
config.vm.network “private_network”, ip: “192.168.33.13”
config.vm.provision :shell, :path => “centos.sh”
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing “localhost:8080” will access port 80 on the guest machine.
config.vm.network :forwarded_port, guest: 80, host: 8080
config.vm.synced_folder “.”, “/vagrant”, :mount_options => [“dmode=777″,”fmode=777”]
config.ssh.forward_agent = true
config.vm.provider :virtualbox do |vb|
vb.customize [“modifyvm”, :id, “–memory”, “1024”]
vb.name = “simple-php7-vagrant-centos”
end
end

centos.sh

#!/usr/bin/env bash
# Install Apache and PHP dependencies.
# ——————–
sudo yum -y install httpd
sudo systemctl start httpd.service
sudo systemctl enable httpd.service
sudo yum install -y \
recode-devel \
aspell-devel \
libmcrypt-devel \
t1lib-devel \
libXpm-devel \
libpng-devel \
libjpeg-turbo-devel \
bzip2-devel \
openssl-libs \
libicu-devel
sudo yum -y install epel-release
# Install precompiled PHP7 from Zend repos.
# ——————–
wget http://repos.zend.com/zend-server/early-access/php7/php-7.0-beta1-RHEL-x86_64.tar.gz
sudo tar xzPf php-7.0-beta1-RHEL-x86_64.tar.gz
sudo cp /usr/local/php7/libphp7.so /etc/httpd/modules/
# Delete default Apache web dir and symlink mounted Vagrant dir from host machine.
# ——————–
rm -rf /var/www/html
mkdir /vagrant/httpdocs
ln -fs /vagrant/httpdocs /var/www/html
sudo chown apache:apache -R /var/www/html
# Set handler for PHP in Apache config
# ——————–
HANDLER=$(echo “LoadModule php7_module /usr/lib64/httpd/modules/libphp7.so
SetHandler application/x-httpd-php
“)
echo “$HANDLER” >> /etc/httpd/conf/httpd.conf
# Create Apache vhost
# ——————–
VHOST=$(cat <
DirectoryIndex index.php
DocumentRoot “/var/www/html/wordpress”
ServerName localhost

AllowOverride All
DirectoryIndex index.php
DocumentRoot “/var/www/html/wordpress”
ServerName localhost

AllowOverride All
EOF
)
echo “$VHOST” >> /etc/httpd/conf/httpd.conf
# Install MariaDB
# —————
sudo yum -y install mariadb-server mariadb
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service
mysql -u root -e “CREATE DATABASE IF NOT EXISTS wp”
mysql -u root -e “GRANT ALL PRIVILEGES ON wp.* TO ‘wp’@’localhost’ IDENTIFIED BY ‘password'”
mysql -u root -e “FLUSH PRIVILEGES”
sudo yum -y install unzip
# Download and extract WordPress
# ——————————
if [[ ! -f “/vagrant/httpdocs/wordpress/index.php” ]]; then
cd /var/www/html
wget http://wordpress.org/latest.zip
unzip latest.zip
echo ‘
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
‘ >> /var/www/html/wordpress/.htaccess
INFO=$(echo ““)
echo “$INFO” >> /var/www/html/wordpress/info.php
sudo chown apache:apache -R *
sudo find . -type d -exec chmod 755 {} \;
sudo find . -type f -exec chmod 644 {} \;
fi
# Restart Apache
# —————
sudo systemctl restart httpd.service
You can find the complete VM installation guide here. It will install everything you need, and once cloned, a simple vagrant up will start the VM creation and provision process. The result will be a ready-to-install WordPress running on PHP7.
Once the provisioning is done you should be abl to access your installation on http://127.0.0.1:8080/ and see a complete phpinfo() at http://127.0.0.1:8080/info.php
The database information for installation is as follows:

  • User: wp
  • Pass: password
  • Database: wp

This is intended to be a test environment and we do not recommend implementing this on a production server. At Nexcess, we are working hard to officially support PHP7, stay tuned for more info and related posts to come!

Miguel Balparda
Miguel Balparda

Who is Miguel? If you’re part of the Magento community, chances are you already know. As a Magento Master and open source Community Maintainer, Miguel can be found traveling the world imparting his Magento wisdom at events and approving pull requests everywhere else.

We use cookies to understand how you interact with our site, to personalize and streamline your experience, and to tailor advertising. By continuing to use our site, you accept our use of cookies and accept our Privacy Policy.