How to Update WordPress Directly Without Using FTP

If for some reason you do not want to rely on the automatic check for which filesystem method to use, you can define a constant, ‘FS_METHOD’ in your wp-config.php file. Open wordpress-site/wp-config.php add.

define('FS_METHOD','direct');

It will allow you to use the ‘direct’ method of installing wordpress plugins, wordpress themes, or wordpress updates.
Detail documentation about WordPress Update and Permission:

How to Install Multiple PHP Version with Apache on Ubuntu 18.04 & 16.04

127.0.0.1 php72.example.com
127.0.0.1 php56.example.com

Apache Installation

Install Apache web server from the official repository. Launch terminal on your system or login with ssh for remote systems. Execute the following commands to install the latest available version of Apache web server.

sudo apt update 
sudo apt install apache2 libapache2-mod-fastcgi 

Ubuntu 18.04 Users:
sudo apt install apache2 libapache2-mod-fcgid

PHP Installation:

For the installation of PHP versions, we use the PPA maintained here. Use the below couple of commands to add the PPA to your system.

sudo apt install python-software-properties
sudo add-apt-repository ppa:ondrej/php

For this tutorial, we are using the PHP 5.6 and PHP 7.2 to configure with Apache web server. To use the multiple PHP versions, we will use PHP FPM and FastCGI. Let’s install the following packages on your system.

sudo apt update
sudo apt install php5.6 php5.6-fpm
sudo apt install php7.2 php7.2-fpm

After installation, php-fpm services will be started automatically. Use the following commands to make sure both services are running.

sudo systemctl status php5.6-fpm
sudo systemctl status php7.2-fpm

Apache Configuration

Now enable few modules required for the configuration of multiple PHP versions with Apache. These modules are necessary to integrate PHP FPM and FastCGI with Apache server.

sudo a2enmod actions fastcgi alias proxy_fcgi

Ubuntu 18.04 Users:
sudo a2enmod actions fcgid alias proxy_fcgi

Get ready for the configuration of websites on your Apache server. For the testing purpose, I am configuring two websites to work with two different-2 PHP versions. First, create two directories on your server.

sudo mkdir /var/www/php56
sudo mkdir /var/www/php72

Now, create and index.php containing the phpinfo() function.

Let’s start the creation of VirtualHost. Apache keeps all the VirtualHost configuration files under /etc/apache2/sites-available with the extension .conf. Create a file for the first virtual host and edit in your favorite text editor.

sudo nano /etc/apache2/sites-available/php56.example.com.conf

Add the following content. Make sure to use correct ServerName and directory path according to your setup. This website is configured to work with PHP 5.6.

<VirtualHost *:80>
    ServerName php56.example.com
    DocumentRoot /var/www/php56
    <Directory /var/www/php56>
        Options -Indexes +FollowSymLinks +MultiViews
        AllowOverride All
        Require all granted
    </Directory>
    <FilesMatch \.php$>
        # Apache 2.4.10+ can proxy to unix socket
        SetHandler “proxy:unix:/var/run/php/php5.6-fpm.sock|fcgi://localhost/”
    </FilesMatch>
</VirtualHost>
Similarly, create a second VirtualHost configuration file to work with PHP 7.2. Edit configuration file in text editor:
sudo nano /etc/apache2/sites-available/php72.example.com.conf

Add the following content to file with proper ServerName and DocumentRoot.

<VirtualHost *:80>
    ServerName php72.example.com
    DocumentRoot /var/www/php72
    <Directory /var/www/php72>
        Options -Indexes +FollowSymLinks +MultiViews
        AllowOverride All
        Require all granted
    </Directory>
    <FilesMatch \.php$>
        SetHandler “proxy:unix:/var/run/php/php7.2-fpm.sock|fcgi://localhost/”
    </FilesMatch>
</VirtualHost>

You both of the websites are configured now. But they are still not active. Apache keeps active sites under /etc/apache2/sites-enabled directory. You can simply create a symbolic link of config files to this directory or use below command to do the same.

sudo a2ensite php56.example.com
sudo a2ensite php72.example.com

After making all the changes restart Apache to reload new settings changes.

sudo systemctl restart apache2

Your setup has been completed now. Go to the next step to test your setup.

Test Setup

Edit /etc/hosts file on your local system and make an entry like below. This will resolve temprory names to localhost IP address.

sudo nano /etc/hosts

Add following entry to end of file

127.0.0.1 php72.example.com
127.0.0.1 php56.example.com

Open a web browser and visit both of the sites. You will see that php56.example.com shows the version PHP 5.6 and php72.example.com is showing the PHP 7.2 as the configuration.

Set Up Apache Virtual Hosts on Ubuntu

The Apache web server is the most popular way of serving web content on the internet. It accounts for more than half of all active websites on the internet and is extremely powerful and flexible.

