1. Check your Linux Centos version
cat /etc/centos-release
2. First of all, you need to enable REMI and EPEL repositories in your Linux distribution to have the updated packages (PHP, Nginx, MariaDB, etc.) using following commands
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
3. Install Nginx server
yum install nginx
4. Enable Nginx
systemctl start nginx
systemctl enable nginx
systemctl status nginx
5.* (If you have a firewall*) To access nginx from public network, you need to open a port 80 on your system firewall to receive external requests as shown.
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --reload
6. Install MySQL
yum install mariadb-server php-mysql
systemctl start mariadb.service
/usr/bin/mysql_secure_installation
7.1 Install PHP
yum install yum-utils yum-config-manager --enable remi-php72 yum install php php-fpm php-common php-xml php-mbstring php-json php-zip php7.0-bcmath
7.2 Enable PHP-FPM
systemctl start php-fpm
systemctl enable php-fpm
systemctl status php-fpm
8. Install Composer
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
chmod +x /usr/local/bin/composer
9. Install Laravel
cd /var/www/html/
sudo composer create-project --prefer-dist laravel/laravel mylaravelsite
10. Check if Laravel was installed
cd /var/www/html/mylaravelsite
ls -l
11. Configure Laravel Installation for Nginx
chmod -R 775 /var/www/html/mylaravelsite
chown -R apache.apache /var/www/html/mylaravelsite
chmod -R 777 /var/www/html/mylaravelsite/storage/
12. If you have SELinux enabled, you need to update the security context of the storage and bootstrap/cache directories using following commands.
sestatus
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/testsite/bootstrap/cache(/.*)?'
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/testsite/storage(/.*)?'
restorecon -Rv '/usr/share/nginx/html/testapp'
13. Create a environment file for your Laravel application, using the sample file provided.
.env.example .env
14. Generate and set your application key to a random string using following command.
php artisan key:generate
15. Configure Nginx
vi /etc/nginx/conf.d/mylaravelsite.conf
server { listen 80; server_name mywebsitename.com; root /var/www/html/mylaraveltsite/public; index index.php; #log your server errors access_log /var/log/nginx/laravel-access.log; error_log /var/log/nginx/laravel-error.log; charset utf-8; gzip on; gzip_types text/css application/javascript text/javascript application/x-javascript image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php { include fastcgi.conf; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass 127.0.0.1:9000; } location ~ /\.ht { deny all; } }
16. Restart Nginx
systemctl restart nginx
17. Access laravel website
If you do not have a fully registered domain name, you need to use the /etc/hosts file to create a local DNS for testing.
Check your server IP address
ip addr show
Add the the following line in your /etc/hosts file as shown (change the IP with your own)
192.168.0.20 mywebsitename.com;
18. Check if Laravel is working
http://mywebsitename.com
If you are developing locally, you may employ PHP’s built-in development server to serve your application or site, as follows. This command will start a development server at http://localhost:8000 or http://127.0.0.1:8000. On CentOS/REHL, this port should be opened in the firewall for you to serve your application this way.