How to Install PHP on Debian 10 (Linux)

How to Install PHP on Debian 10 (Linux)

In this post, we will discuss how to install PHP on Debian 10, Buster. We'll also show you how to integrate PHP with Nginx and Apache.

In this post, we will discuss how to install PHP on Debian 10, Buster. We'll also show you how to integrate PHP with Nginx and Apache. Debian 10 ships with PHP version 7.3, which is supported by the most popular CMS and frameworks such as WordPress, Magento, and Laravel.

Prerequisites

To be able to install packages, you need to be logged in as root or user with sudo privileges

Installing PHP with Apache

If you are using Apache as your webserver to install PHP and Apache PHP module run the following commands:

sudo apt update
sudo apt install php libapache2-mod-php

Once the installation is complete, restart Apache to load the PHP module:

sudo systemctl restart apache2

Installing PHP with Nginx

Unlike Apache, Nginx doesn't have a built-in support for processing PHP files. You'll need to use the PHP FPM (“fastCGI process manager”) service to handle the PHP files.

Install the PHP and PHP FPM packages by running the following command:

sudo apt update
sudo apt install php php-fpm

Once the packages are installed, the PHP FPM service will start automatically.

You can now edit your domain Nginx server block and add the following lines so that Nginx can process PHP files:

server {

    # . . . other code

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.3-fpm.sock;
    }
}

Save the configuration file and restart the nginx service for the new configuration take effect:

sudo systemctl restart nginx

Installing PHP extensions

You can extend the PHP core functionalities by installing additional extensions. PHP extensions are available as packages and can be easily installed by typing:

sudo apt install php-[extname]

For example, to install MySQL and GD PHP extensions, you would run the following command:

sudo apt install php-mysql php-gd

When installing PHP extensions, do not forget to restart the Apache or the PHP FPM service, depending on your setup.

Testing PHP Processing

To test whether your web server is properly configured for PHP processing, create a new file called info.php inside the /var/www/html directory with the following code:

/var/www/html/info.php

<?php

phpinfo();

Save the file, open your browser of choice and visit http://your_server_ip/info.php

The phpinfo function prints information about your PHP configuration as shown on the image below:

Conclusion

We have shown you how to install PHP on Debian 10 and configure your webserver to process PHP files. Thank you for reading !

Clear Cache in Laravel 6.8 App using Artisan Command Interface (CLI)

Clear Cache in Laravel 6.8 App using Artisan Command Interface (CLI)

In Laravel 6 tutorial, we learn how to use PHP artisan command interface (CLI) to clear the cache from Laravel 6.8 application. How To Clear Cache in Laravel 6.8 Application using Artisan Command Line Interface (CLI)? How to clear route cache using php artisan command? How to easily clear cache in Laravel application? How to clear config cache in PHP Laravel via artisan command? How to clear Laravel view cache? How to Reoptimized class in Laravel via artisan CLI?

Today in this tutorial, we are going to learn how to clear route cache, laravel application cache, config cache, view cache and reoptimized class in a Laravel 6.8 application using artisan command-line interface.

I’m pretty sure many of you may have found yourself gotten into the situation where you do not see changes in the view after making the changes in the app.

Laravel application serves the cached data so caching problem occurs due to the robust cache mechanism of Laravel.

But, if you are still facing this issue, then you do not have to worry further. Let me do the honour of introducing you some of the best artisan commands to remove the cache from your Laravel app via PHP artisan command line interface.

Artisan is the command-line interface included with Laravel. It provides a number of helpful commands that can assist you while you build your application.

Table of Contents

  • Clear Route Cache in Laravel
  • Clear Laravel Application Cache
  • Clear Config Cache via PHP Artisan
  • Clear Laravel View Cache
  • Reoptimized Class
Clear Route Cache in Laravel

Laravel caching system also takes routes in consideration, to remove route cache in Laravel use the given below command:

php artisan route:cache
Clear Application Cache in Laravel

Run the following command to clear application cache:

php artisan cache:clear
Clear Config Cache in Laravel

Run the following command to clear config cache:

php artisan config:cache
Clear View Cache in Laravel

Run the following command to clean your view cache:

php artisan view:clear
Reoptimize Class

Run the below command to reoptimize the class loader:

php artisan optimize

Conclusion