Step One — Create the Directory Structure

The first step that we are going to take is to make a directory structure that will hold the site data that we will be serving to visitors.

Our document root (the top-level directory that Apache looks at to find content to serve) will be set to individual directories under the /var/www directory. We will create a directory here for both of the virtual hosts we plan on making.

Within each of these directories, we will create a public_html folder that will hold our actual files. This gives us some flexibility in our hosting.

For instance, for our sites, we’re going to make our directories like this:

sudo mkdir -p /var/www/example.com/public_html

The portions in red represent the domain names that we are wanting to serve from our VPS.

Step Two — Grant Permissions

Now we have the directory structure for our files, but they are owned by our root user. If we want our regular user to be able to modify files in our web directories, we can change the ownership by doing this:

sudo chown -R $USER:$USER /var/www/example.com/public_html

The $USER variable will take the value of the user you are currently logged in as when you press “ENTER”. By doing this, our regular user now owns the public_html subdirectories where we will be storing our content.

We should also modify our permissions a little bit to ensure that read access is permitted to the general web directory and all of the files and folders it contains so that pages can be served correctly:

sudo chmod -R 755 /var/www

Step Three — Create Demo Pages for Each Virtual Host

nano /var/www/example.com/public_html/index.html

In this file, create a simple HTML document that indicates the site it is connected to. My file looks like this:

<html>
  <head>
    <title>Welcome to Example.com!</title>
  </head>
  <body>
    <h1>Success!  The example.com virtual host is working!</h1>
  </body>
</html>

Save and close the file when you are finished.

Step Four — Create New Virtual Host Files

Create the First Virtual Host File

Start by copying the file for the first domain:

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.com.conf

Open the new file in your editor with root privileges:

sudo nano /etc/apache2/sites-available/example.com.conf

The file will look something like this (I’ve removed the comments here to make the file more approachable):

 

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

As you can see, there’s not much here. We will customize the items here for our first domain and add some additional directives. This virtual host section matches any requests that are made on port 80, the default HTTP port.

First, we need to change the ServerAdmin directive to an email that the site administrator can receive emails through.

ServerAdmin admin@example.com

After this, we need to add two directives. The first, called ServerName, establishes the base domain that should match for this virtual host definition. This will most likely be your domain. The second, called ServerAlias, defines further names that should match as if they were the base name. This is useful for matching hosts you defined, like www:

ServerName example.com
ServerAlias www.example.com

The only other thing we need to change for a basic virtual host file is the location of the document root for this domain. We already created the directory we need, so we just need to alter the DocumentRoot directive to reflect the directory we created:

DocumentRoot /var/www/example.com/public_html

In total, our virtualhost file should look like this:

<VirtualHost *:80>
    ServerAdmin admin@example.com
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com/public_html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Save and close the file.

Step Five — Enable the New Virtual Host Files

Now that we have created our virtual host files, we must enable them. Apache includes some tools that allow us to do this.

We can use the a2ensite tool to enable each of our sites like this:

sudo a2ensite example.com.conf

When you are finished, you need to restart Apache to make these changes take effect:

sudo service apache2 restart

You will most likely receive a message saying something similar to:

* Restarting web server apache2
 AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message

Step Six — Set Up Local Hosts File (Optional)

 

Edit your local file with administrative privileges by typing:

sudo nano /etc/hosts

For the domains that I used in this guide, assuming that my VPS IP address is 111.111.111.111, I could add the following lines to the bottom of my hosts file:

127.0.0.1   localhost
127.0.1.1   guest-desktop
111.111.111.111 example.com

This will direct any requests for example.com on our computer and send them to our server at 111.111.111.111.

Save and close the file.

Step Seven — Test your Results

Now that you have your virtual hosts configured, you can test your setup easily by going to the domains that you configured in your web browser:

http://example.com

Images can’t be uploaded using WYSIWYG if media directory is a symlink in Magento 2

As of  Magento 2, it’s not possible to upload images via the WYSIWYG if the media directory is a symlink.

To fix this issue you can use this module.

https://github.com/sitewards/magento2-fix13929

And for more information check this url.

https://github.com/magento/magento2/issues/13929

Use Pestal phar in magento 2

Install Pestal :- 
1) curl -LO http://pestle.pulsestorm.net/pestle.phar
2) php pestle.phar
Create module using Pestal :-

If you’ve worked through the Introduction to Magento 2 — No More MVC, you know creating a basic Magento module is straight forward, but involved many different files. Pestle can handle the grunt work of creating those files for you.

For example — all you need to do to generate your module.xmlboiler plate is run the following.

$ pestle.phar generate_module
Vendor Namespace? (Pulsestorm)] Pulsestorm
Module Name? (Testbed)] HelloPestle
Version? (0.0.1)] 0.0.1
Created: /path/to/magento2/app/code/Pulsestorm/HelloPestle/etc/module.xml
Created: /path/to/magento2/app/code/Pulsestorm/HelloPestle/registration.php

