Serveur dédié VPS

Afin d’héberger des pages PHP j’ai choisi un hébergement virtualisé privé « Vps », tout d’abord chez BeHost mais ils ont suspendu leur service. J’ai alors migré chez ARUBA

A) Choix de la Distribution : Ubuntu 11.04 32bit

B) Initialisation du Serveur :

                                1. Se connecter via PuTTY : Root (clic droit pour coller)
                                2. Créer un nouvel utilisateur :
                                  1. adduser demo
                                  2. gpasswd -a demo sudo
                                3. Installation éditeur : apt-get install nano
                                4. Installation MySql : apt-get install mysql-server mysql-client
                                5. Installation PHP : apt-get install php5 php5-mysql libapache2-mod-php5
                                  
                                  

                                   

                               

                               

                           

                           

                       

                       

                   

                   

               

               

           

           

       

       

 

 

 

                                • Relance d’Appache : systemctl restart apache2

                               

                               

                           

                           

                       

                       

                   

                   

               

               

           

           

       

       

 

 

 

                • Installation MySql : apt-get install phpmyadmin

               

               

           

           

       

       

 

 

  • Open terminal, and type:
    sudo nano /etc/apache2/apache2.conf

    Add the following line at the end.

    Include /etc/phpmyadmin/apache.conf

    Save and Exit. Restart apache service:

    On Ubuntu 15.10/15.04:

    sudo systemctl restart apache2

Acces : http://—IP—/phpmyadmin

C) Pages serveur HTML :

Les pages sont dans /var/www/html

D) Installation Serveur FTP :

  1. apt install vsftpd
  2. service vsftpd restart

Modifier le fichier de conf :
1 – Editez le fichier => nano /etc/vsftpd/vsftpd.conf

2 – anonymous_enable=NO

2 – Rajouter la ligne =>seccomp_sandbox=no

3 – Redémarrez VSFTPD => /etc/init.d/vsftpd restart

E) CURL :

Cette bibliothèque permet de se connecter en utilisant divers protocoles à des sites internet. Utile pour lire des pages HTML…

https://www.vultr.com/docs/use-php5-fpm-with-apache-2-on-ubuntu-14-04

a) Test cUrl :

Fichier PHP :

Chmod +777 du fichier ou du répertoire /var/www/html

b) Installation si cUrl n’est pas dispo :


 

sudo apt-get install php5-curl

sudo service apache2 restart

sudo service php5-fpm restart

Exemple d’utilisation de cUrl pour lire une page :


Exemple pour traiter la redirection d’url et si le site n’est pas en erreur : <?php $curl = curl_init($url);curl_setopt($curl, CURLOPT_POSTFIELDS, « foo »); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, « POST »); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $subject = curl_exec($curl); $redirectURL = curl_getinfo($curl,CURLINFO_EFFECTIVE_URL ); echo $redirectURL;echo ‘<br>’; $wrong_http_codes = ‘^0|4.*|5.*$’;$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE); if (preg_match(« /$wrong_http_codes/ », $http_code) === 1) {    echo ‘Error’;} else{echo ‘Taille de page : ‘ .curl_getinfo($curl, CURLINFO_SIZE_DOWNLOAD);} curl_close($ch); ?>   F) Envoi de mail avec GMAIL : The lightweight solution is ssmtphttps://seeit.org/2010/08/26/php-mail-with-ubuntu-desktop-and-gmail/

1: Install ssmtp : sudo apt-get install ssmtp

Check where the binary and the ssmtp.conf file ended up. You’ll need to know the locations for the following steps: whereis ssmtp donne

2. Configure ssmtp : nano /etc/ssmtp/ssmtp.conf attention préciser localhost

 

 #  
 # Config file for sSMTP sendmail  
 #  
 # The person who gets all mail for userids &lt; 1000  
 # Make this empty to disable rewriting.  
 root=your-full-gmail-address  
 # The place where the mail goes. The actual machine name is required no  
 # MX records are consulted. Commonly mailhosts are named mail.domain.com  
 mailhub=smtp.gmail.com:587  
 # Where will the mail seem to come from?  
 #rewriteDomain=  
 # The full hostname
hostname=localhost
 # Are users allowed to set their own From: address?  
 # YES - Allow the user to specify their own From: address  
 # NO - Use the system generated From: address  
 FromLineOverride=YES  
 UseSTARTTLS=YES  
 AuthUser=your-gmail-username-here  
 AuthPass=your-gmail-password-here  
3. Setup your users

nano /etc/ssmtp/revaliases

You’ll probably want to set up your local user and root for sending mail:

root:username@gmail.com:smtp.gmail.com:587
localusername:username@gmail.com:smtp.gmail.com:587

4. Configure PHP

nano /etc/php5/apache2/php.ini

(This is correct for Ubuntu 10.04. You can always check which php.ini file Apache is using with the PHP function call phpinfo( INFO_GENERAL ).)

Find the sendmail configuration line: sendmail_path = /usr/sbin/ssmtp -t

