Skip to content

Commit

Permalink
Upgrade LAMP to PHP 7.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
remluben committed Dec 11, 2017
1 parent 6797f13 commit d948def
Show file tree
Hide file tree
Showing 6 changed files with 296 additions and 184 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ These boilerplates are tested and working on Ubuntu 14.04.
4. Let vagrant do all the work
5. Start programming or login to the brand new VM using `vagrant ssh`
6. Access the webserver root directory using [http://localhost:8080](http://localhost:8080)
7. Access the MYQL adminer database administration tool using [http://localhost:8181](http://localhost:8181) using user *root* and no password
7. Access the MYQL adminer database administration tool using [http://localhost:8081](http://localhost:8081) using user *root* and no password

### Default database credentials

User: root

Password:
Password: root

Database: development

Expand Down
15 changes: 6 additions & 9 deletions boilerplates/lamp-laravel/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

config.vm.box = "ubuntu/trusty32"

config.vm.network :forwarded_port, guest: 80, host: 8080
Expand All @@ -13,14 +14,10 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.provision :shell, :path => "install.sh"

config.vm.synced_folder ".", "/vagrant", :mount_options => ["dmode=777", "fmode=766"]

# set to 1024 minimum to make mysql server version 5.6 work in vm
config.vm.provider "virtualbox" do |v|
v.memory = 1024
end

# If true, then any SSH connections made will enable agent forwarding.
# Default value: false
# config.ssh.forward_agent = true

# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"
end
282 changes: 181 additions & 101 deletions boilerplates/lamp-laravel/install.sh
Original file line number Diff line number Diff line change
@@ -1,101 +1,181 @@
#!/usr/bin/env bash

# adjust to whatever you like as a MYSQL root password
# adjust to whatever you like as a MYSQL database name
DBPASSWD=root
DBNAME=development

echo "--- Good morning, master. Let's get to work. Installing now. ---"

echo "--- Updating packages list ---"
sudo apt-get update

echo "--- Installing base packages ---"
sudo apt-get install -y vim curl python-software-properties

echo "--- We want the bleeding edge of PHP, right master? ---"
sudo add-apt-repository ppa:ondrej/php5-5.6

echo "--- Updating packages list ---"
sudo apt-get update

echo "--- MySQL time ---"
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password $DBPASSWD"
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $DBPASSWD"

echo "\n--- Installing the phpmyadmin for easier MYSQL database access. It will save you time master. ---\n"
sudo debconf-set-selections <<< "phpmyadmin phpmyadmin/dbconfig-install boolean true"
sudo debconf-set-selections <<< "phpmyadmin phpmyadmin/app-password-confirm password $DBPASSWD"
sudo debconf-set-selections <<< "phpmyadmin phpmyadmin/mysql/admin-pass password $DBPASSWD"
sudo debconf-set-selections <<< "phpmyadmin phpmyadmin/mysql/app-pass password $DBPASSWD"
sudo debconf-set-selections <<< "phpmyadmin phpmyadmin/reconfigure-webserver multiselect none"
sudo apt-get -y install mysql-server-5.5 phpmyadmin

echo "--- Installing PHP-specific packages ---"
sudo apt-get install -y php5 apache2 libapache2-mod-php5 php5-curl php5-gd php5-mcrypt mysql-server-5.5 php5-mysql git-core

echo "--- Installing and configuring Xdebug ---"
sudo apt-get install -y php5-xdebug

cat << EOF | sudo tee -a /etc/php5/mods-available/xdebug.ini
xdebug.scream=1
xdebug.cli_color=1
xdebug.show_local_vars=1
EOF

echo "--- Enabling mod-rewrite ---"
sudo a2enmod rewrite

echo "--- Setting document root ---"
sudo rm -rf /var/www
sudo ln -fs /vagrant/public /var/www

sed -i "s/DocumentRoot \/var\/www\/html/DocumentRoot \/var\/www\//" /etc/apache2/sites-available/000-default.conf

echo "--- What developer codes without errors turned on? Not you, master. ---"
sed -i "s/error_reporting = .*/error_reporting = E_ALL/" /etc/php5/apache2/php.ini
sed -i "s/display_errors = .*/display_errors = On/" /etc/php5/apache2/php.ini

echo "--- Allowing .htaccess overrides. You will need it master. ---"
sed -i 's/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf

echo "\n--- Configuring Apache webserver to use phpmyadmin ---\n"
echo "Listen 81" >> /etc/apache2/ports.conf

cat > /etc/apache2/conf-available/phpmyadmin.conf << "EOF"
<VirtualHost *:81>
ServerAdmin webmaster@localhost
DocumentRoot /usr/share/phpmyadmin
DirectoryIndex index.php
ErrorLog ${APACHE_LOG_DIR}/phpmyadmin-error.log
CustomLog ${APACHE_LOG_DIR}/phpmyadmin-access.log combined
</VirtualHost>
EOF
sudo a2enconf phpmyadmin

echo "--- Restarting Apache ---"
sudo service apache2 restart

echo "--- Composer is the future. But you knew that, did you master? Nice job. ---"
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

echo "--- Setup database $DBNAME ---"
echo "CREATE DATABASE $DBNAME;" | mysql -u root -p$DBPASSWD

echo "--- We need laravel installed for out laravel project. Don't we? ---"
composer create-project laravel/laravel /vagrant/laravel --prefer-dist
cd /vagrant/laravel
mv * .[^.]* ..
cd ..
rm -r laravel
sudo chmod -R 777 /vagrant/storage/

echo "--- Start setting up environment specific configuration values for our laravel application. ---"
echo "--- Frist, set laravel database credentials. ---"

sed -i "s/DB_DATABASE=homestead/DB_DATABASE=$DBNAME/" /vagrant/.env
sed -i "s/DB_USERNAME=homestead/DB_USERNAME=root/" /vagrant/.env
sed -i "s/DB_PASSWORD=secret/DB_PASSWORD=$DBPASSWD/" /vagrant/.env

echo "--- All set to go! Would you like to play a game? ---"
#!/usr/bin/env bash

# MYSQL
# user: root
# pass: as defined below
# adjust to whatever you like as a MYSQL database name
DBNAME=development
DBPASS=root

echo "--- Good morning, master. Let's get to work. Installing now. ---"

echo "--- Updating packages list and upgrading system ---"
sudo apt-get update
sudo apt-get -y dist-upgrade

echo "--- Start installing ---"
sudo apt-get install -y unzip zip build-essential

# Apache
echo "--- Installing and configuring apache webserver with bleeing edge PHP FPM ---"
sudo apt-get install -y apache2

# Set server name to calm output
sudo echo "ServerName localhost" > /etc/apache2/conf-available/httpd.conf
sudo a2enconf httpd

# PHP7
sudo apt-get install python-software-properties software-properties-common
sudo LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install libapache2-mod-fastcgi php7.1 php7.1-fpm php7.1-mysql php7.1-curl php7.1-gd php7.1-intl php-pear php7.1-imap php7.1-mcrypt php7.1-ps php7.1-pspell php7.1-recode php7.1-snmp php7.1-sqlite php7.1-tidy php7.1-xmlrpc php7.1-xsl php7.1-mbstring -y

sudo a2enmod actions fastcgi alias

sudo service apache2 restart
sudo service php7.1-fpm restart

# PHP tweaks
echo "--- Let us configure good PHP defaults, my master. ---"
sed -i "s/error_reporting = .*/error_reporting = E_ALL/" /etc/php/7.1/fpm/php.ini
sed -i "s/display_errors = .*/display_errors = On/" /etc/php/7.1/fpm/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 20M/g" /etc/php/7.1/fpm/php.ini
sed -i "s/post_max_size = 8M/post_max_size = 80M/g" /etc/php/7.1/fpm/php.ini

# Silent MySQL Install
# http://stackoverflow.com/questions/7739645/install-mysql-on-ubuntu-without-password-prompt
echo "--- Master, it's MySQL time ---"
sudo apt-get update
sudo debconf-set-selections <<< "mysql-server-5.6 mysql-server/root_password password $DBPASS"
sudo debconf-set-selections <<< "mysql-server-5.6 mysql-server/root_password_again password $DBPASS"
sudo -E apt-get install -q -y mysql-server-5.6

# Install Adminer
echo "--- Setup adminer for mysql administration. I hope you like it, my master. ---"
wget http://www.adminer.org/latest.php
mkdir /var/www/adminer
mv latest.php /var/www/adminer/index.php
chown -R www-data: /var/www/adminer
chmod 755 /var/www/adminer/index.php

# Setup the project database
echo "--- Setup database '$DBNAME' ---"
echo "CREATE DATABASE $DBNAME;" | mysql -u root -p$DBPASS

# virtual host setup
echo "--- Setting document root for project ---"
sudo rm -rf /var/www/html
sudo ln -fs /vagrant/public /var/www/htdocs

# setup hosts file
VHOST=$(cat <<EOF
<IfModule mod_fastcgi.c>
AddHandler php7-fcgi .php
Action php7-fcgi /php7-fcgi
Alias /php7-fcgi /usr/lib/cgi-bin/php7-fcgi
FastCgiExternalServer /usr/lib/cgi-bin/php7-fcgi -socket /var/run/php/php7.1-fpm.sock -pass-header Authorization
</IfModule>
<VirtualHost *:80>
DocumentRoot "/var/www/htdocs"
<Directory "/var/www/htdocs">
AllowOverride All
Require all granted
</Directory>
<Directory /usr/lib/cgi-bin>
Require all granted
</Directory>
</VirtualHost>
Listen 81
<VirtualHost *:81>
DocumentRoot "/var/www/adminer"
<Directory "/var/www/adminer">
AllowOverride All
Require all granted
</Directory>
<Directory /usr/lib/cgi-bin>
Require all granted
</Directory>
</VirtualHost>
EOF
)
echo "${VHOST}" > /etc/apache2/sites-available/000-default.conf

sudo a2enmod rewrite
sudo service apache2 restart

# Install git
sudo apt-get install -y git

# Clean up old packages
sudo apt-get -y autoremove

# Install Composer
echo "--- Composer is the future. But you knew that, did you master? Nice job. ---"
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
sudo chmod 755 /usr/local/bin/composer

echo "--- Load a fresh new laravel installation ---"
cd /vagrant/
composer create-project --prefer-dist laravel/laravel laravel
cd /vagrant/laravel
mv * .[^.]* ..
cd ..
rm -r laravel

sudo chmod -R 777 /vagrant/storage/

echo "--- Make laravel work with current MYSQL version. Have a look at AppServiceProvider for more information on this. ---"
cat > /vagrant/app/Providers/AppServiceProvider.php <<- "EOF"
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
// @see https://laravel-news.com/laravel-5-4-key-too-long-error
// required for our server and mysql setup
Schema::defaultStringLength(191);
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
}
EOF

echo "--- Start setting up environment specific configuration values for our laravel application. ---"
echo "--- First, set laravel database credentials. ---"

sed -i "s/DB_DATABASE=homestead/DB_DATABASE=$DBNAME/" /vagrant/.env
sed -i "s/DB_USERNAME=homestead/DB_USERNAME=root/" /vagrant/.env
sed -i "s/DB_PASSWORD=secret/DB_PASSWORD=$DBPASS/" /vagrant/.env

echo "--- Let's setup the laravel auth service for this project, my master. ---"

cd /vagrant/
php artisan make:auth
php artisan migrate

echo "--- All set to go! Would you like to play a game? ---"
15 changes: 6 additions & 9 deletions boilerplates/lamp/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

config.vm.box = "ubuntu/trusty32"

config.vm.network :forwarded_port, guest: 80, host: 8080
Expand All @@ -13,14 +14,10 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.provision :shell, :path => "install.sh"

config.vm.synced_folder ".", "/vagrant", :mount_options => ["dmode=777", "fmode=766"]

# set to 1024 minimum to make mysql server version 5.6 work in vm
config.vm.provider "virtualbox" do |v|
v.memory = 1024
end

# If true, then any SSH connections made will enable agent forwarding.
# Default value: false
# config.ssh.forward_agent = true

# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"
end
6 changes: 3 additions & 3 deletions boilerplates/lamp/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->

<div class="container-fluid">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="col-md-12 text-center">

<div class="alert alert-info" role="alert">
Congratulations! Your vagrant VM is up and running with
<ul>
<li>the latest version of PHP 5.*</li>
<li>the latest version of PHP 7.*</li>
<li>the Apache webserver</li>
<li>a MYSQL database <i>development</i> with username and password <i>root</i></li>
</ul>
Expand Down
Loading

0 comments on commit d948def

Please sign in to comment.