Vous n'êtes pas identifié(e).
L'icône rouge permet de télécharger chaque page du wiki visitée au format PDF et la grise au format ODT →
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente Prochaine révision Les deux révisions suivantes | ||
utilisateurs:hypathie:tutos:creer-son-site-web-en-php-_-prendre-en-main-apache2-sur-jessie [14/06/2020 15:57] Hypathie [Créer son site web en php _ prendre en main Apache2 sur Jessie] |
utilisateurs:hypathie:tutos:creer-son-site-web-en-php-_-prendre-en-main-apache2-sur-jessie [19/06/2020 18:39] Hypathie [Créer son site web en php _ prendre en main Apache2] |
||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | ====== Créer son site web en php _ prendre en main Apache2 ====== | + | ====== Prendre en main Apache2 ====== |
Ligne 352: | Ligne 352: | ||
<code root>apt install php-pear php7.4 libapache2-mod-php7.4</code> | <code root>apt install php-pear php7.4 libapache2-mod-php7.4</code> | ||
+ | |||
+ | ==== Configurer Apache pour utiliser du code php dans un fichier avec une extension html ==== | ||
+ | |||
+ | Par défaut, le code php est interprété s'il se trouve dans un fichier nommé avec l'extension .php, par exemple index.php.\\ | ||
+ | Pour utiliser du code php comme ci-dessous dans un fichier nommé avec l'extension html, par exemple index.html : \\ | ||
+ | |||
+ | <code html> | ||
+ | <!DOCTYPE html> | ||
+ | <html> | ||
+ | <head> | ||
+ | <meta charset="UTF-8"> | ||
+ | <title>test1.net _ index.html</title> | ||
+ | </head> | ||
+ | |||
+ | <body> | ||
+ | <h1>Bienvenue sur le site de test de /var/www/test1.net/index.php ! </h1> | ||
+ | <?php | ||
+ | |||
+ | phpinfo(); | ||
+ | |||
+ | ?> | ||
+ | </body> | ||
+ | </html> | ||
+ | </code> | ||
+ | |||
+ | il faut modifier le fichier **/etc/apache2/mods-enabled/php7.4.conf** en ajoutant :\\ | ||
+ | |||
+ | <code> | ||
+ | <FilesMatch ".+\.html$"> | ||
+ | SetHandler application/x-httpd-php | ||
+ | </FilesMatch> | ||
+ | </code> | ||
Ligne 407: | Ligne 439: | ||
* Relancer le service d'apache après une modification d'un ou plusieurs fichiers de configuration | * Relancer le service d'apache après une modification d'un ou plusieurs fichiers de configuration | ||
+ | __**Sur Jessie**__ | ||
<code root>service apache2 reload</code> | <code root>service apache2 reload</code> | ||
<note> | <note> | ||
On peut faire aussi : | On peut faire aussi : | ||
<code>{start|stop|graceful-stop|restart|reload|force-reload|start-htcacheclean|stop-htcacheclean}</code> | <code>{start|stop|graceful-stop|restart|reload|force-reload|start-htcacheclean|stop-htcacheclean}</code> | ||
+ | </note> | ||
+ | |||
+ | __**Sur Buster (debian10)**__ | ||
+ | |||
+ | <code root>systemctl reload apache2</code> | ||
+ | <note> | ||
+ | Info sur systemctl : https://www.linuxtricks.fr/wiki/systemd-les-commandes-essentielles | ||
+ | |||
</note> | </note> | ||
Ligne 424: | Ligne 465: | ||
* Désactiver un module : | * Désactiver un module : | ||
<code root>a2dismod nomModule</code> | <code root>a2dismod nomModule</code> | ||
+ | |||
+ | ===== Modules Php ===== | ||
+ | |||
+ | Pour installer un module php en fonction de sa version de php | ||
+ | |||
+ | <code user> | ||
+ | php -v | ||
+ | </code> | ||
+ | |||
+ | Puis | ||
+ | |||
+ | <code root> | ||
+ | apt-get install php[version-here]-sqlite3 | ||
+ | </code> | ||
+ | |||
+ | ===== Pour un projet symfony5 ===== | ||
+ | |||
+ | ==== On installe Apache2 si c'est pas fait ==== | ||
+ | |||
+ | <code root>apt install apache2</code> | ||
+ | |||
+ | ==== On installe php7 ==== | ||
+ | |||
+ | <code root> | ||
+ | apt install php7.2 libapache2-mod-php7.2 php7.2-common php7.2-sqlite3 php7.2-mysql php7.2-gmp php7.2-curl php7.2-intl php7.2-mbstring php7.2-xmlrpc php7.2-soap php7.2-ldap php7.2-gd php7.2-bcmath php7.2-xml php7.2-cli php7.2-zip | ||
+ | </code> | ||
+ | |||
+ | ==== On configure php pour Apache ainsi==== | ||
+ | |||
+ | <code root>/etc/php/7.[version]/apache2/php.ini </code> | ||
+ | |||
+ | <code> | ||
+ | file_uploads = On | ||
+ | allow_url_fopen = On | ||
+ | short_open_tag = On | ||
+ | memory_limit = 256M | ||
+ | upload_max_filesize = 100M | ||
+ | max_execution_time = 360 | ||
+ | </code> | ||
+ | |||
+ | ==== On crée un virtualhost de même nom que le projet symfony==== | ||
+ | <code root> | ||
+ | cd /etc/apache2/sites-available && vim TestSymfony | ||
+ | </code> | ||
+ | apt install php7.2 libapache2-mod-php7.2 php7.2-common php7.2-sqlite3 php7.2-mysql php7.2-gmp php7.2-curl php7.2-intl php7.2-mbstring php7.2-xmlrpc php7.2-soap php7.2-ldap php7.2-gd php7.2-bcmath php7.2-xml php7.2-cli php7.2-zip | ||
+ | <code> | ||
+ | <VirtualHost *:80> | ||
+ | ServerName TestSymfony | ||
+ | |||
+ | DocumentRoot /var/www/TestSymfony/public/ | ||
+ | |||
+ | <Directory /var/www/TestSymfony/public/> | ||
+ | Options FollowSymLinks MultiViews | ||
+ | AllowOverride All | ||
+ | Order allow,deny | ||
+ | Allow from All | ||
+ | </Directory> | ||
+ | |||
+ | ErrorLog /var/log/apache2/project_error.log | ||
+ | CustomLog /var/log/apache2/projec_access.log combined | ||
+ | </VirtualHost> | ||
+ | </code> | ||
+ | |||
+ | |||
+ | ==== On donne les bons droits au dossier du projet ==== | ||
+ | Symfony a besoin du droit d’exécution de certains fichiers. | ||
+ | |||
+ | <code root> | ||
+ | chown -R www-data:www-data /var/www/TestSymfony/ | ||
+ | chmod -R 755 /var/www/TestSymfony/ | ||
+ | |||
+ | </code> | ||
+ | |||
+ | |||
+ | ==== On crée un lien symbolique vers "site enable" ==== | ||
+ | |||
+ | <code root> | ||
+ | a2ensite TestSymfony && systemctl restart apache2.service | ||
+ | </code> | ||
+ | |||
+ | === Discuter avec Apache === | ||
+ | <code root> | ||
+ | systemctl [stop|start|enable] apache2.service | ||
+ | </code> | ||
+ | |||
+ | |||
+ | ==== On installe symfony ==== | ||
+ | |||
+ | <code user> | ||
+ | mkdir InstallSymfonyComposer | ||
+ | cd InstallSymfonyComposer/ | ||
+ | wget https://getcomposer.org/installer | ||
+ | |||
+ | php installer | ||
+ | |||
+ | cp composer.phar composer.phar_copy | ||
+ | |||
+ | sudo mv composer.phar /usr/local/bin/composer | ||
+ | |||
+ | sudo chmod +x /usr/local/bin/composer | ||
+ | |||
+ | cd /var/www/ | ||
+ | </code> | ||
+ | |||
+ | <code user> | ||
+ | composer create-project symfony/skeleton TestSymfony | ||
+ | </code> | ||
+ | |||
+ | Le dossier web /var/www appartient à root : | ||
+ | |||
+ | <code root> | ||
+ | chmod -R 777 /var/www/ | ||
+ | </code> | ||
+ | |||
+ | Pour créer une application plus légère comme un microservice, une app console ou une API dans une certaine version du framework : | ||
+ | <code user> | ||
+ | composer create-project symfony/skeleton TestSymfony [^version_voulue] | ||
+ | </code> | ||
+ | |||
+ | ou | ||
+ | <code user> | ||
+ | symfony new my_project [--version=lts|stable|4.4] | ||
+ | </code> | ||
+ | |||
+ | Pour créer une application web traditionnelle : | ||
+ | <code user> | ||
+ | composer create-project symfony/website-skeleton TestSymfony | ||
+ | </code> | ||
+ | |||
+ | ou | ||
+ | |||
+ | <code user> | ||
+ | symfony new --full my_project [--version=lts|stable|4.4] | ||
+ | </code> | ||
+ | |||
+ | |||
+ | On n'oublie de remettre les droits à /var/www | ||
+ | |||
+ | <code root> | ||
+ | chmod -R 755 /var/www/ | ||
+ | </code> | ||