We have completed this Laravel 6 tutorial, In this tutorial we learned how to use php artisan command to clear the cache from your Laravel application. We have answered the following questions in this article.

  • How to clear route cache using php artisan command?
  • How to easily clear cache in Laravel application?
  • How to clear config cache in PHP Laravel via artisan command?
  • How to clear Laravel view cache?
  • How to Reoptimized class in Laravel via artisan CLI?

Now, it’s your time to let me know what do you think about this laravel 6 article. Go forth and try these super awesome artisan commands and let me know how these commands are helping you.

How to use Corcel in Laravel to CRUD Wordpress Data

How to use Corcel in Laravel to CRUD Wordpress Data

As a developer, you may find yourself in a situation where you want to make use of the data coming from your WordPress blog. And that's where Corcel comes to the stage.

Originally published by Ivica Jangelovski at https://adevait.com

Laravel and Wordpress are with no doubt the most recognized open-source projects in the PHP community. The first one gives developers complete freedom and flexibility like no other framework before. The second one is the most widely used CMS across the internet, covering more than 34% of all existing websites. Yes, it’s true, at least that’s what the WordPress core people are saying on the official site. WordPress is also highly customizable, allowing developers to extend its functionality by leveraging the Wordpress developer APIs. Both of them are the “representatives” of the PHP language in its community nowadays.

As a developer, you may find yourself in a situation where you want to make use of the data coming from your WordPress blog. And that's where Corcel comes to the stage.

Table Of Contents

  • What is Corcel?
  • Why choose Corcel over the WP REST API?
  • Installation and configuration
  • Code Samples
  • Corcel and ACF
  • Summary

What is Corcel?

Corcel is a standalone PHP package which aims to allow developers to easily fetch, manipulate or communicate (doing CRUD operations) with the data from your WordPress blog.

The codebase of Corcel consists of a collection of PHP classes built on top of Eloquent ORM (from Laravel framework), that provides a fluent interface to connect and get data directly from a WordPress database.

Why choose Corcel over the WP REST API?

Good question. And the answer is the efficiency and speed that Corcel provides. It's simple. This package communicates directly with the WordPress database to give all it needs, while the REST API is calling WP and WP is calling the database (duplicating actions unnecessary). And that's not very likely to be efficient enough. Someone already raised that question so you can read more on this question on this GitHub issue. But let's go and try it.

Installation and configuration

As I said above, Corcel can be used as a standalone package on every PHP project, but the following examples are only for a Laravel installation. For more details about including Corcel in your other (not Laravel) PHP project, you can read the documentation on GitHub (the package repository has very clean and well-written documentation along with some usage examples).

Install with composer

The installation is pretty straightforward using the well-known composer. Run the following command from your terminal in order to install Corcel as a dependency:

composer require jgrossi/corcel

Now that we have Corcel added as dependency let's do the configuration work.

Configuration

Open your config/app.php file and include the CorcelServiceProvider at the bottom of the providers list:

'providers' => [

    Corcel\Laravel\CorcelServiceProvider::class,

]

Next step is to run the following artisan command from your terminal:

php artisan vendor:publish --provider="Corcel\Laravel\CorcelServiceProvider"

This will create the config/corcel.php configuration file in your config directory. We’ll get back to it later (after the main database config).

Database configuration

Open the main database configuration file config/database.php. Here you already have the connections array. In order to configure the params for the WordPress database that we'll be using, you’ll need to add one more element to it like this:

'corcel' => [ // You can name this connection name as you wish 

        'driver'    => 'mysql',

        'host'      => 'localhost',

        'database'  => 'wordpress_database',

        'username'  => 'root',

        'password'  => 'root',

        'charset'   => 'utf8',

        'collation' => 'utf8_unicode_ci',

        'prefix'    => 'wp_',

        'strict'    => false,

        'engine'    => null,

],

Now go back to the config/corcel.php file and add the name of the connection that you just created to the connection element (in our case it’s named corcel) and that's all (regarding the configuration of course)! Now let's see some usage examples from Corcel.

Code Samples

Corcel has few predefined models for the Posts, Pages, Meta, and all other entities. But you can extend those very easily. I'll provide a few examples of using Corcel to fetch Posts and Metadata.

Posts

Create a model called Post.php and at the top of it use the Corcel core Post model:

