Installazione del framework PHP Laravel su CentOS 7
In questo articolo andremo a descrivere come installare il framework PHP Laravel su CentOS 7.
Consideriamo di partire da una macchina CentOS 7 preinstallata ( qui l’ articolo per l’installazione ) ed aggiorniamola
yum update
in un precedente articolo abbiamo descritto come installare PHP 7.x su CentOS 7 ( qui l’ articolo), seguiamo passo passo la procedura installando il repository epel
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
ed il repository relativo al php 7.x
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
inoltre avendo diverse versioni di PHP, scegliamo attraverso l’utility di yum quale repository di pacchetti PHP utilizzare
yum install yum-utils
scegliamo la versione PHP 7.4
yum-config-manager --enable remi-php74
Plugin abilitati:fastestmirror
=============================== repo: remi-php74 ===============================
[remi-php74]
async = True
bandwidth = 0
base_persistdir = /var/lib/yum/repos/x86_64/7
baseurl =
cache = 0
cachedir = /var/cache/yum/x86_64/7/remi-php74
check_config_file_age = True
compare_providers_priority = 80
cost = 1000
deltarpm_metadata_percentage = 100
deltarpm_percentage =
enabled = 1
enablegroups = True
exclude =
failovermethod = priority
ftp_disable_epsv = False
gpgcadir = /var/lib/yum/repos/x86_64/7/remi-php74/gpgcadir
gpgcakey =
gpgcheck = True
gpgdir = /var/lib/yum/repos/x86_64/7/remi-php74/gpgdir
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
hdrdir = /var/cache/yum/x86_64/7/remi-php74/headers
http_caching = all
includepkgs =
ip_resolve =
keepalive = True
keepcache = False
mddownloadpolicy = sqlite
mdpolicy = group:small
mediaid =
metadata_expire = 21600
metadata_expire_filter = read-only:present
metalink =
minrate = 0
mirrorlist = http://cdn.remirepo.net/enterprise/7/php74/mirror
mirrorlist_expire = 86400
name = Remi’s PHP 7.4 RPM repository for Enterprise Linux 7 – x86_64
old_base_cache_dir =
password =
persistdir = /var/lib/yum/repos/x86_64/7/remi-php74
pkgdir = /var/cache/yum/x86_64/7/remi-php74/packages
proxy = False
proxy_dict =
proxy_password =
proxy_username =
repo_gpgcheck = False
retries = 10
skip_if_unavailable = False
ssl_check_cert_permissions = True
sslcacert =
sslclientcert =
sslclientkey =
sslverify = True
throttle = 0
timeout = 30.0
ui_id = remi-php74
ui_repoid_vars = releasever,
basearch
username =
a questo punto installiamo PHP ed i moduli necessari per il framework Laravel
yum install php php-zip php-mysql php-mcrypt php-xml php-mbstring
installiamo il web server HTTPD
yum install httpd
avviamolo e abilitiamo l’ avvio automatico al boot
systemctl start httpd
systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
installiamo il database
yum install mariadb-server
avviamolo e abilitiamo l’ avvio automatico al boot
systemctl start mariadb.service
systemctl enable mariadb.service
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
rendiamo sicuro il database MariaDB
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):INVIO
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]Y
… 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]Y
… 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]Y
– 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]Y
Cleaning up…
All done! If you’ve completed all of the above steps, your MariaDB
installation should now be secure.Thanks for using MariaDB!
Per installare Laravel abbiamo necessità del gestore dei pacchetti PHP Composer, quindi
yum install git unzip vim
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/bin/composer
chmod +x /usr/bin/composer
installiamo Laravel
cd /var/www
git clone https://github.com/laravel/laravel.git
installiamo le dipendenze PHP di Laravel
cd /var/www/laravel
composer install
impostiamo i permessi sui singoli file
chown -R apache.apache /var/www/laravel
chmod -R 755 /var/www/laravel
chmod -R 755 /var/www/laravel/storage
per i nostri scopi dimostrativi impostiamo il Selinux in modalità permissive
setenforce 0
vim /etc/selinux/config
impostiamo la variabile SELINUX
SELINUX=permissive
La configurazione di Laravel passa per il file .env, all’interno della cartella di progetto
cd /var/ww/laravel
creiamo il file partendo dal template fornito da Laravel
cp .env.example .env
generiamo la chiave
php artisan key:generate
Application key set successfully.
Creiamo il Virtual host su Apache per accedere al framework Laravel via browser
vim /etc/httpd/conf.d/laravel.conf
<VirtualHost *:80>
DocumentRoot /var/www/laravel/public<Directory /var/www/laravel>
AllowOverride All
</Directory>
</VirtualHost>
riavviamo il web server
systemctl restart httpd
accediamo tramite browser a Laravel http://ip_server, avremo