Restart Apache :   sudo service apache2 restart

Utilisez msmtp

Install MSMTP : 

sudo apt-get install msmtp ca-certificates

Configure MSMTP :

The default config files for MSMTP are located in SYSCONFDIR/msmtprc and ~/.msmtprc.
Neither the first or the second was created by apt, so I preferred to have a folder in /etc where store more than one config file if needed.
Same for the logs.

sudo mkdir /etc/msmtp
sudo mkdir /var/log/msmtp

Then I’ve created the config file: AndroUbuntu is the name of my server, change it.

sudo nano /etc/msmtp/AndroUbuntu

Change your mailbox and password

# Define here some setting that can be useful for every account
defaults
        logfile /var/log/msmtp/general.log

# Settings for AndroUbuntu account
account AndroUbuntu
        protocol smtp
        host smtp.gmail.com
        tls on
        tls_trust_file /usr/share/ca-certificates/mozilla/Equifax_Secure_CA.crt
        port 587
        auth login
        user my_server_account@gmail.com
        password my_server_password
        from my_server_account@gmail.com
        logfile /var/log/msmtp/AndroUbuntu.log

# If you don't use any "-a" parameter in your command line,
# the default account "AndroUbuntu" will be used.
account default: AndroUbuntu

Test MSMTP

change the your_personal_mail@gmail.com with your own recipient, the file path if needed and run:

echo -e "Subject: Test Mail\r\n\r\nThis is a test mail" | msmtp --debug --from=default -t your_personal_mail@gmail.com --file=/etc/msmtp/AndroUbuntu

Configuring Apache\PHP to use MSMTP

To force PHP to use MSMTP when called by Apache you have to edit : nano /etc/php5/apache2/php.ini

sendmail_path = "/usr/bin/msmtp -C /etc/msmtp/AndroUbuntu --logfile /var/log/msmtp.log -a gmail -t"

 Send mail with PHP using msmtp

Look for sendmail_path option in your php.ini and edit like this:

sendmail_path = "/usr/bin/msmtp -C /path/to/your/config -t"

Note that you can not use a user configuration file (ie: one under ~/) if you plan on using msmtp as a sendmail replacement with php or something similar. In that case just create /etc/msmtprc, and remove your user configuration (or not if you plan on using it for something else). Also make sure it’s readable by whatever you’re using it with (php, django, etc…)

From the msmtp manual: Accounts defined in the user configuration file override accounts from the system configuration file. The user configuration file must have no more permissions than user read/write

So it’s impossible to have a conf file under ~/ and have it still be readable by the php user.

To test it place this file in your php enabled server or using php-cli.


ou

php -r "mail('pzuraq@gmail.com', 'Test Email', 'Test email body');" 

Test : config 

/path/to/your/config : /etc/msmtp/AndroUbuntu

I have fix the problem. It was that /root/.msmtprc was with non-accesible right which have to be 600 and the owner www-data

sudo chown : -R /.blabla

Restart Apache :

sudo service apache2 reload

https://www.emanueletessore.com/how-to-configure-msmtp-as-a-gmail-relay-on-ubuntu-server/

https://www.digitalocean.com/community/tutorials/how-to-use-gmail-or-yahoo-with-php-mail-function#configuring-php

https://wiki.archlinux.org/index.php/Msmtp

Pour HTTPS :

https://www.1and1.com/cloud-community/learn/networking/ssl-certificates/install-a-11-ssl-certificate-on-ubuntu-1604/

Attention, modifier le champ A du DNS avec l’adresse IP du serveur en IPv4 et/ou le champ AAAA avec l’IPV6

https://www.informatiweb-pro.net/admin-systeme/linux/7–ubuntu-securiser-son-serveur-web-apache-en-https-grace-a-ssl.html

Puis, pour un certificat authentifié :

https://doc.ubuntu-fr.org/tutoriel/comment_creer_un_certificat_ssl

https://letsencrypt.org/getting-started/

https://certbot.eff.org/lets-encrypt/ubuntuxenial-apache.html

Fichiers à modifier :

root@AndroUbuntu:/etc/apache2/sites-enabled# nano default-ssl.conf

root@AndroUbuntu:/etc/apache2/sites-enabled# nano 000-default.conf

 

Gestion des répertoires web 

Pour les sites avec adresse ip du serveur sur port 80 : dans le répertoire décrit dans 000-default.conf soit par exemple /var/www/html

Pour les sites en https sur port 443 : dans le répertoire décrit dans default-ssl.conf soit par exemple /var/www/html/maison

Pour relancer Apache : service apache2 reload

Références :

https://www.unixmen.com/how-to-install-lamp-stack-on-ubuntu-15-10/

http://www.liquidweb.com/kb/how-to-install-and-configure-vsftpd-on-ubuntu-15-04/

cUrl : http://99webtools.com/blog/extract-website-data-using-php/

Articles récents
Commentaires récents
fatima dans Bienvenue !
AdminDroid dans Bienvenue !
fatima dans Bienvenue !
Archives
Catégories