Skip to content
This repository was archived by the owner on Apr 13, 2019. It is now read-only.

Commit 3e59548

Browse files
Merge pull request #2 from eugene-manuilov/feature/custom-sites
Added ability to create custom sites
2 parents e21cc80 + e53a97b commit 3e59548

File tree

24 files changed

+151
-259
lines changed

24 files changed

+151
-259
lines changed

.gitignore

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
.vagrant/
2-
log/**/*.log
3-
www/default/memcached-admin/
4-
www/default/database-admin/
5-
www/default/webgrind/
6-
www/default/opcache-status/
7-
www/**/.phalcon
8-
www/**/cache/*.php
1+
/.vagrant/
2+
/log/**/*.log
3+
/www/
4+
!/www/default/index.php
5+
!/www/default/phpinfo.php
6+
/config/nginx-config/sites/
7+
!/config/nginx-config/sites/default.conf
8+
!/config/nginx-config/sites/local-nginx-example.conf-sample

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ The primary goal is to provide an approachable development environment with a mo
4343
* ***Note:*** If Vagrant is already installed, use `vagrant -v` to check the version. You may want to consider upgrading if a much older version is in use.
4444
1. Install the [vagrant-hostsupdater](https://github.com/cogitatio/vagrant-hostsupdater) plugin with `vagrant plugin install vagrant-hostsupdater`
4545
* Note: This step is not a requirement, though it does make the process of starting up a virtual machine nicer by automating the entries needed in your local machine's `hosts` file to access the provisioned domains in your browser.
46-
* If you choose not to install this plugin, a manual entry should be added to your local `hosts` file that looks like this: `192.168.50.99 phalcon-vm phalcon.dev`
46+
* If you choose not to install this plugin, a manual entry should be added to your local `hosts` file that looks like this: `192.168.50.99 phalcon-vm`
4747
1. Clone or extract the Phalcon VM project into a local directory
4848
* `git clone [email protected]:eugene-manuilov/phalcon-vm.git phalcon-vm`
4949
* OR download and extract the repository [zip file](https://github.com/eugene-manuilov/phalcon-vm/archive/master.zip) to a local directory on your computer.
@@ -52,9 +52,14 @@ The primary goal is to provide an approachable development environment with a mo
5252
* Be patient as the magic happens. This could take a while on the first run as your local machine downloads the required files.
5353
* Watch as the script ends, as an administrator or `su` ***password may be required*** to properly modify the hosts file on your local machine.
5454
1. Visit any of the following default sites in your browser:
55-
* [http://phalcon.dev/](http://phalcon.dev/) for Phalcon site
5655
* [http://phalcon-vm/](http://phalcon-vm/) for a default dashboard containing several useful tools
5756

57+
## Create Custom Site
58+
59+
You can easily create a new site by running `./bin/create-site` command. It will ask you a name for new site directory, its domain name and git repository for the project. Then it will halt vagrant, if it is running, and start it again with provisioning mode. In a few minutes you will get your site up and running again.
60+
61+
Please, pay attention to domain name question. The script allows you to enter space-separated list of domains which will be bound to your site. For example: `mysite.dev test.mysite.dev test2.mysite.dev`
62+
5863
## LICENSE
5964

60-
The MIT License (MIT)
65+
The MIT License (MIT)

bin/create-site

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#!/usr/bin/env bash
2+
3+
# Get root folder
4+
DIR="$( dirname $( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) )"
5+
6+
# If we have tput, let's set our colors
7+
if [[ ! -z $(which tput 2>/dev/null) ]]; then
8+
normal=$(tput sgr0)
9+
bold=$(tput bold)
10+
red=$(tput setaf 1)
11+
green=$(tput setaf 2)
12+
yellow=$(tput setaf 3)
13+
magenta=$(tput setaf 5)
14+
cyan=$(tput setaf 6)
15+
fi
16+
17+
__prompt() {
18+
printf "%b" "${magenta} $1: ${normal}"
19+
}
20+
21+
__warning() {
22+
printf "%b" "${red} $1 ${normal}\n"
23+
}
24+
25+
__error() {
26+
printf "%b" "[${bold}${red}Error${normal}]${bold}${red} ${1:-'Unknown Error'}${normal}\n" >&2
27+
}
28+
29+
__info() {
30+
printf "%b" "${bold}${yellow}$1${normal} \n"
31+
}
32+
33+
34+
__vagrant_is_running() {
35+
local is_running
36+
is_running="true"
37+
vagrant global-status | grep "$DIR\s*"'$' | grep -q running || is_running="false"
38+
echo "$is_running"
39+
}
40+
41+
__vagrant_maybe_halt() {
42+
local is_running
43+
is_running=$(__vagrant_is_running)
44+
if [[ "$is_running" = "true" ]]; then
45+
__info "Running \`vagrant halt\`"
46+
vagrant halt
47+
else
48+
__info "Vagrant not running, skipping \`vagrant halt\`..."
49+
fi
50+
}
51+
52+
__vagrant_up() {
53+
__info "Running vagrant up --provision... "
54+
cd "$DIR"
55+
vagrant up --provision
56+
}
57+
58+
__direcotry() {
59+
while [ -z "$site" ]; do
60+
__prompt "Name of new site directory"
61+
read -r site
62+
63+
if [ -z "$site" ]; then
64+
__error "You must enter a directory name."
65+
elif [ -f "$path/config/nginx-config/sites/$site.conf" ]; then
66+
__error "Site $site already exists. Remove config/nginx-config/sites/$site.conf to run setup again."
67+
unset site
68+
elif [ -d "$DIR/www/$site" ]; then
69+
__warning "Directory $DIR/www/$site already exists. Existing files will be overwritten."
70+
fi
71+
done
72+
73+
if [ ! -d "$DIR/www/$site" ]; then
74+
mkdir "$DIR/www/$site"
75+
fi
76+
}
77+
78+
__domain() {
79+
while [ -z "$domain" ]; do
80+
__prompt "Space separated domains to use (leave blank for ${site// /-}.dev)"
81+
read -r domain
82+
83+
if [ -z "$domain" ]; then
84+
domain="${site// /-}.dev"
85+
fi
86+
done
87+
88+
__info "Adding $domain to new pahlcon-hosts file... "
89+
echo "$domain" > "$DIR/www/$site/phalcon-hosts"
90+
91+
__info "Creating nginx-config/sites/$site.conf... "
92+
cd $DIR/config/nginx-config/sites
93+
sed -e "s/testserver\.com/$domain/" \
94+
-e "s|/srv/www/testserver|/srv/www/$site/htdocs/public|" local-nginx-example.conf-sample > "$site".conf
95+
}
96+
97+
__site() {
98+
__prompt "Git repo to clone (leave blank to skip)"
99+
read -r git_repo
100+
101+
if [ ! -z "$git_repo" ]; then
102+
git clone --recursive "$git_repo" $DIR/www/$site/htdocs
103+
else
104+
mkdir -p "$DIR/www/$site/htdocs/public"
105+
touch "$DIR/www/$site/htdocs/public/index.php"
106+
cat <<EOF > "$DIR/www/$site/htdocs/public/index.php"
107+
<?php
108+
109+
echo '<h1>', ucfirst( "$site" ), ' has been created.</h1>';
110+
echo 'Please, use <a href="https://docs.phalconphp.com/en/latest/reference/tools.html">Phalcon Dev Tool</a> to generate project skeleton.';
111+
EOF
112+
fi
113+
}
114+
115+
__main() {
116+
__direcotry
117+
__domain
118+
__site
119+
__vagrant_maybe_halt
120+
__vagrant_up
121+
}
122+
123+
__main

config/nginx-config/sites/default.conf

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ server {
3939
}
4040

4141
# this prevents hidden files (beginning with a period) from being served
42-
location ~ /\. {
42+
location ~ /\. {
4343
access_log off;
4444
log_not_found off; deny all;
4545
}
@@ -70,18 +70,3 @@ server {
7070
fastcgi_pass php;
7171
}
7272
}
73-
74-
################################################################
75-
# Blank site nginx configuration
76-
#
77-
# http://phalcon.dev - this server configuration is
78-
# setup to listen on port 80 for any requests coming in to
79-
# local.wordpress.dev and use the /srv/www/phalcon directory
80-
# to serve them.
81-
server {
82-
listen 80;
83-
listen 443 ssl;
84-
server_name phalcon.dev *.phalcon.dev;
85-
root /srv/www/phalcon/htdocs/public;
86-
include /etc/nginx/nginx-common.conf;
87-
}

provision/10-install-phalcon.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@
44
#
55
# Build and install zephir if it's not built yet
66
if [[ -f /usr/local/bin/zephir ]]; then
7-
echo "Zephir is already installed"
7+
echo "Zephir is already installed"
88
else
9-
echo "Installing Zephir..."
10-
git clone https://github.com/phalcon/zephir /tmp/zephir 2>&1
11-
cd /tmp/zephir
12-
sudo ./install -c
9+
echo "Installing Zephir..."
10+
git clone https://github.com/phalcon/zephir /tmp/zephir 2>&1
11+
cd /tmp/zephir
12+
sudo ./install -c
1313
fi
1414

1515
# PhalconPHP
1616
#
1717
# Build and install phalcon extension if it isn't built yet
1818
if [[ -f /usr/lib/php/20151012/phalcon.so ]]; then
19-
echo "PhalconPHP is already installed"
19+
echo "PhalconPHP is already installed"
2020
else
21-
echo "Installing PhalconPHP..."
22-
git clone --depth=5 git://github.com/phalcon/cphalcon.git /tmp/cphalcon 2>&1
23-
cd /tmp/cphalcon/build
21+
echo "Installing PhalconPHP..."
22+
git clone --depth=5 git://github.com/phalcon/cphalcon.git /tmp/cphalcon 2>&1
23+
cd /tmp/cphalcon/build
2424
sudo ./install
25-
fi
25+
fi

www/default/index.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,5 @@
1515
<li><a href="/phpinfo.php">PHP Info</a></li>
1616
<li><a href="/php-status?html&amp;full">PHP Status</a></li>
1717
</ul>
18-
19-
<ul class="nav">
20-
<li><a href="http://phalcon.dev/">http://pahlcon.dev/</a></li>
21-
</ul>
2218
</body>
23-
</html>
19+
</html>

www/phalcon/htdocs/app/cache/readme.md

Whitespace-only changes.

www/phalcon/htdocs/app/config/config.php

Lines changed: 0 additions & 24 deletions
This file was deleted.

www/phalcon/htdocs/app/config/loader.php

Lines changed: 0 additions & 13 deletions
This file was deleted.

www/phalcon/htdocs/app/config/services.php

Lines changed: 0 additions & 98 deletions
This file was deleted.

0 commit comments

Comments
 (0)