use Corcel\Model\Post as Corcel;

Get a specific post by ID:

Post::find($id);

Get the latest posts from the post types post, cptname and othercpt that are assigned to the taxonomies category and category2:

Post::status('publish')
           ->whereIn('post_type', ['post', 'cpt_name', 'other_cpt'])
           ->whereHas('taxonomies', function ($query) {
               $query->whereIn('taxonomy',['category', 'category2']);
           })
           ->newest()
           ->get();

A method inside the model that returns the URL of the post featured image with the size that's given as parameter:

public function getPostThumbnailUrl($size = '')
{
   if ($this->thumbnail !== null && $this->thumbnail->size($size) !== null) {
      return $this->thumbnail->size($size)['url'];
   }

   return '';
 }

Metadata

According to the Codex, the post metadata is the "administrative" information you provide to viewers about each post. This information usually includes the author of the post, when it was written (or posted), and how the author categorized that particular post. Of course, this is only by default. Developers usually extend this data to fit their needs. One example of using the custom metadata is leveraged by YoastSEO - a plugin that helps you optimize your post SEO scores. It adds a unique meta description for each post in the <head> tag. One way to fetch this data to your post view in Laravel is to create a method in the Post model:

public function getYoastDescription()
   {
       return array_key_exists('_yoast_wpseo_metadesc', $this->getMetasAttribute()) ? $this->getMetasAttribute()['_yoast_wpseo_metadesc'] : '';
   }

As you can see this method is already using some methods that are written in the Corcel's core. We are just using them to make things cleaner in our view:

@section('metaDescription', $post->getYoastDescription())

The above will print the <meta> tag with the content attribute filled with the value that returned our method.

Corcel and ACF

There is also a way to get data from the ACF (Advanced custom fields) plugin. This plugin is essentially storing data as Metadata but in a more convenient way. In order to use it, you'll have to install it as a standalone package because it's not included in the main one that I wrote above. For more details check the repo for this package and you'll find the instructions there.

Summary

So far we have covered some ways of using Corcel. But there are many other examples that you can make use of that can be found in the official documentation on GitHub. We saw why you should use Corcel over WP REST API to fetch data into Laravel and how that benefits you. 

Thanks for reading

If you liked this post, share it with all of your programming buddies!

Follow me on Facebook | Twitter

Further reading

PHP with Laravel for beginners - Become a Master in Laravel

Projects in Laravel: Learn Laravel Building 10 Projects

Laravel for RESTful: Build Your RESTful API with Laravel

Fullstack Web Development With Laravel and Vue.js

Laravel 5.8 Tutorial for Beginners

Laravel 5.8 Ajax CRUD tutorial using Datatable JS

Laravel 5.8 Tutorial from Scratch for Beginners

Upgrading Laravel To 6.0 From 5.8

Laravel 6 Release New Features and Upgrade


Get Weather Data with Laravel Weather

Get Weather Data with Laravel Weather

Get Weather Data with Laravel Weather. Laravel Weather is a good package which we can use to get weather data. It's a wrapper around Open Weather Map API (Current weather). A wrapper around Open Weather Map API (Current weather)

🌤️ A wrapper around Open Weather Map API (Current weather)

Installation

You can install the package via composer:

source-shell
composer require gnahotelsolutions/laravel-weather
Usage
text-html-php
$weather = new Weather();

// Checking weather by city name
$currentWeatherInGirona = $weather->get('girona,es');

// You can use the city id, this will get you unambiguous results
$currentWeatherInGirona = $weather->find('3121456');

Units

By default the package uses metric for Celsius temperature results, this can be modified using the configuration file or on the fly:

text-html-php
$weather = new Weather();

$currentWeatherInGirona = $weather->inUnits('imperial')->get('girona,es');

Language

By default the package uses es for the description translation, this can be modified using the configuration file or on the fly:

text-html-php
$weather = new Weather();

$currentWeatherInGirona = $weather->inLanguage('en')->get('girona');

Guzzle Client Instance

If you need to use another instance of Guzzle, to modify headers for example:

text-html-php
$weather = new Weather();

$guzzle = $this->getSpecialGuzzleClient();

$currentWeatherInGirona = $weather->using($guzzle)->get('girona');

Testing

source-shell
composer test