├── .gitignore ├── README.md ├── Vagrantfile ├── config ├── config.yaml ├── puppet │ ├── manifests │ │ └── default.pp │ └── modules │ │ ├── apache │ │ └── manifests │ │ │ └── init.pp │ │ ├── composer │ │ └── manifests │ │ │ └── init.pp │ │ ├── mysql │ │ └── manifests │ │ │ └── init.pp │ │ ├── php │ │ └── manifests │ │ │ └── init.pp │ │ ├── phpmyadmin │ │ └── manifests │ │ │ └── init.pp │ │ ├── services │ │ └── manifests │ │ │ └── init.pp │ │ ├── ssmtp │ │ └── manifests │ │ │ └── init.pp │ │ └── syspackages │ │ └── manifests │ │ └── init.pp └── shell │ ├── default.sh │ ├── info.txt │ └── ready.txt └── www └── default ├── index.php ├── phpinfo.php └── vhosts.txt /.gitignore: -------------------------------------------------------------------------------- 1 | ### Project ### 2 | www/* 3 | !www/default/ 4 | 5 | ### Vagrant ### 6 | .vagrant 7 | 8 | ### Windows ### 9 | Thumbs.db 10 | Desktop.ini 11 | $RECYCLE.BIN/ 12 | 13 | ### OSX ### 14 | .DS_Store 15 | .AppleDouble 16 | .LSOverride 17 | Icon 18 | ._* 19 | .Spotlight-V100 20 | .Trashes 21 | 22 | ### IntelliJ based IDE's like PhpStorm ### 23 | *.iml 24 | *.ipr 25 | *.iws 26 | .idea/ 27 | 28 | ### NetBeans ### 29 | nbproject/ 30 | build/ 31 | nbbuild/ 32 | dist/ 33 | nbdist/ 34 | nbactions.xml 35 | nb-configuration.xml 36 | build.xml 37 | build.properties 38 | 39 | ### SublimeText ### 40 | *.sublime-workspace 41 | 42 | # Much credit to http://gitignore.io for many of these -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | cptserver 2 | ========= 3 | 4 | A student web development environment using Vagrant, Virtualbox, and Puppet. 5 | 6 | Virtualbox is software that lets you create virtual machines, allowing you to run another operating system in a sandbox. Vagrant is used to customize, load, and access that virtual machine. Once it's running, Puppet is used to manage the software on the virtual machine. Puppet makes sure things like Apache and MySQL are installed, running as a service, configured properly, and restarted when necessary. 7 | 8 | All together, this creates an Ubuntu LAMP webserver that can be run on your current computer, whether it be Windows, Apple OSX, or Linux itself. Many developers prefer this type of environment instead of installing something like WAMP, XAMPP, or MAMP. One major benefit is that it doesn't interfere with your current computer. Another is that when on a team or in a class, everybody could be developing on the exact same environment with the same versions of all software. 9 | 10 | Features 11 | -------- 12 | 13 | * It uses a single config file for everything. No need to dig into Puppet code to customize. 14 | * It adds a repository that will give you the latest PHP (5.6+) and Apache (2.4+). 15 | * It installs phpMyAdmin for you so that you can manage databases. 16 | * It also configures MySQL so that you can use local DB software on your computer, like MySQL Workbench. 17 | * It installs Composer globally in your path for you to easily manage PHP dependencies. 18 | * It installs and configures Xdebug so that you may debug with local IDEs, like PHPStorm and Netbeans. 19 | * It allows you to configure PHP error reporting levels. 20 | * It sets up SSL with a self-signed certificate so you can develop for HTTPS. 21 | 22 | Installation 23 | -------- 24 | 25 | These steps should get you going, but I've also created a video too: https://www.youtube.com/watch?v=TEAZnpM8RuA 26 | 27 | 1. First, install Virtualbox, then Vagrant. You don't need Puppet on your host computer; it will exist on the linux virtual machine. After installing Vagrant, you'll need to reboot. 28 | * Virtualbox - https://www.virtualbox.org/wiki/Downloads 29 | * Vagrant - http://www.vagrantup.com/ 30 | 2. Next, download this repository. You could just download the .zip file and extract it where you keep your work, but cloning with Git is preferred. If you haven't learned Git yet, you really should. 31 | * Git - http://git-scm.com/downloads 32 | * Go to your project folder (on Windows, it's probably something like 'C:\Users\Scott\Documents\'), open a terminal/command prompt there, and type `git clone https://github.com/pigeontech/cptserver.git`. 33 | * This creates a copy on your computer, like 'C:\Users\Scott\Documents\cptserver\'. Go into that folder. 34 | 3. Open the config/config.yaml file in a text editor, and change anything that you feel needs changed. Right now, the only thing that probably matters is the default mysql password for "root" and email SMTP server settings so your websites can send email. You can add virtual hosts later. Also, if your computer is already using port 80, like if you run a media server to stream movies to your TV, you might need to change port 80 to something else, like 8080. 35 | 4. Reopen the terminal if you closed it, and go into the cptserver folder that Git made for you. If you left it open (good idea), just type `cd cptserver`. 36 | 5. Now type `vagrant up`. 37 | * It will streamline the entire process for you, from creating the virtual machine to installing PHP and its modules. 38 | * The first time you run it, it will be slow, because it must download and install a linux box, which is a few hundred mb. 39 | 6. It's ready. Inside the `www/default/` folder is a sample website. Open your browser and go to `http://localhost` and see if it works. Check out `http://localhost/phpmyadmin` as well, and try logging with the username `root` and the password you set in the config.yaml file. If you changed the port, these URLs would look like `http://localhost:8080` and `http://localhost:8080/phpmyadmin`. 40 | 41 | Virtual Hosts 42 | --------- 43 | 44 | You will probably build more than one website. Using `http://dev/foldername` is too ugly. So we use virtual hosts. A few have already been created in the config.yaml file. There is another step you must do though. On your actual computer, you have to edit the `hosts` file. On Windows, it's located at `C:\Windows\System32\drivers\etc`. You may need to open Notepad with admin privilages for it to allow you to save changes. 45 | 46 | Make the file look something like this: 47 | ``` 48 | 127.0.0.1 localhost localhost.dev www.localhost.dev 49 | 127.0.0.1 default default.dev www.default.dev 50 | 127.0.0.1 dev dev.dev www.dev.dev 51 | ``` 52 | 53 | By looking at config.yaml, you'll see that the `localhost` and `default` URLs all route to a folder named `default`, and the `dev` URLs route to the entire `www` directory listing. If you didn't add a custom localhost for a site you're building, like `wordpress` that routes to a `blog` folder, you could still access the `blog` folder via `http://dev/blog`. 54 | 55 | More Vagrant Commands 56 | --------- 57 | 58 | These are more commands you'll need. As before, make sure the terminal is open in the root of the cptserver folder. 59 | 60 | * `vagrant provision` 61 | * Any time you make changes to the config.yaml file, like adding a vhost you need to run this command. 62 | * `vagrant reload --provision` 63 | * If you make changes in top (vagrant) portion of the config.yaml, you need to run this. 64 | * `vagrant halt` 65 | * This is how you turn it off when you're done. Your computer won't go into sleep mode when a virtual machine is running. 66 | * `vagrant up` 67 | * Ready to start working on your website again? Run this. 68 | * `vagrant destroy` 69 | * This will completely wipe out the linux installation and delete the virtual machine. Use with great caution, as you'll lose your databases. Only run this command if things are broken, you're lost, and you want to start over. 70 | * `vagrant ssh` 71 | * Once you're up and running, this is a command you'll use most often. It lets you into Ubuntu, as if you were really sitting at the computer terminal. From here, you can run commands like `sudo apt-get install `. Often, you'll want to immediately go into the web root with `cd /var/www`. Any changes made here are also mirrored on your host computer's www folder. Try it! If you're not familiar with the linux file structure, it's worth doing a Google search. When you're readty to go back to your normal computer's terminal, type `exit`. 72 | 73 | Composer 74 | ---------- 75 | Composer is a dependency manager for common libraries, such as the popular Laravel framework, or the PHPUnit testing library. It will automatically download the latest/specified version of them, as well as any dependencies that they rely on. It will then create an autoload.php file, which you include into your actual project to load the library and dependencies. Composer, like Git, is one of those technologies that separates the new school from the old school. Don't get left behind! It's more important than ever for web developers to become familiar with these command line tools. 76 | 77 | 1. Log in via `vagrant ssh` and navigate to your website folder, such as `cd /var/www/mywebsite`. 78 | 2. Create a `composer.json` file in the same place containing the following: 79 | 80 | ``` 81 | { 82 | "require-dev": { 83 | "phpunit/phpunit": "3.7.14" 84 | } 85 | } 86 | ``` 87 | 88 | Don't make things difficult. You don't have to use Vi or Nano to create and edit this file. You can do this step on your normal computer with Sublime Text, Notepad, etc. Remember that the www folder is shared between your computer and the vm. Changes to one happen to both. That's the whole point of using Vagrant! 89 | 3. Back to the terminal, type `composer install`. This will create a `vendor` folder, download all of the software packages you specified in the json file, and also download their dependencies. For example, if you specify PHPUnit as above, your project and vendor folder will look like this: 90 | 91 | ``` 92 | - \var\www\mywebsite 93 | -- vendor 94 | -- composer.json 95 | -- composer.lock 96 | -- composer.phar 97 | -- index.php 98 | 99 | - \var\www\mywebsite\vendor 100 | -- bin 101 | -- composer 102 | -- phpunit 103 | -- symfony 104 | -- autoload.php 105 | ``` 106 | 4. Now in your index.php file, you'd put something like `require 'vendor/autoload.php';`. 107 | 5. Keep in mind that you need to do all of these steps for each website you build. Composer is dependency managment on a per project basis. So if you create another website, like `\var\www\lolcatpics`, it will need its own composor.json, and you'll need to run `composer install` in that directory, and a vendor folder will be created. 108 | 6. Visit the following websites to learn more about fitting these tools into your workflow: 109 | * http://daylerees.com/composer-primer 110 | * https://www.digitalocean.com/community/articles/how-to-install-and-use-composer-on-your-vps-running-ubuntu 111 | * https://jtreminio.com/2013/03/unit-testing-tutorial-introduction-to-phpunit/ 112 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | #################################### 2 | ### Load Configuration Variables 3 | #################################### 4 | require 'yaml' 5 | $vconfig = YAML::load_file("config/config.yaml") 6 | 7 | # Handle directory 8 | def getDirectory(directory, tabs) 9 | 10 | if tabs == 2 11 | tabs = "\t" 12 | else 13 | tabs = "" 14 | end 15 | 16 | rewrite = "\n\t"+tabs+"\n" 17 | $vconfig['directory'].each_with_index do |val, key| 18 | rewrite = rewrite + "\t\t"+ tabs + val + "\n" 19 | end 20 | rewrite = rewrite+"\t"+tabs+"\n" 21 | return rewrite 22 | end 23 | 24 | # Handle email 25 | email = "" 26 | $vconfig['email'].each do |k, v| 27 | email = email+k+"="+v+"\n" 28 | end 29 | 30 | # Handle vhosts 31 | vhosts = "" 32 | $vconfig['vhosts'].each_with_index do |v, k| 33 | vhosts = vhosts + "\n" + getDirectory(v['DocumentRoot'],1) + "\n" 34 | v.each_with_index do |val, key| 35 | vhosts = vhosts + "\t" + val.join(' ') + "\n" 36 | end 37 | vhosts = vhosts + "\n\n\n" 38 | end 39 | 40 | # Handle vhostsssl 41 | vhostsssl = "\n\n" 42 | $vconfig['vhosts'].each_with_index do |v, k| 43 | vhostsssl = vhostsssl + "\t\n" + getDirectory(v['DocumentRoot'],2) + "\n" 44 | v.each_with_index do |val, key| 45 | vhostsssl = vhostsssl + "\t\t" + val.join(' ') + "\n" 46 | end 47 | vhostsssl = vhostsssl + "\n\t\tErrorLog ${APACHE_LOG_DIR}/error.log\n\t\tCustomLog ${APACHE_LOG_DIR}/access.log combined\n\n\t\tSSLEngine on\n\n\t\tSSLCertificateFile /etc/apache2/ssl/apache.crt\n\t\tSSLCertificateKeyFile /etc/apache2/ssl/apache.key\n\n\t\t\n\t\t\tSSLOptions +StdEnvVars\n\t\t\n\n\t\t\n\t\t\tSSLOptions +StdEnvVars\n\t\t\n\n\t\n\n" 48 | end 49 | vhostsssl = vhostsssl + "\n" 50 | 51 | # Openssl args 52 | opensslargs = "" 53 | $vconfig['ssl'].each do |k, v| 54 | opensslargs = opensslargs+v+'\n' 55 | end 56 | 57 | #################################### 58 | ### Running Vagrant 59 | #################################### 60 | Vagrant.configure("2") do |config| 61 | config.vagrant.host = :detect 62 | config.ssh.shell = $vconfig['vagrant']['ssh_shell'] 63 | config.ssh.username = $vconfig['vagrant']['ssh_username'] 64 | config.ssh.keep_alive = true 65 | 66 | #################################### 67 | ### Machine Setup 68 | #################################### 69 | config.vm.box = $vconfig['vagrant']['box'] 70 | config.vm.box_url = $vconfig['vagrant']['box_url'] 71 | config.vm.network "private_network", ip: $vconfig['vagrant']['box_ip'] 72 | config.vm.hostname = $vconfig['vagrant']['vm_hostname'] 73 | config.vm.network "forwarded_port", guest: 80, host: $vconfig['vagrant']['box_port'] 74 | config.vm.network "forwarded_port", guest: 3306, host: $vconfig['mysql']['port'] 75 | config.vm.network "forwarded_port", guest: 443, host: $vconfig['vagrant']['box_port_ssl'] 76 | config.vm.synced_folder $vconfig['vagrant']['vm_webroot'], $vconfig['vagrant']['vm_docroot'], :owner => "vagrant", :group => "www-data", :mount_options => ["dmode=777","fmode=777"] 77 | 78 | #################################### 79 | ### VirtualBox Provider 80 | #################################### 81 | config.vm.provider "virtualbox" do |virtualbox| 82 | virtualbox.customize ["modifyvm", :id, "--cpuexecutioncap", $vconfig['vagrant']['vm_cpu']] 83 | virtualbox.customize ["modifyvm", :id, "--name", $vconfig['vagrant']['vm_name']] 84 | virtualbox.customize ["modifyvm", :id, "--natdnshostresolver1", "on"] 85 | virtualbox.customize ["modifyvm", :id, "--memory", $vconfig['vagrant']['vm_memory']] 86 | virtualbox.customize ["modifyvm", :id, "--rtcuseutc", "on"] 87 | virtualbox.customize ["setextradata", :id, "--VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"] 88 | end 89 | 90 | #################################### 91 | ### Shell Provisioning 92 | #################################### 93 | config.vm.provision "shell" do |s| 94 | s.path = "config/shell/default.sh" 95 | end 96 | 97 | #################################### 98 | ### Puppet Provisioning 99 | #################################### 100 | config.vm.provision "puppet" do |puppet| 101 | puppet.facter = { 102 | "ssh_username" => $vconfig['vagrant']['ssh_username'], 103 | "fqdn" => $vconfig['vagrant']['vm_hostname'], 104 | "syspackages" => $vconfig['syspackages'].join(','), 105 | "apachemodules" => $vconfig['apachemodules'].join(','), 106 | "phpmodules" => $vconfig['phpmodules'].join(','), 107 | "vhostsphp" => $vconfig['vhosts'].join(','), 108 | "vhosts" => vhosts, 109 | "vhostsssl" => vhostsssl, 110 | "opensslargs" => opensslargs, 111 | "email" => email, 112 | "xdebug" => $vconfig['xdebug'].join("\n")+"\n", 113 | "errors" => $vconfig['errors'].join("\n")+"\n", 114 | "password" => $vconfig['mysql']['password'], 115 | } 116 | puppet.options = "--verbose" 117 | puppet.manifests_path = "config/puppet/manifests" 118 | puppet.manifest_file = "default.pp" 119 | puppet.module_path = "config/puppet/modules" 120 | end 121 | 122 | #################################### 123 | ### Run SQL 124 | #################################### 125 | config.vm.provision "shell", 126 | inline: "mysql -uroot -p"+$vconfig['mysql']['password']+" < '/etc/mysql/remote.sql'" 127 | 128 | #################################### 129 | ### Ready 130 | #################################### 131 | config.vm.provision "shell", 132 | inline: "cat /vagrant/config/shell/ready.txt" 133 | end -------------------------------------------------------------------------------- /config/config.yaml: -------------------------------------------------------------------------------- 1 | #################################### 2 | ### Virtual Machine 3 | ### 4 | ### Only change these if you are experienced with VMs or are instructed to do so. 5 | #################################### 6 | vagrant: 7 | box: ubuntu/trusty32 8 | box_url: https://atlas.hashicorp.com/ubuntu/boxes/trusty32/versions/14.04/providers/virtualbox.box 9 | box_port: 80 10 | box_port_ssl: 443 11 | box_ip: 10.0.0.123 12 | ssh_shell: bash -c 'BASH_ENV=/etc/profile exec bash' 13 | ssh_username: vagrant 14 | vm_name: cptserver 15 | vm_memory: 512 16 | vm_cpu: 80 17 | vm_webroot: www 18 | vm_docroot: /var/www 19 | vm_hostname: localhost 20 | 21 | #################################### 22 | ### Ubuntu Linux 23 | ### 24 | ### These packages install before anything else via apt-get. You may add some, but you shouldn't remove any or install one that uninstalls another. 25 | #################################### 26 | syspackages: 27 | - build-essential 28 | - openssl 29 | - unzip 30 | - git 31 | - curl 32 | - php5-dev 33 | - php-pear 34 | - libyaml-dev 35 | - libgnutls-openssl27 36 | - libgnutls26 37 | - ssmtp 38 | 39 | #################################### 40 | ### Email 41 | ### 42 | ### These settings work for gmail. Just change your email address in 'root' and 'AuthUser', and password in 'AuthPass'. 43 | ### If using a different SMTP server (your school, company, etc), you'll need to change 'mailhub' and 'rewriteDomain' and possibly the two 'Use*' lines too. 44 | ### More info: http://manpages.ubuntu.com/manpages/utopic/man5/ssmtp.conf.5.html 45 | ### 46 | ### The "Real Name" that shows in front of the "from email" will be "vagrant" unless you change it in the header when sending. 47 | ### Do "vagrant ssh" and paste the following command to test sending: php -r 'mail("recipient@gmail.com", "The Subject", "The Body", "From: Real Name");' 48 | ### In the above test, be sure to change the recipient to a real email you own so you can check if it worked! 49 | #################################### 50 | email: 51 | mailhub: smtp.gmail.com:587 52 | hostname: localhost 53 | rewriteDomain: gmail.com 54 | root: username@gmail.com 55 | AuthUser: username@gmail.com 56 | AuthPass: hunter2 57 | UseSTARTTLS: 'YES' 58 | UseTLS: 'YES' 59 | FromLineOverride: 'YES' 60 | 61 | #################################### 62 | ### Modules 63 | ### 64 | ### Some default modules for a well-rounded Apache and PHP setup. You may add others. 65 | #################################### 66 | apachemodules: 67 | - rewrite 68 | - ssl 69 | phpmodules: 70 | - php5-cli 71 | - php5-mysql 72 | - php5-sqlite 73 | - php5-imagick 74 | - php5-mcrypt 75 | - php5-imap 76 | - php5-curl 77 | - php5-gd 78 | - php5-xmlrpc 79 | - php5-xdebug 80 | - libapache2-mod-php5 81 | 82 | #################################### 83 | ### Database 84 | ### 85 | ### For username "root". You have only one chance to change the root password. Do it before typing "vagrant up" for the first time. 86 | #################################### 87 | mysql: 88 | port: 3306 89 | password: vagrant 90 | 91 | #################################### 92 | ### SSL Certificate 93 | ### 94 | ### You'll get a security warning in the browser when testing https sites you build, but it will work. You can customize this info, but it's not crucial as you're the only one who sees it. 95 | #################################### 96 | ssl: 97 | country: US 98 | state: Pennsylvania 99 | city: Pittsburgh 100 | company: Fake Company 101 | section: Information Technology 102 | domain: 127.0.0.1 103 | email: fake@example.com 104 | 105 | #################################### 106 | ### Debugging 107 | ### 108 | ### Errors are for the way PHP displays errors, like what should happen if you try to echo out an unset variable. 109 | ### Xdebug should only be customized if your IDE doesn't work with these default settings. 110 | #################################### 111 | errors: 112 | - display_errors = On 113 | - error_reporting = E_ALL 114 | - display_startup_errors = On 115 | - log_errors = On 116 | - log_errors_max_len = 1024 117 | - ignore_repeated_errors = Off 118 | - ignore_repeated_source = Off 119 | - report_memleaks = On 120 | - html_errors = On 121 | - docref_root = "http://www.php.net/manual/en/" 122 | - docref_ext = .php 123 | - error_log = /var/log/php_errors.log 124 | - error_prepend_string = "" 125 | - error_append_string = "" 126 | xdebug: 127 | - zend_extension = xdebug.so 128 | - xdebug.remote_enable = 1 129 | - xdebug.remote_host = localhost 130 | - xdebug.remote_port = 9000 131 | - xdebug.remote_connect_back = 1 132 | - xdebug.remote_handler = dbgp 133 | - xdebug.remote_mode = req 134 | - xdebug.remote_log = /var/log/php5-xdebug.log 135 | - xdebug.profiler_enable = 0 136 | - xdebug.profiler_output_dir = /tmp 137 | - xdebug.profiler_output_name = cachegrind.out.%t.%p 138 | 139 | #################################### 140 | ### Directory Rules 141 | ### 142 | ### Some rules for Apache. You shouldn't need to change these unless you have problems with .htaccess files. 143 | #################################### 144 | directory: 145 | - Options Indexes FollowSymLinks MultiViews 146 | - AllowOverride All 147 | - Order allow,deny 148 | - Allow from all 149 | 150 | #################################### 151 | ### Virtual Hosts 152 | ### 153 | ### Vhosts let you set up nicer URLs instead of using http://dev/foldername all the time. 154 | ### 155 | ### Be sure to mirror changes here in your computer's hosts file too! 156 | ### Windows: C:\Windows\System32\Drivers\etc\hosts (Open your text editor as Administrator first (Right click and choose "Run as administrator")) 157 | ### OSX: sudo nano /private/etc/hosts (From the terminal) 158 | ### 159 | ### Open the hosts file and make it look something like: 160 | ### 127.0.0.1 localhost localhost.dev www.localhost.dev default default.dev www.default.dev 161 | ### 127.0.0.1 dev dev.dev www.dev.dev 162 | ### 127.0.0.1 anothersite anothersite.dev www.anothersite.dev 163 | ### 164 | ### Because localhost is mapped to an example default site, it's crucial you add dev to the hosts file (As demonstrated above) to access folders that don't have a vhost. 165 | ### Also don't forget to run "vagrant provision" for any changes. 166 | #################################### 167 | vhosts: 168 | - 169 | ServerName: localhost 170 | ServerAlias: localhost.dev www.localhost.dev default default.dev www.default.dev 171 | DocumentRoot: /var/www/default 172 | ServerAdmin: webmaster@localhost 173 | - 174 | ServerName: dev 175 | ServerAlias: dev.dev www.dev.dev 176 | DocumentRoot: /var/www 177 | ServerAdmin: webmaster@localhost -------------------------------------------------------------------------------- /config/puppet/manifests/default.pp: -------------------------------------------------------------------------------- 1 | #################################### 2 | ### Default Paths 3 | #################################### 4 | Exec 5 | { 6 | path => ["/usr/bin", "/bin", "/usr/sbin", "/sbin", "/usr/local/bin", "/usr/local/sbin"] 7 | } 8 | 9 | #################################### 10 | ### Build Arrays 11 | #################################### 12 | $syspackages_arr = split($syspackages,',') 13 | $apachemodules_arr = split($apachemodules,',') 14 | $phpmodules_arr = split($phpmodules,',') 15 | 16 | 17 | 18 | #################################### 19 | ### Class Declarations 20 | #################################### 21 | 22 | class 23 | { 24 | 'syspackages': 25 | syspackages_arr => $syspackages_arr, 26 | startmsg => "\n\n################## System Setup ##################\n\n" 27 | } 28 | 29 | class 30 | { 31 | 'apache': 32 | apachemodules_arr => $apachemodules_arr, 33 | vhosts => $vhosts, 34 | vhostsssl => $vhostsssl, 35 | startmsg => "\n\n################## Apache Setup ##################\n\n", 36 | opensslargs => $opensslargs, 37 | require => Class['syspackages'] 38 | } 39 | 40 | class 41 | { 42 | 'php': 43 | phpmodules_arr => $phpmodules_arr, 44 | xdebug => $xdebug, 45 | errors => $errors, 46 | vhostsphp => $vhostsphp, 47 | startmsg => "\n\n################## PHP Setup ##################\n\n", 48 | require => Class['apache'] 49 | } 50 | 51 | class 52 | { 53 | 'ssmtp': 54 | email => $email, 55 | startmsg => "\n\n################## Email Setup ##################\n\n", 56 | require => Class['php'] 57 | } 58 | 59 | class 60 | { 61 | 'mysql': 62 | password => $password, 63 | startmsg => "\n\n################## MySQL Setup ##################\n\n", 64 | require => Class['ssmtp'] 65 | } 66 | 67 | class 68 | { 69 | 'phpmyadmin': 70 | startmsg => "\n\n################## phpMyAdmin Setup ##################\n\n", 71 | require => Class['mysql'] 72 | } 73 | 74 | class 75 | { 76 | 'composer': 77 | startmsg => "\n\n################## Composer Setup ##################\n\n", 78 | require => Class['phpmyadmin'] 79 | } -------------------------------------------------------------------------------- /config/puppet/modules/apache/manifests/init.pp: -------------------------------------------------------------------------------- 1 | class apache ($apachemodules_arr, $vhosts, $vhostsssl, $startmsg, $opensslargs) 2 | { 3 | #################################### 4 | ### Apache 5 | #################################### 6 | 7 | notify 8 | { 9 | 'msg_apache': 10 | message => "${startmsg}", 11 | loglevel => info 12 | } 13 | 14 | # Install Apache 15 | package 16 | { 17 | "apache": 18 | name => "apache2", 19 | ensure => latest, 20 | require => Notify['msg_apache'] 21 | } 22 | 23 | # Run Apache as a service, have it restart if those files change 24 | include ::services 25 | 26 | # Ensure rewrite link 27 | file 28 | { 29 | "/etc/apache2/mods-enabled/rewrite.load": 30 | ensure => link, 31 | target => "/etc/apache2/mods-available/rewrite.load", 32 | require => Package['apache'], 33 | notify => Service['apache'] 34 | } 35 | 36 | # Update the vhosts file 37 | file 38 | { 39 | "/etc/apache2/sites-available/000-default.conf": 40 | ensure => present, 41 | require => Package['apache'], 42 | content => "${vhosts}", 43 | notify => Service['apache'] 44 | } 45 | 46 | # Update ssl vhosts file 47 | file 48 | { 49 | "/etc/apache2/sites-available/default-ssl.conf": 50 | ensure => present, 51 | require => Package['apache'], 52 | content => "${vhostsssl}", 53 | notify => Service['apache'] 54 | } 55 | 56 | # Load Apache modules 57 | define apache::loadmodule ($modname = $title) { 58 | exec { 59 | "/usr/sbin/a2enmod ${modname}": 60 | unless => "/bin/readlink -e /etc/apache2/mods-enabled/${modname}.load", 61 | require => Package['apache'], 62 | notify => Service['apache'] 63 | } 64 | } 65 | 66 | apache::loadmodule{$apachemodules_arr: } 67 | 68 | # enable default-ssl.conf 69 | exec { 70 | "default-ssl": 71 | command => "a2ensite default-ssl", 72 | unless => "/bin/readlink -e /etc/apache2/sites-enabled/default-ssl.conf", 73 | require => Package['apache'], 74 | notify => Service['apache'] 75 | } 76 | 77 | file 78 | { 79 | "/var/www/html": 80 | ensure => absent, 81 | require => Exec['default-ssl'], 82 | force => true 83 | } 84 | 85 | file { 86 | "/etc/apache2/ssl": 87 | ensure => directory, 88 | require => Package['apache'] 89 | } 90 | 91 | # Get rid of the "It works!" file Apache installs 92 | file { 93 | "/var/www/index.html": 94 | ensure => absent, 95 | require => Package['apache'] 96 | } 97 | 98 | # create ssl certificate and key 99 | exec { 100 | "cert-key": 101 | command => "echo \"${opensslargs}\" | openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt", 102 | require => [Package['apache'], File['/etc/apache2/ssl']], 103 | returns => [0,1], 104 | notify => Service['apache'] 105 | } 106 | } -------------------------------------------------------------------------------- /config/puppet/modules/composer/manifests/init.pp: -------------------------------------------------------------------------------- 1 | class composer ($startmsg) 2 | { 3 | #################################### 4 | ### Composer 5 | #################################### 6 | 7 | notify 8 | { 9 | 'msg_composer': 10 | message => "${startmsg}", 11 | loglevel => info 12 | } 13 | 14 | # Download and add to path 15 | exec 16 | { 17 | "composer": 18 | command => "curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/local/bin/composer", 19 | require => Notify['msg_composer'] 20 | } 21 | 22 | # Add composer/vender/bin to path 23 | file 24 | { 25 | "/etc/profile.d/composer.sh": 26 | mode => 0644, 27 | content => 'export PATH="~/.composer/vendor/bin:$PATH"', 28 | require => Exec['composer'] 29 | } 30 | } -------------------------------------------------------------------------------- /config/puppet/modules/mysql/manifests/init.pp: -------------------------------------------------------------------------------- 1 | class mysql ($password, $startmsg) 2 | { 3 | #################################### 4 | ### MySQL 5 | #################################### 6 | 7 | $sqlaccess = "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '$password';\nFLUSH PRIVILEGES;" 8 | 9 | notify 10 | { 11 | 'msg_mysql': 12 | message => "${startmsg}", 13 | loglevel => info 14 | } 15 | 16 | # Install MySQL server 17 | package 18 | { 19 | "mysql": 20 | name => "mysql-server", 21 | ensure => latest, 22 | require => Notify['msg_mysql'] 23 | } 24 | 25 | # Install MySQL client 26 | package 27 | { 28 | "mysql-client": 29 | ensure => latest, 30 | require => Package['mysql'] 31 | } 32 | 33 | # Declare file resource so the service can subscribe to changes 34 | file 35 | { 36 | '/etc/mysql/my.cnf': 37 | ensure => present, 38 | require => Package["mysql"] 39 | } 40 | 41 | # Create an SQL file that we need. 42 | file 43 | { 44 | '/etc/mysql/remote.sql': 45 | ensure => present, 46 | require => Package["mysql"], 47 | content => $sqlaccess 48 | } 49 | 50 | # Run MySQL as a service 51 | service 52 | { 53 | "mysql": 54 | enable => true, 55 | ensure => running, 56 | require => [File["/etc/mysql/my.cnf"], File["/etc/mysql/remote.sql"]], 57 | subscribe => [ 58 | File["/etc/mysql/my.cnf"], 59 | File["/etc/mysql/remote.sql"] 60 | ], 61 | } 62 | 63 | # If it's the first run, set the password from config 64 | exec 65 | { 66 | "root-setup": 67 | command => "mysqladmin -uroot password ${password}", 68 | unless => "mysqladmin -uroot -p${password} status", 69 | require => Service['mysql'] 70 | } 71 | 72 | # Make sure bind-address is commented out 73 | exec 74 | { 75 | "bind-address": 76 | command => 'sed -i "s/^bind-address/#bind-address/" /etc/mysql/my.cnf', 77 | require => File["/etc/mysql/my.cnf"] 78 | } 79 | } -------------------------------------------------------------------------------- /config/puppet/modules/php/manifests/init.pp: -------------------------------------------------------------------------------- 1 | class php ($phpmodules_arr, $xdebug, $errors, $vhostsphp, $startmsg) 2 | { 3 | #################################### 4 | ### PHP 5 | #################################### 6 | 7 | include ::services 8 | 9 | notify 10 | { 11 | 'msg_php': 12 | message => "${startmsg}", 13 | loglevel => info 14 | } 15 | 16 | # Install PHP 17 | package 18 | { 19 | 'php': 20 | name => "php5", 21 | ensure => latest, 22 | require => Notify['msg_php'] 23 | } 24 | 25 | # Install PHP Modules 26 | define php::loadmodule ($modname = $title) { 27 | package 28 | { 29 | $modname: 30 | ensure => latest, 31 | require => Package["php"], 32 | } 33 | } 34 | 35 | php::loadmodule{$phpmodules_arr: } 36 | 37 | # Add some custom xdebug ini settings to override any in php.ini 38 | file 39 | { 40 | '/etc/php5/mods-available/xdebug.ini': 41 | ensure => present, 42 | require => Package["php"], 43 | content => "${xdebug}", 44 | notify => Service['apache'] 45 | } 46 | 47 | # Email 48 | file 49 | { 50 | '/etc/php5/mods-available/sendmail.ini': 51 | ensure => present, 52 | require => Package["php"], 53 | content => "sendmail_path = /usr/sbin/sendmail -t", 54 | notify => Service['apache'] 55 | } 56 | 57 | # Error settings 58 | file 59 | { 60 | '/etc/php5/mods-available/errors.ini': 61 | ensure => present, 62 | require => Package["php"], 63 | content => "${errors}", 64 | notify => Service['apache'] 65 | } 66 | 67 | # Error link 68 | file 69 | { 70 | "/etc/php5/apache2/conf.d/errors.ini": 71 | ensure => link, 72 | target => "/etc/php5/mods-available/errors.ini", 73 | require => Package['php'], 74 | notify => Service['apache'] 75 | } 76 | 77 | # Add a vhost file to our default website 78 | file 79 | { 80 | '/var/www/default/vhosts.txt': 81 | ensure => present, 82 | require => Package["php"], 83 | content => "${vhostsphp}" 84 | } 85 | } -------------------------------------------------------------------------------- /config/puppet/modules/phpmyadmin/manifests/init.pp: -------------------------------------------------------------------------------- 1 | class phpmyadmin ($startmsg) 2 | { 3 | #################################### 4 | ### phpMyAdmin 5 | #################################### 6 | 7 | include ::services 8 | 9 | notify 10 | { 11 | 'msg_phpmyadmin': 12 | message => "${startmsg}", 13 | loglevel => info 14 | } 15 | 16 | # Install phpMyAdmin 17 | package 18 | { 19 | "phpmyadmin": 20 | ensure => latest, 21 | require => Notify['msg_phpmyadmin'] 22 | } 23 | 24 | # Create vhost 25 | file 26 | { 27 | "/etc/apache2/conf-enabled/phpmyadmin.conf": 28 | ensure => link, 29 | target => "/etc/phpmyadmin/apache.conf", 30 | require => Package['phpmyadmin'], 31 | notify => Service['apache'] 32 | } 33 | } -------------------------------------------------------------------------------- /config/puppet/modules/services/manifests/init.pp: -------------------------------------------------------------------------------- 1 | class services () 2 | { 3 | #################################### 4 | ### Services 5 | #################################### 6 | 7 | service 8 | { 9 | "apache": 10 | name => apache2, 11 | enable => true, 12 | ensure => running, 13 | require => Package["apache"], 14 | } 15 | } -------------------------------------------------------------------------------- /config/puppet/modules/ssmtp/manifests/init.pp: -------------------------------------------------------------------------------- 1 | class ssmtp ($email, $startmsg) 2 | { 3 | #################################### 4 | ### ssmtp 5 | #################################### 6 | 7 | notify 8 | { 9 | 'msg_email': 10 | message => "${startmsg}", 11 | loglevel => info 12 | } 13 | 14 | # Update ssmtp file 15 | file 16 | { 17 | "/etc/ssmtp/ssmtp.conf": 18 | ensure => present, 19 | require => Notify['msg_email'], 20 | content => "${email}" 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /config/puppet/modules/syspackages/manifests/init.pp: -------------------------------------------------------------------------------- 1 | class syspackages ($syspackages_arr, $startmsg) 2 | { 3 | #################################### 4 | ### System Setup 5 | #################################### 6 | 7 | # Output start of this section 8 | notify 9 | { 10 | 'msg_syspackages': 11 | message => "${startmsg}", 12 | loglevel => info 13 | } 14 | 15 | exec 16 | { 17 | 'apt-get update': 18 | command => 'apt-get update', 19 | require => Notify['msg_syspackages'] 20 | } 21 | 22 | # This is needed for other repos 23 | package 24 | { 25 | 'python-software-properties': 26 | ensure => latest, 27 | require => Exec['apt-get update'], 28 | } 29 | 30 | # This is needed for other repos 31 | package 32 | { 33 | 'ppa-purge': 34 | ensure => latest, 35 | require => Package['python-software-properties'], 36 | } 37 | 38 | # Apache 2.4 repo 39 | exec 40 | { 41 | 'ondrej-apache': 42 | command => 'add-apt-repository -y ppa:ondrej/apache2', 43 | require => Package['ppa-purge'] 44 | } 45 | 46 | # PHP 5.6 repo 47 | exec 48 | { 49 | 'ondrej-php': 50 | command => 'add-apt-repository -y ppa:ondrej/php5-5.6', 51 | require => Exec['ondrej-apache'] 52 | } 53 | 54 | # Update list of packages again with new repos installed 55 | exec 56 | { 57 | 'apt-get update2': 58 | command => 'apt-get update', 59 | require => Exec['ondrej-php'] 60 | } 61 | 62 | # Install system packages 63 | define syspackages::loadmodule ($modname = $title) { 64 | package 65 | { 66 | $modname: 67 | ensure => latest, 68 | require => Exec['apt-get update2'], 69 | } 70 | } 71 | 72 | syspackages::loadmodule{$syspackages_arr: } 73 | } -------------------------------------------------------------------------------- /config/shell/default.sh: -------------------------------------------------------------------------------- 1 | cat /vagrant/config/shell/info.txt -------------------------------------------------------------------------------- /config/shell/info.txt: -------------------------------------------------------------------------------- 1 | 2 | ################################################# 3 | # | 4 | # ,---.,---.|--- ,---.,---.,---.. ,,---.,---. 5 | # | | || `---.|---'| \ / |---'| 6 | # `---'|---'`---'`---'`---'` `' `---'` 7 | # | 8 | ################################################# 9 | # github.com/pigeontech/cptserver 10 | ################################################# 11 | 12 | -------------------------------------------------------------------------------- /config/shell/ready.txt: -------------------------------------------------------------------------------- 1 | 2 | ################################################# 3 | # It is ready! 4 | ################################################# 5 | 6 | -------------------------------------------------------------------------------- /www/default/index.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CptServer 6 | 7 | 8 | 9 |

CptServer

10 |

11 | The installation was successful! 12 |

13 |

Useful Links

14 | 18 | 19 |

Your Websites

20 | 45 | After adding vhosts to config.yaml and your computer's hosts file, don't forget to run the command "vagrant provision" 46 | 47 | 48 | -------------------------------------------------------------------------------- /www/default/phpinfo.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /www/default/vhosts.txt: -------------------------------------------------------------------------------- 1 | {"ServerName"=>"localhost", "ServerAlias"=>"localhost.dev www.localhost.dev default default.dev www.default.dev", "DocumentRoot"=>"/var/www/default", "ServerAdmin"=>"webmaster@localhost"},{"ServerName"=>"dev", "ServerAlias"=>"dev.dev www.dev.dev", "DocumentRoot"=>"/var/www", "ServerAdmin"=>"webmaster@localhost"} --------------------------------------------------------------------------------