-
Notifications
You must be signed in to change notification settings - Fork 0
/
laraveldev
executable file
·215 lines (167 loc) · 4.79 KB
/
laraveldev
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/bin/bash
# -----------------------------------------------------------
# laraveldev
# -----------------------------------------------------------
#
# Setup local dev environment and create a new laravel project
# complete with a local virtual host. Ideal for setting up a
# dev environment on a new computer.
#
# Author: Mario Rodriguez, June 2014.
#
# gather user input and validate
# -----------------------------------------------------------
echo
echo -n "Enter the project name ( Example: myapp ): "
read projectname
if [ -z ${projectname} ]; then
echo "You must enter a project name. Command canceled."
echo
exit
fi
if echo ${projectname} | grep -q "/"; then
echo "Project name cannot contain '/' (slash). Command canceled."
echo
exit
fi
echo
echo -n "Where do you want to create this project? ( Example: /home/[user]/sites ): "
read sitespath
if [ -z ${sitespath} ]; then
echo "You must enter the path where you want to create the project folder. Command canceled."
echo
exit
fi
# path must start at the root
if [ ${sitespath:0:1} != "/" ]; then
sitespath="/${sitespath}"
fi
# remove any trailing slash, we add it later when needed
sitespath=${sitespath%%/}
# build the full path of the project folder
projectpath="${sitespath}/${projectname}"
if [ -d ${projectpath} ]; then
echo -n "That project already exists. Command canceled."
echo
exit
fi
# confirm action
# -----------------------------------------------------------
echo
echo -n "A new laravel project will be created in ${projectpath}. Continue? (y|n): "
read answer
if [ -z ${answer} ]; then
echo "You must enter 'y' or 'Y' to continue. Command canceled."
echo
exit
fi
if [ ${answer} != "y" ] && [ ${answer} != "Y" ]; then
echo "Command canceled at your request."
echo
exit
fi
# ensure we are in home directory and off we go!
cd ~
# update sources
# -----------------------------------------------------------
sudo apt-get -y update
# install required software
# -----------------------------------------------------------
sudo apt-get -y install apache2
sudo apt-get -y install mysql-server
sudo apt-get -y install php5
# install php extensions
# -----------------------------------------------------------
sudo apt-get -y install php5-cli
sudo apt-get -y install php5-json
sudo apt-get -y install php5-mysql
sudo apt-get -y install php5-xdebug
sudo apt-get -y install php5-mcrypt
# create symbolic link of mcrypt.ini, if needed
if [ ! -f "/etc/php5/mods-available/mcrypt.ini" ]; then
sudo ln -s /etc/php5/conf.d/mcrypt.ini /etc/php5/mods-available
fi
# enable mcrypt
sudo php5enmod mcrypt
# install laravel, if not installed
# -----------------------------------------------------------
sudo apt-get install curl
# download composer
if ! which composer > /dev/null; then
curl -s http://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
fi
# download laravel
if ! type laravel > /dev/null; then
wget http://laravel.com/laravel.phar
sudo mv laravel.phar /usr/local/bin/laravel
fi
# create new project
# -----------------------------------------------------------
if [ ! -d ${projectpath} ]; then
mkdir -p ${projectpath}
cd ${sitespath}
composer create-project laravel/laravel ${projectname} --prefer-dist
fi
# give write acess to storage folder
sudo chmod -R ugo+w ${projectpath}/app/storage
# create .gitignore file
# -----------------------------------------------------------
echo "
# laravel
bootstrap/compiled.php
vendor
composer.phar
composer.lock
.env.*.php
.env.php
# phpStorm
.idea
# apache
error.log
access.log
# netbeans
nbproject
# aptana
.project
.settings
# mac
.DS_STORE
.DS_Store
.DS_STORE?
# windows
Thumbs.db" > ${projectpath}/.gitignore
# create virtual host
# -----------------------------------------------------------
echo "
<VirtualHost *:80>
<Directory ${projectpath}>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ServerName ${projectname}.local
ServerAdmin webmaster@localhost
DocumentRoot ${projectpath}/public
ErrorLog ${projectpath}/error.log
CustomLog ${projectpath}/access.log combined
</VirtualHost>" > ${projectname}.conf
# move it to sites-available
sudo mv ${projectname}.conf /etc/apache2/sites-available/
# add site to hosts file
# -----------------------------------------------------------
if ! grep "${projectname}.local" /etc/hosts > /dev/null; then
cp /etc/hosts ${projectpath}
echo "127.0.0.1 ${projectname}.local" >> ${projectpath}/hosts
sudo mv ${projectpath}/hosts /etc/
fi
# enable apache site and mod rewrite, then restart
# -----------------------------------------------------------
sudo a2ensite ${projectname}.conf
sudo a2enmod rewrite
sudo service apache2 restart
echo
echo "Done!"
echo
echo "In your browser, go to http://${projectname}.local to verify installation."
echo