Then enable it with Magento’s CLI tool

$ php bin/magento module:enable Pulsestorm_HelloPest
Then tell Magento to update the setup resource versions
$ bin/magento setup:upgrade 

Adding the Route/URL Endpoint : –

he next part of creating a Magento module is adding a URL controller endpoint, which is also known as a route. Pestle can handle this for you as well.

$ pestle.phar generate_route
Which module? (Magento_Catalog)] Pulsestorm_HelloPestle
Which area? [frontend, adminhtml] (frontend)] frontend
Frontname/Route ID? ()] hello_pestle
/path/to/magento2/app/code/Pulsestorm/HelloPestle/etc/frontend/routes.xml
/path/to/magento2/app/code/Pulsestorm/HelloPestle/Controller/Index/Index.php    

Open the generated controller and add the following debugging code to the execute method.

#File: app/code/Pulsestorm/HelloPestle/Controller/Index/Index.php
public function execute()
{
    var_dump(__METHOD__);
    return $this->resultPageFactory->create();  
}

then clear your Magento cache and load the hello_pestle URL in your browser

http://magento.example.com/hello_pestle

You should see an HTML page returned with HTTP Status: 200, and the following content.

string 'Pulsestorm\HelloPestle\Controller\Index\Index::execute' (length=54)

Don’t forget to remove the var_dump debugging code before moving on.

Adding a View:-

Now that we have a module and controller endpoint configured, we need to add Magento’s default view files. Once again, pestle can save us the hassle of needing to manually create our layout handle XML file, phtml template, and default block/view class.

$ pestle.phar generate_view Pulsestorm_HelloPestle frontend hello_pestle_index_index Main content.phtml
$ pestle.phar generate_view
Which Module? (Pulsestorm_HelloGenerate)] Pulsestorm_HelloPestle
Which Area? (frontend)] frontend
Which Handle? (pulsestorm_hellopestle_index_index)] hello_pestle_index_index
Block Name? (Main)] Main
Template File? (content.phtml)] content.phtml
Creating /path/to/magento2/app/code/Pulsestorm/HelloPestle/view/frontend/templates/content.phtml
Creating: Pulsestorm\HelloPestle\Block\Main
Creating: /path/to/magento2/app/code/Pulsestorm/HelloPestle/view/frontend/layout/hello_pestle_index_index.xml

After running the above, clear your cache and reload the page. You should see a fully laid out Magento page, with your view’s content right in the middle.

 

 

 

PWA with Magento 2.3

Required :
NodeJS >=10.14.1 LTS
Node Package Manager (NPM)
A running instance of Magento 2.3
Php 7.2

To download magento 2.3 Use this :
composer create-project –repository-url=https://repo.magento.com/ magento/project-community-edition:2.3.0 [destination directory]

Step 1. Clone the PWA Studio repository

git clone https://github.com/magento-research/pwa-studio.git

The issue during PHP installation :
1)Php version Use : PHP 7.2

Issue faced
1) Class ‘DOMDocument’ not found

Fix using: sudo apt-get install php7.2-dom

Avoid import Vanica sample data because facing github issue.

If you don’t upload sample data from vanica

Then Remove variants from these files:
pwa-studio/packages/venia-concept/src/queries/getProductDetail.graphql
pwa-studio/packages/venia-concept/src/RootComponents/Product/Product.js

Point to be noted:

1) Use url like : testpwa.local.
2) Set magento in developer mode.
3) Use node version 8.3.0( nvm install 8.3.0)
4) Install : npm install envalid
5) Set NPM version 6.5.0.

Follow this tutorial
https://magento-research.github.io/pwa-studio/venia-pwa-concept/setup/

Add validation in default jquery validation.

1) Crete new method.

jQuery.validator.addMethod(
“regex”,
function(value, element, regexp) {
var check = false;
return this.optional(element) || regexp.test(value);
},
“Please check your input.”
);

2) Add the method in validation.

“phone” : {
required : true,
regex : /^[0-9_~\-!@#\$%\^&\*\(\)]+$/
}

Here, I added for phone num validation, Here I have use regex as a method

Magento 2: Folder permission’s

You need to follow these folder and file permission in Magento 2.

find . -type f -exec chmod 644 {} \; // 644 permission for files

find . -type d -exec chmod 755 {} \; // 755 permission for directory

find ./var -type d -exec chmod 777 {} \; // 777 permission for var folder

find ./pub/media -type d -exec chmod 777 {} \;

find ./pub/static -type d -exec chmod 777 {} \;

chmod 777 ./app/etc

chmod 644 ./app/etc/*.xml

chmod u+x bin/magento

rm -rf var/di var/generation/* var/view_preprocessed pub/static/*