GNU/Linux >> Linux Esercitazione >  >> Linux

Come installare lo stack Apache, MariaDB e PHP (FAMP) su FreeBSD 11

In questo tutorial ti mostreremo come installare Apache, MariaDB e PHP su FreeBSD 11. Se non conosci FAMP è l'acronimo di FreeBSD, Apache, MySQL/MariaDB, PHP. FreeBSD 11 è l'ultima versione al momento della creazione di questo articolo.

Prerequisiti

Prima di iniziare con questa guida, dovresti almeno avere una conoscenza di base di linux o unix, conoscere i comandi di base della shell per linux o unix, avere il login come utente root e ovviamente hai bisogno di FreeBSD 11 installato sul tuo PC o server.

Fase 1:aggiorna il tuo FreeBSD

Prima di continuare a installare qualsiasi software, dobbiamo prima aggiornare il nostro sistema operativo FreeBSD 11.

Esegui i seguenti comandi sul tuo server FreeBSD.

$ su
# freebsd-update fetch
# freebsd-update install

Se sei stato installato in ritardo, dovresti ottenere un output come questi

# freebsd-update fetch
src component not installed, skipped
Looking up update.FreeBSD.org mirrors... 4 mirrors found.
Fetching public key from update5.freebsd.org... done.
Fetching metadata signature for 11.0-RELEASE from update5.freebsd.org... done.
Fetching metadata index... done.
Fetching 1 metadata files... done.
Inspecting system... done.
Preparing to download files... done.

No updates needed to update system to 11.0-RELEASE-p0.
# freebsd-update install
src component not installed, skipped
No updates are available to install.
Run '/usr/sbin/freebsd-update fetch' first.

Passaggio 2:installazione del server Web Apache

Installeremo Apache 2.4 usando il comando pkg.

# pkg install apache24

Se usi per la prima volta il comando pkg nel tuo sistema operativo dovresti ricevere una notifica quando installi lo strumento di gestione dei pacchetti, scegli semplicemente y

# pkg install apache24
The package management tool is not yet installed on your system.
Do you want to fetch and install it now? [y/N]: y

Successivamente, consentiamo l'esecuzione di Apache all'avvio utilizzando questi comandi:

# sysrc apache24_enable=yes

Avvia il servizio apache usando questi comandi:

# service apache24 start

Test del servizio web apache:

Prima di testare Apache, dobbiamo configurare la configurazione di Apache. Modifica questo file utilizzando nano /usr/local/etc/apache24/httpd.conf .

# nano /usr/local/etc/apache24/httpd.conf

Trova e modifica questa variabile come queste in base al tuo indirizzo IP o nome host, in questo esempio utilizziamo l'indirizzo IP 192.168.14.126:

ServerName 192.168.14.126:80

Esci e salva il file. Quindi riavvia il servizio Apache usando il comando seguente:

# service apache24 restart

Ora apri il tuo browser web e vai a:http://indirizzo-IP/ o http://localhost/. Dovresti vedere la pagina di test di Apache.

Fase 3 – Installa MariaDB

MariaDB è un sostituto drop-in di MySQL. Ha lo stesso nome di processo, la stessa sintassi e configurazione. Per installare esegui questi seguenti comandi pkg:

# pkg install mariadb100-server

Copia la configurazione di esempio di MariaDB dalla directory '/usr/local/share/mysql/ ‘ a ‘/usr/local/etc/ ':

# cp /usr/local/share/mysql/my-medium.cnf /usr/local/etc/my.cnf

Abilita e avvia il servizio MariaDB:

# sysrc mysql_enable=yes
# service mysql-server start

In impostazione predefinita, la password di root dell'installazione di MariaDB era vuota. Per motivi di sicurezza creeremo la password di root usando questo comando:

# mysql_secure_installation

Quando viene richiesto "Inserisci la password corrente per root", basta premere il tasto INVIO e impostare la password due volte. Quindi premi semplicemente Y per accettare i valori predefiniti.

Esempio di output:

# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] Y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] 
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] 
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] 
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] 
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

Fase 4 – Installa PHP

Abbiamo bisogno di php per il contenuto dinamico del server, per installare PHP esegui questi seguenti comandi:

# pkg install mod_php56 php56-mysql php56-mysqli

Dopo l'installazione riuscita, dobbiamo copiare php.ini configurazione di esempio:

# cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini

Aggiorna le modifiche con questo comando:

# rehash

Abbiamo bisogno di configurare PHP con il server web apache, quindi abbiamo bisogno di modificare il file di configurazione di apache usando nano:

# nano /usr/local/etc/apache24/httpd.conf

Trova la sezione DirectoryIndex e aggiungi index.php davanti a index.html esistente come mostrato di seguito.

[...]

<IfModule dir_module>
 DirectoryIndex index.php index.html
</IfModule>

[...]

E poi, aggiungi le seguenti righe nella parte inferiore del file di configurazione di Apache

<FilesMatch "\.php$">
 SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
 SetHandler application/x-httpd-php-source
</FilesMatch>

Salva e chiudi il file. È necessario riavviare il server Web Apache per modificare la configurazione:

# service apache24 restart

Passaggio 5:verifica PHP

Per testare PHP creeremo script php di esempio usando nano:

# nano /usr/local/www/apache24/data/test.php

Aggiungi la seguente riga:

<?php phpinfo(); ?>

Salva e chiudi il file. Apri il browser web e vai all'indirizzo del tuo server http://IP-Address/test.php.

Passaggio 6:installazione dei moduli PHP (estensioni)

Per ottenere il pieno funzionamento del tuo script PHP a volte abbiamo bisogno di installare alcuni moduli PHP aggiuntivi (estensioni), puoi saltare questo passaggio se non hai bisogno di installare estensioni. Per visualizzare l'elenco dei moduli disponibili, esegui:

# pkg search php56

Esempio di output:

# pkg search php56
mod_php56-5.6.26               PHP Scripting Language
php56-5.6.26                   PHP Scripting Language
php56-bcmath-5.6.26            The bcmath shared extension for php
php56-bz2-5.6.26               The bz2 shared extension for php
php56-calendar-5.6.26          The calendar shared extension for php
php56-ctype-5.6.26             The ctype shared extension for php
php56-curl-5.6.26              The curl shared extension for php
php56-dba-5.6.26               The dba shared extension for php
php56-dom-5.6.26               The dom shared extension for php
php56-exif-5.6.26              The exif shared extension for php
php56-extensions-1.0           "meta-port" to install PHP extensions
php56-fileinfo-5.6.26          The fileinfo shared extension for php
php56-filter-5.6.26            The filter shared extension for php
php56-ftp-5.6.26               The ftp shared extension for php
php56-gd-5.6.26                The gd shared extension for php
php56-gettext-5.6.26           The gettext shared extension for php
php56-gmp-5.6.26               The gmp shared extension for php
php56-hash-5.6.26              The hash shared extension for php
php56-iconv-5.6.26             The iconv shared extension for php
php56-imap-5.6.26              The imap shared extension for php
php56-interbase-5.6.26         The interbase shared extension for php
php56-json-5.6.26              The json shared extension for php
php56-ldap-5.6.26              The ldap shared extension for php
php56-mbstring-5.6.26          The mbstring shared extension for php
php56-mcrypt-5.6.26            The mcrypt shared extension for php
php56-mssql-5.6.26             The mssql shared extension for php

Puoi verificare cosa fa ogni modulo dalla sezione commenti nell'output sopra, o semplicemente eseguire il seguente comando:

# pkg search -f php56-curl

Esempio di output:

# pkg search -f php56-curl
php56-curl-5.6.26
Name           : php56-curl
Version        : 5.6.26
Origin         : ftp/php56-curl
Architecture   : freebsd:11:x86:64
Prefix         : /usr/local
Repository     : FreeBSD [pkg+http://pkg.FreeBSD.org/FreeBSD:11:amd64/quarterly]
Categories     : ftp
Licenses       : PHP301
Maintainer     : [email protected]
WWW            : http://www.php.net/
Comment        : The curl shared extension for php
Shared Libs required:
	libcurl.so.4
Annotations    :
	cpe            : cpe:2.3:a:php:php:5.6.26:::::freebsd11:x64
Flat size      : 90.1KiB
Pkg size       : 26.3KiB
Description    :
PHP, which stands for "PHP: Hypertext Preprocessor" is a widely-used Open
Source general-purpose scripting language that is especially suited for
Web development and can be embedded into HTML.  Its syntax draws upon C,
Java, and Perl, and is easy to learn.  The main goal of the language is to
allow web developers to write dynamically generated webpages quickly, but
you can do much more with PHP.

WWW: http://www.php.net/

Per installare l'estensione php, ad esempio installeremo php56-curl, eseguiamo questo comando:

# pkg install php56-curl

Per apportare modifiche dopo l'installazione, è necessario riavviare il servizio Web Apache:

# service apache24 restart

Congratulazioni, hai installato con successo lo stack Apache, MariaDB e PHP (FAMP) su FreeBSD 11, ora sei pronto per ospitare i tuoi siti Web o qualsiasi applicazione basata sul Web.


Linux
  1. Come installare Nginx con PHP e MySQL (stack LEMP) su CentOS 7

  2. Come installare lo stack Nginx, MariaDB e PHP (FEMP) su FreeBSD

  3. Come installare lo stack Apache, MariaDB e PHP (FAMP) su FreeBSD

  4. Come installare e configurare PHP e Apache (stack LAMP) su Ubuntu 20.04

  5. Come installare e configurare PHP e Apache (stack LAMP) su Debian 11

Come installare Apache e PHP su OpenSUSE 15.1

Come configurare lo stack LAMP (Apache, MariaDB e PHP) su Debian 11

Come installare Apache, MariaDB, PHP (LAMP) su Fedora 32

Come Installare FAMP (FreeBSD 10, Apache, MySQL, PHP) su un Server Cloud o VPS

Come installare uno stack LAMP (Apache, MariaDB, PHP) su CentOS 7

Come installare LAMP su Fedora 23 (Linux, Apache, MySQL e PHP)