0 entorno php
TRANSCRIPT
![Page 1: 0 entorno php](https://reader033.vdocuments.pub/reader033/viewer/2022052412/558897a1d8b42a547d8b45f1/html5/thumbnails/1.jpg)
Tecnologías Web de Cliente
Departamento de Ingeniería de Sistemas Telemáticoshttp://moodle.dit.upm.es
Entorno PHP
![Page 2: 0 entorno php](https://reader033.vdocuments.pub/reader033/viewer/2022052412/558897a1d8b42a547d8b45f1/html5/thumbnails/2.jpg)
2
ÍndiceInstalar PHPServidor web 'interno'Apache Web ServerConfigurar Eclipse
– Crear proyecto
– Ejecutar PHP
Trabajar en la nube
![Page 3: 0 entorno php](https://reader033.vdocuments.pub/reader033/viewer/2022052412/558897a1d8b42a547d8b45f1/html5/thumbnails/3.jpg)
3
Entorno del curso: Linux● PHP puede utilizarse en cualquier entorno: Linux, MS-Windows, MacOS....
– Windows: www.wampserver.com
– Mac: ya instalado. Ejecutar php en terminal. Para mySQL, www.mamp.info
● En este curso las instrucciones serán para Linux en la distribución Ubuntu● Puedes mirar manuales para ver cómo instalar las cosas en otro entorno
![Page 4: 0 entorno php](https://reader033.vdocuments.pub/reader033/viewer/2022052412/558897a1d8b42a547d8b45f1/html5/thumbnails/4.jpg)
4
Instalar PHP como script● En linux, instalar php5-cli
● Ejecutar
![Page 5: 0 entorno php](https://reader033.vdocuments.pub/reader033/viewer/2022052412/558897a1d8b42a547d8b45f1/html5/thumbnails/5.jpg)
5
Servidor web● Escucha en un puerto, en el que acepta conexiones http● Normalmente, ese puerto es el puerto 80
– Ej. http://localhost● Si es otro puerto, debo indicarlo
– Ej. http://localhost:8080
![Page 6: 0 entorno php](https://reader033.vdocuments.pub/reader033/viewer/2022052412/558897a1d8b42a547d8b45f1/html5/thumbnails/6.jpg)
6
DocumentRoot Serv. Web● En un servidor web, tenemos que configurar la carpeta que es publicada por ese servidor (conocida como 'Document Root)● De todo el servidor, sólo son públicos los ficheros de esa carpeta
– Podemos cambiar la configuración
– Lo normal es usar /var/www pero tiene permisos de root
![Page 7: 0 entorno php](https://reader033.vdocuments.pub/reader033/viewer/2022052412/558897a1d8b42a547d8b45f1/html5/thumbnails/7.jpg)
7
Puertos privilegiados● Los puertos TCP/IP menores de 1024 están reservados para usuarios privilegiados● Si ejecutamos un servidor web como usuario normal, lo habitual son los puertos 2784, 5000, 8001, 8080
http://www.w3.org/Daemon/User/Installation/PrivilegedPorts.html
![Page 8: 0 entorno php](https://reader033.vdocuments.pub/reader033/viewer/2022052412/558897a1d8b42a547d8b45f1/html5/thumbnails/8.jpg)
8
Fallos habituales● Intentamos lanzar un servidor web, y ya hay un proceso escuchando en el puerto 80● Solución: 'acabar' con el proceso
![Page 9: 0 entorno php](https://reader033.vdocuments.pub/reader033/viewer/2022052412/558897a1d8b42a547d8b45f1/html5/thumbnails/9.jpg)
9
¿Cómo acabo un servicio?● Si sospechas que está lanzado apache2, como es un servicio, podemos usar
– sudo servide <service> start|stop|restart
http://httpd.apache.org/docs/2.0/
![Page 10: 0 entorno php](https://reader033.vdocuments.pub/reader033/viewer/2022052412/558897a1d8b42a547d8b45f1/html5/thumbnails/10.jpg)
10
¿Cómo listo los procesos?● Opción a): fuser
● Opción b): ps |grep
![Page 11: 0 entorno php](https://reader033.vdocuments.pub/reader033/viewer/2022052412/558897a1d8b42a547d8b45f1/html5/thumbnails/11.jpg)
11
¿Cómo mato los procesos?● Opción a) kill -9
● Opción b) killall
![Page 12: 0 entorno php](https://reader033.vdocuments.pub/reader033/viewer/2022052412/558897a1d8b42a547d8b45f1/html5/thumbnails/12.jpg)
12
Servidor 'de serie'● Si no queremos instalar apache
● Con el parámetro -t podemos indicar la raíz de documentos.
– Ej. php -S localhost:8080 -t /home/pepe
![Page 13: 0 entorno php](https://reader033.vdocuments.pub/reader033/viewer/2022052412/558897a1d8b42a547d8b45f1/html5/thumbnails/13.jpg)
13
Entorno LAMP● LAMP = Linux + Apache Web Server + MySQL/MariaDB + PHP/Perl/Python● En Mac: MAMP, Windows: WAMP, en cualquier sistema operativo X: XAMP.● En linux, puedes instalarlo con el paquete tasksel, lanzarlo y seleccionar LAMP server. Luego conéctate en un navegador a http://localhost:80 y verás el mensaje 'It works'
– El mensaje que ves está en /var/www/index.html
![Page 14: 0 entorno php](https://reader033.vdocuments.pub/reader033/viewer/2022052412/558897a1d8b42a547d8b45f1/html5/thumbnails/14.jpg)
14
Ejecutar PHP ● Editamos
● Copio en el documentroot y lo miro en el navegador
– Si es apache2, copio con permisos de root en /var/www y damos permisos de lectura (chmod 644)
![Page 15: 0 entorno php](https://reader033.vdocuments.pub/reader033/viewer/2022052412/558897a1d8b42a547d8b45f1/html5/thumbnails/15.jpg)
15
Configurar Apache para Eclipse
● Por defecto, apache2 tiene document-root en /var/www donde no tenemos permiso de escritura● Tenemos que cambiar la configuración de apache2 para que sirva nuestro workspace
– /etc/apache2/apache2.conf
– /etc/apache2/enabled/000-default.conf
![Page 16: 0 entorno php](https://reader033.vdocuments.pub/reader033/viewer/2022052412/558897a1d8b42a547d8b45f1/html5/thumbnails/16.jpg)
16
Configurar apache2● Añado el directorio nuevo en apache2.conf
● Cambio DocumentRoot en 00-default-conf
Directorio del workspace
![Page 17: 0 entorno php](https://reader033.vdocuments.pub/reader033/viewer/2022052412/558897a1d8b42a547d8b45f1/html5/thumbnails/17.jpg)
17
Otra alternativa● Para cada proyecto, me creo un enlace desde /var/www● Ej. sudo ln -s $home/workspace /var/www
– Con $home/workspace el directorio workspace de eclipse
● La principal ventaja es que irán todas las aplicaciones que tengamos instaladas (p.ej. PhpMyAdmin).
![Page 18: 0 entorno php](https://reader033.vdocuments.pub/reader033/viewer/2022052412/558897a1d8b42a547d8b45f1/html5/thumbnails/18.jpg)
18
Eclipse● Vamos a utilizar el plugin PDT
– http://www.eclipse.org/pdt/downloads/● Hay una versión 'todo en 1'
– Con eclipse, apache, etc.● Y una versión como plugin para añadir a nuestro eclipse si ya lo tenemos (seguimos con esta opción)
![Page 19: 0 entorno php](https://reader033.vdocuments.pub/reader033/viewer/2022052412/558897a1d8b42a547d8b45f1/html5/thumbnails/19.jpg)
19
Instalar - Plugin PDT● Eclipse
– Help->Install new software
– Add• http://download.eclipse.org/tools/pdt/updates/release
![Page 20: 0 entorno php](https://reader033.vdocuments.pub/reader033/viewer/2022052412/558897a1d8b42a547d8b45f1/html5/thumbnails/20.jpg)
20
Eclipse PDT● File → New Project → Other → PHP Project
![Page 21: 0 entorno php](https://reader033.vdocuments.pub/reader033/viewer/2022052412/558897a1d8b42a547d8b45f1/html5/thumbnails/21.jpg)
21
Proyecto PHP
![Page 22: 0 entorno php](https://reader033.vdocuments.pub/reader033/viewer/2022052412/558897a1d8b42a547d8b45f1/html5/thumbnails/22.jpg)
22
Crear fichero ● Botón derecho->New->PHP File
![Page 23: 0 entorno php](https://reader033.vdocuments.pub/reader033/viewer/2022052412/558897a1d8b42a547d8b45f1/html5/thumbnails/23.jpg)
23
Ejecutar fichero ● Botón derecho->Run As->PHP Web Application
![Page 24: 0 entorno php](https://reader033.vdocuments.pub/reader033/viewer/2022052412/558897a1d8b42a547d8b45f1/html5/thumbnails/24.jpg)
24
Ejecutar (II)
![Page 25: 0 entorno php](https://reader033.vdocuments.pub/reader033/viewer/2022052412/558897a1d8b42a547d8b45f1/html5/thumbnails/25.jpg)
25
Configurar PHP● Window->Preferences->PHP
![Page 26: 0 entorno php](https://reader033.vdocuments.pub/reader033/viewer/2022052412/558897a1d8b42a547d8b45f1/html5/thumbnails/26.jpg)
26
Trabajar en la nube● Hay un creciente número de IDEs en la nube con soporte para PHP● Ej. codenvy
![Page 27: 0 entorno php](https://reader033.vdocuments.pub/reader033/viewer/2022052412/558897a1d8b42a547d8b45f1/html5/thumbnails/27.jpg)
27
![Page 28: 0 entorno php](https://reader033.vdocuments.pub/reader033/viewer/2022052412/558897a1d8b42a547d8b45f1/html5/thumbnails/28.jpg)
28
Codenvy (I)
![Page 29: 0 entorno php](https://reader033.vdocuments.pub/reader033/viewer/2022052412/558897a1d8b42a547d8b45f1/html5/thumbnails/29.jpg)
29
Codenvy (II)
![Page 30: 0 entorno php](https://reader033.vdocuments.pub/reader033/viewer/2022052412/558897a1d8b42a547d8b45f1/html5/thumbnails/30.jpg)
30
Codenvy (III)
![Page 31: 0 entorno php](https://reader033.vdocuments.pub/reader033/viewer/2022052412/558897a1d8b42a547d8b45f1/html5/thumbnails/31.jpg)
31
Conclusiones● La primera tarea para aprender PHP es instalar PHP y comprobar que somos capaces de ejecutar un ejemplo en el navegador● Un entorno como Eclipse nos va a permitir desarrollar, ejecutar y depurar tanto PHP como HTML, CSS y JavaScript
![Page 32: 0 entorno php](https://reader033.vdocuments.pub/reader033/viewer/2022052412/558897a1d8b42a547d8b45f1/html5/thumbnails/32.jpg)
32
Referencias●Programming PHP, O'Reilly, 2013,
– http://proquest.safaribooksonline.com/book/programming/php/9781449361068
●Head first PHP & MySQL, O'Reilly, 2008,– http://proquest.safaribooksonline.com/book/
databases/mysql/9780596157739