This repository has been archived by the owner on Dec 12, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
INSTALLING LAMP - apache2-DJANGO.txt
320 lines (156 loc) · 7.43 KB
/
INSTALLING LAMP - apache2-DJANGO.txt
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
sudo aptitude install apache2
Next up, we’ll test to see if PHP is working. In terminal, enter the following command to create a new document:
sudo nano /var/www/testing.php
Then, copy the following code:
<?php phpinfo(); ?>
Let’s test Apache to see if it’s serving properly. Open up a browser and direct it the following URL:
http://localhost/
defualt domain is 127.0.1.1cd
=================how to control apache2========================================
How do I start, restart, or stop Apache 2.x web server on Ubuntu Linux operating systems using command line options?
You can use any one of the following method to restart / start / stop your Apache (httpd) sever on Ubuntu:
/etc/init.d/apache2 - A sys v init style script to start / stop / restart the Apache2 service under Debian or Ubuntu Linux.
service command - This command work in most Linux distributions including Debian and Ubuntu.
upstart command - Only works on latest version of Ubuntu.
apache2ctl command - This method should work on all Linux and Unix like operating systems.
Method #1: /etc/init.d/apache2 command examples
You need to login as root user or use the sudo command to control Apache web-server.
Task: Start Apache 2 Server
# /etc/init.d/apache2 start
or
$ sudo /etc/init.d/apache2 start
Task: Restart Apache 2 Server
# /etc/init.d/apache2 restart
or
$ sudo /etc/init.d/apache2 restart
Task: Stop Apache 2 Server
# /etc/init.d/apache2 stop
or
$ sudo /etc/init.d/apache2 stop
Method #2: service command examples
To restart Apache 2, enter:
$ sudo service apache2 restart
To stop Apache 2, enter:
$ sudo service apache2 stop
To start Apache 2, enter:
$ sudo service apache2 start
To gracefully reload Apache 2, enter:
$ sudo service apache2 reload
Method #3: upstart command examples
To start Apache 2 on Ubuntu, run:
$ sudo start apache2
To stop Apache 2 on Ubuntu, run:
$ sudo stop apache2
To restart Apache 2 on Ubuntu, run:
$ sudo restart apache2
To gracefully reload Apache 2 on Ubuntu, run:
$ sudo restart apache2
Method #4: apache2ctl command examples
apache2ctl is Apache HTTP server control interface command, which can be used to stop or start web server under any Linux distribution or UNIX.
To start Apache 2 on Ubuntu, type:
$ sudo apache2ctl start
To stop Apache 2 on Ubuntu, type:
$ sudo apache2ctl stop
To restart Apache 2 on Ubuntu, type:
$ sudo apache2ctl restart
To gracefully reload Apache 2 on Ubuntu, type:
$ sudo apache2ctl graceful
=======also: sudo /usr/sbin/apachectl restart
==================Installing mod_wsgi ===========
sudo aptitude install libapache2-mod-wsgi
Restart Apache to get mod_wsgi to work.
sudo service apache2 restart
======================postgreSQL=====================
Postgres package and a "contrib" package that adds some additional utilities and functionality:
sudo apt-get install postgresql postgresql-contrib
Upon installation Postgres is set up to use "ident" authentication, meaning that it associates Postgres roles with a matching Unix/Linux system account
sudo -i -u postgres
You will be asked for your normal user password and then will be given a shell prompt for the postgres user.
You can get a Postgres prompt immediately by typing:
psql
create a database
createdb test1
go out of this by \q
lets create a user and give them a password
first create a new user in linux
adduser test1 #this will prompt you for a password use 'test1' to keep things simple
log into psql
sudo -i -u test1
psql
at the prompt add a password for this user (no idea why tis has to be done again instead of useing the unix password)
ALTER ROLE test1 WITH PASSWORD 'test1';
---------------python bindings----------------------------
In addition to a database backend, you’ll need to make sure your Python database bindings are installed.
If you’re using PostgreSQL, you’ll need the postgresql_psycopg2 package
sudo apt-get install python-psycopg2
======install Django==============
make sure you install pip first
The python-dev and build-essential packages are recommended to install along, because it isn't possible to install any Python module that ships with a C extension without them later on.
sudo apt-get install python-pip python-dev build-essential && sudo pip install --upgrade pip
then
sudo pip install Django
==========make django project==============
create a folder
mkdir /var/www/testsite.com
go into the folder and run
django-admin.py startproject testsite . #note the full stop, it makes sure the django installer does not make another directory and place the install filed into it
==========HOSTING======================
Create your new virtual host node which should look something like this
sudo nano /etc/apache2/sites-available/mydomain.com.conf
put this
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName testsite.com
ServerAlias testsite.com
WSGIScriptAlias / /var/www/testsite.com/index.wsgi
Alias /static/ /var/www/testsite.com/static/
<Location "/static/">
Options -Indexes
</Location>
</VirtualHost>
make the static directory
mkdir /var/www/testsite.com/static/
create the index.wsgi file (can be any name not just index)
vim /var/www/testsite.com/index.wsgi
add this to the file
import os
import sys
sys.path.append('~/www/testsite.com/')
os.environ['DJANGO_SETTINGS_MODULE'] = 'testsite.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
enable the site
a2ensite /etc/apache2/sites-available/www.testsite.com.conf
sudo service apache2 restart
edit your Apache server’s httpd.conf file and add the following. If you are using a version of Apache older than 2.4, replace Require all granted with Allow from all and also add the line Order deny,allow above it.The first bit in the WSGIScriptAlias line is the base URL path you want to serve your application at (/ indicates the root url), and the second is the location of a “WSGI file” – see below – on your system, usually inside of your project package (mysite in this example). This tells Apache to serve any request below the given URL using the WSGI application defined in that file.
The WSGIPythonPath line ensures that your project package is available for import on the Python path; in other words, that import mysite works.
The <Directory> piece just ensures that Apache can access your wsgi.py file.
On Ubuntu the main Apache configuration file is actually apache2.conf
WSGIScriptAlias / /var/www/testsite.com/testsite/wsgi.py
WSGIPythonPath /var/www/testsite.com
<Directory /var/www/testsite.com>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
sudo service apache2 restart
=====================CONFIGURE DJANGO APP================
Now, edit testsite/settings.py. It’s a normal Python module with module-level variables representing Django settings. add the postgresql details we created earlier NAME is the database name
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'test1',
'USER': 'test1',
'PASSWORD': 'test1',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
now create the default tables using the manage function
python manage.py migrate
==========dont forget to migrate static content============
Add to settings:
STATIC_URL = '/static/'
STATIC_ROOT = '/var/www/static/'
Then run "python manage.py collectstatic"
====================DJANGO APP==============================