Tag Archives: PHP

How to Manually Install PHP 7.4 on Windows Server 2019

Motivation:

  • You want to deploy a PHP application or WordPress on Windows Server 2019.
  • You want to update PHP to any version to address compatibility or security issues in Windows.
  • You want to understand how PHP works with IIS.

Solution:

  • Install CGI for IIS on Turn Windows features on or off > Internet Information Services > World Wide Web Services > Application Development Features > CGI.
  • Download VC15 x86 Non Thread Safe package here or under PHP 7.4 section from http://windows.php.net/download/
  • Extract the ZIP file to the C:\Program Files (x86)\php-7.4.9-nts-Win32-vc15-x86 folder.
  • Rename the php-.ini-development file to php.ini.
  • Open the php.ini file and add the following line at the end of the file.
    extension=php_wincache.dll
  • Uncomment the following lines
    fastcgi.impersonate = 1;
    
    cgi.fix_pathinfo=1;
    cgi.force_redirect = 1 (and change the value to 0, i.e. cgi.force_redirect = 0)
    
    extension_dir = "C:\Program Files (x86)\php-7.4.9-nts-Win32-vc15-x86\ext"
    
    extension=php_curl.dll
    extension=php_fileinfo.dll
    extension=php_mbstring.dll
    extension=php_exif.dll
    extension=php_mysqli.dll
    extension=php_pdo_mysql.dll
    extension=php_openssl.dll
    
    error_log = "C:\Program Files (x86)\php-7.4.9-nts-Win32-vc15-x86\php_errors.log"
    
    error_log = syslog
  • A sample php.ini file can be download here.
  • Add C:\Program Files (x86)\php-7.4.9-nts-Win32-vc15-x86 to System Path.
  • Download x86 package of WinCache 2.0 for PHP 7.4 here or from https://sourceforge.net/projects/wincache/.
  • Extract and copy the php_wincache.dll file to C:\Program Files (x86)\php-7.4.9-nts-Win32-vc15-x86\ext
    folder.
  • Open IIS, click on Server name, double click on Handler Mappings, click on Add Module Mapping, and enter below information.
    Request path = *.php
    
    Module = FastCgiModule
    
    Executable = "C:\Program Files (x86)\php-7.4.9-nts-Win32-vc15-x86\php-cgi.exe"
    
    Name = PHP 7.4
    
    Request Restrictions = File or folder
  • Download and install VC_redist.x86.exe of Microsoft Visual C++ Redistributable for Visual Studio 2019 here or on https://visualstudio.microsoft.com/downloads/#microsoft-visual-c-redistributable-for-visual-studio-2019
  • en a Command Prompt, execute below command and ensure that NO WARNINGS APPEAR.
    php --version
  • Create phpinfo.php file with below content in the root website folder.
    <?php phpinfo(); ?>
  • Open http://localhost/phpinfo.php URL and verify PHP information.

 

How to move a WordPress instance from one server to another Linux server

Motivation:

You want to move a WordPress instance from one server to another to consolidate your websites to reduce cost.

Solution:

Install and use below Duplicator plugin to achieve your goal.

https://wordpress.org/plugins/duplicator/

User guide: https://snapcreek.com/duplicator/docs/quick-start/

If everything goes well for you then congratulation!

Otherwise, please review below possible problems and corresponding solutions.


Problem 1:

You don’t have a website on the new server.

Solution 1:

1. Create a new virtual host in the /etc/httpd/conf/httpd.conf

<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot "/var/www/www.example.com"
</VirtualHost>

2. Set 775 permission for /var/www/www.example.com

3. Restart httpd service

sudo systemctl restart httpd

Problem 2:

You are using Amazon Linux 2 server.

You are logged in as ec2-user.

You use WinSCP to upload files and edit configuration files.

You cannot modify /etc/httpd/conf/httpd.conf and /etc/php.ini.

Solution 2:

1 View permission settings for the file

ls -ld /etc/httpd/conf/httpd.conf

The result indicates that the file owner is root user and root group, not ec2-user.

2. View groups of a user

groups ec2-user

The result indicates that the ec2-user does not belong to root group.

3. Add a user to root group

sudo usermod -a -G root ec2-user

4. Grant Read-Write permission against a file to root group

sudo chmod g+rwx /etc/httpd/conf/httpd.conf
sudo chmod g+rwx /etc/php.ini

5. Logout and login to the server again.


Problem 3:

You are using Amazon Linux 2 server. The ZipArchive feature is missing.

Solution 3:

1. Execute below commands:

sudo amazon-linux-extras install php7.2
sudo yum install php-pear php-devel gcc libzip-devel zlib-devel
sudo pecl install zip-1.13.5 # we must specify a slightly older version due due to compatibility

2. Add “extension=zip.so” to /etc/php.ini

3. Restart the server

sudo reboot

Problem 4:

You don’t have a WordPress database on the new Linux server.

Solution 4:

Execute below MySQL commands:

CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
CREATE DATABASE `wp_database`;
GRANT ALL PRIVILEGES ON `wp_database`.* TO "username"@"localhost";
FLUSH PRIVILEGES;

Problem 5:

An database error occurs while restoring a website.

Solution 5:

1. Execute below commands to remove the website:

sudo chown -R ec2-user:apache /var/www/example.com
sudo chmod 2775 /var/www/example.com && find /var/www/example.com -type d -exec sudo chmod 2775 {} \;
find /var/www/example.com -type f -exec sudo chmod 0664 {} \;
rm -r /var/www/example.com

2. Upload the Duplicator files again, and restore the website again.


Problem 6:

No write access against /var/www/example.com is available for Duplicator.

Solution 6:

1. Execute below commands:

sudo chown -R ec2-user:apache /var/www/example.com
sudo chmod 2775 /var/www/example.com && find /var/www/example.com -type d -exec sudo chmod 2775 {} \;
find /var/www/example.com -type f -exec sudo chmod 0664 {} \;

2. Run http://example.com/installer.php again.

How to Manually Install PHP 8.1 on Windows 10

Motivation:

  • You want to understand how PHP works with IIS.
  • You want to prepare a PHP or WordPress development environment on Windows.
  • You want to update PHP to any version to address compatibility or security issues on Windows.

Solution:

  • Install CGI for IIS on Turn Windows features on or off > Internet Information Services > World Wide Web Services > Application Development Features > CGI.
  • Download VS16 x64 Non Thread Safe package under PHP 8.1 section on https://windows.php.net/download/.
  • Extract the ZIP file to C:\Program Files\php-8.1.10-nts-Win32-vs16-x64 folder.
  • Download the cacert.pem file and move it to the C:\Program Files\php-8.1.10-nts-Win32-vs16-x64\extras\ssl folder.
  • Copy the php-.ini-development file to php.ini.
  • Open the php.ini file and uncomment the following lines
    fastcgi.impersonate = 1;
    
    cgi.fix_pathinfo=1;
    cgi.force_redirect = 1 (and change the value to 0, i.e. cgi.force_redirect = 0)
    
    extension_dir = "C:\Program Files\php-8.1.10-nts-Win32-vs16-x64\ext"
    
    extension=curl
    extension=fileinfo
    extension=gd
    extension=gettext
    extension=mbstring
    extension=exif ; Must be after mbstring as it depends on it
    extension=mysqli
    extension=openssl
    extension=pdo_mysql
    
    error_log = "C:\Program Files\php-8.1.10-nts-Win32-vs16-x64\php_errors.log"
    
    error_log = syslog
    
    curl.cainfo = "C:\Program Files\php-8.1.10-nts-Win32-vs16-x64\extras\ssl\cacert.pem"
    
    openssl.capath="C:\Program Files\php-8.1.10-nts-Win32-vs16-x64\extras\ssl\cacert.pem"
  • Add C:\Program Files\php-8.1.10-nts-Win32-vs16-x64 to SYSTEM PATH.
  • Restart your machine.
  • Open cmd and execute the command below to ensure that the PHP file can be found in the SYSTEM PATH.
    php --version
  • Open IIS, click on Server name, double click on Handler Mappings > Add Module Mapping with below information.
    Request path = *.php
    
    Module = FastCgiModule
    
    Executable = "C:\Program Files\php-8.1.10-nts-Win32-vs16-x64\php-cgi.exe"
    
    Name = PHP 8.1
    
    Request Restrictions = File or folder
  • Create phpinfo.php file with below content in the root website folder.
    <?php phpinfo(); ?>

 

 

Topic 8 – Introduction to Web Application Development

Why do I need to learn about web application development?

Desktop applications are very powerful and convenient but their development, deployment and maintenance are daunting.

The reason is that the platform dependency makes it very expensive to create a desktop application working on different versions of different operating systems, such as Windows, Linux and Mac OSX.

Deployment and updates of desktop application typically require high privileges access to a computer machine, causing a problem for companies requiring high security.

Fortunately, you can overcome these limitations by creating a web application running on a browser. To create a web application you need to learn about web application development.

What can I do after finishing learning web application development?

You will be able to create web applications like The BBC News, The WordPress Blog or The White House Website.

This is exactly what I want to learn! What should I do now?

Web application development requires a lot of reading. You have to master networking concepts, HTML, CSS, JavaScript, a programming language and a database management system for web.

First, please read the two books below to get familiar with web application development concepts, and gain hands-on experience with HTML and CSS.

After that,  please read the two books below to learn in-depth about HTML and CSS.

JavaScript is the language for web development because it is implemented in most of the web browsers. Strong knowledge of JavaScript will ease your web development learning very much. Please read the books below to learn about JavaScript.

Single page application is the default front-end choice for most of new web development projects.
Please read the books below to learn how to create a single page application (SPA).

After that, please read the books below to learn how to create micro-frontends.

After that you will have 4 main options. You can choose one of them. We STRONGLY recommend that you choose only ONE option.

You should NOT learn all of them at the beginning. You could save your time by digging into only one option. After mastering the selected technology, you will realize that all of them are very similar in the sense of use.

One note is that although their concepts are similar to one another but it still takes us much time to learn how to apply an approach to real world web application.

When developing a real world web application, you often use only one or two of these 4 approaches. If you cannot make your own selection then we recommend you
– a combination of the first and second option, or
– a combination of the first and third option, or
– a combination of the first and fourth option.

The first option is PHP world.  Please read one of the following books to learn how to create web applications using PHP:

After that, After that, if your projects use WordPress, you may read this book: Brad Williams et al. (2015). Professional WordPress: Design and Development. Wrox.

The second option is ASP.NET. Please read the two books below to learn how to create web applications using ASP.NET:

A complementary part for this option is ASP.NET Web Forms that is a technology that you need to master if you are maintaining a legacy project. Please read this book to learn about ASP.NET Web Forms: Imar Spaanjaars (2014). Beginning ASP.NET 4.5.1 in C# and VB. Wrox.

The third option is Java world. If you are not familiar with Java language then please read the two books below first:

After that, please read one of the following books to learn how to create web applications using Java.

After that, please read this book to learn how to speed up Java web application development using Spring Boot framework: Mark Heckler (2021). Spring Boot – Up and Running – Building Cloud Native Java and Kotlin Applications. O’Reilly Media.

The 4th option is Node.js world. Please read the two books below to learn how to create web applications using Node.js:

There are also several other options that you may consider if you are required to learn them for maintening a project.
These options include:
Ruby on Rails, please read this book: Michael Hartl (2020). The Ruby on Rails Tutorial. Addison-Wesley Professional,
Flask, please read this book: Miguel Grinberg (2018). Flask Web Development: Developing Web Applications with Python. O’Reilly Media,
Django
.

IIf you need to convert a web application from one platform to another or create a web application framework, please read the two books below to learn about the architecture of web applications:

It seems that there are many topics to learn. I am completely new to web programming. What essential knowledge should I focus on to reduce my learning time?

You could focus on these topics first:

  • How to install necessary tools and create a Hello World application.
  • What is the physical structure of a project and how to build it using both IDE and command line?
  • How to deploy an application to a cloud virtual machine and access it via an URL.
  • How to create UIs, transfer data between UIs, compose new UI using existing UIs using frameworks and libraries.
  • How to use built-in or 3rd party libraries to interact with external databases and external services.
  • How to integrate with other web services using standards.

Terminology Review:

  • Networking
  • HTTP
  • HTML
  • Cascading Style Sheets (CSS)
  • CGI
  • Web Applications
  • Multiple Page Application
  • Single-Page Application (SPA)
  • RESTful APIs
  • gRPC APIs
  • GraphQL APIs
  • XML
  • SOAP APIs
  • Web Application Frameworks
  • Portal Frameworks
  • Content Management System (CMS)
  • Payment Gateways

After finishing web application development, please click on Topic 9 – Introduction to Mobile Application Development to continue.

 

Topic 5 – Object-Oriented Programming

Why do I need to learn about object-oriented programming?

Because most of modern software are written using object-oriented programming languages. Using object-oriented programming as a tool and more importantly as a problem solving approach will save you a lot of time and cost when you create modern software systems.

What can I do after finishing learning object-oriented programming?

You will be able to write a program to allow a user
– to draw a picture, save it, then load it, or
– to play ping-pong game, or
– to store and search for an employee’s CV.

Alright! What should I do now?

First, please read this book to gain a fundamental understanding of object-oriented programming with intuitive examples, and to distinguish object-oriented concepts from procedural programming concepts: Jim Keogh and Mario Giannini (2004). OOP Demystified. McGraw-Hill.

After that, please read this book to learn how to apply object-oriented concepts to creating real world software using a specific object-oriented programming language (i.e. C# language): RB Whitaker (2017). The C# Player’s Guide. Starbound Software.

After that, please take a quick look at one of the books below so you can refer to a specific topic that requires further study when developing real-world software:

I hear that there are many object-oriented programming languages, such as C++, C#, Java, PHP, Objective-C, Swift, Python, and Ruby. How many object-oriented programming languages do I need to learn?

You should learn as many as possible. However, at this stage, we recommend that you focus on learning only C++, C#, or Java.

C++ is the most widely used language for developing high-performance software systems, including games, operating systems, compilers, database management systems, web browsers, graphics editors, and medical or engineering applications.

Java and C# are the most widely used languages for developing enterprise systems.

If you are required or prefer to learn C++, please read this book to learn the core concepts of object-oriented programming with C++ implementation and specific features: Bjarne Stroustrup (2013). The C++ Programming Language. Pearson Education.

If you are required or prefer to learn Java, please read this book to learn the core concepts of object-oriented programming with Java implementation and specific features: Herbert Schildt (2019). Java: The Complete Reference. McGraw-Hill Education.

You should focus on mastering the core object-oriented principles such as encapsulation, inheritance, polymorphism, and abstraction, rather than trying to learn every OOP language. Once you understand these principles well, you can apply them across different languages with relatively little effort.

After that, please read the two books below to deepen your understanding of OOP concepts and to learn how to design software more efficiently using this approach:

Terminology Review:

  • Abstraction.
  • Encapsulation.
  • Class-based Inheritance.
  • Prototype-based Inheritance.
  • Polymorphism.
  • Types.
  • Method Variables (C++ Function Pointers, C# Delegates).
  • Concurrency.
  • Collections.
  • Object-Oriented Analysis.
  • Object-Oriented Design.
  • Object-Oriented Programming.

After finishing learning about object-oriented programming, please click on Topic 6 – Introduction to Windows Programming to continue.

Topic 3 – Introduction to Programming

Why do I need to know a programming language?

Because you will develop your software using a programming language.
A programming language is a language that both you and a computer will understand.
It’s a tool for you to express what you want a computer to do.
It’s a tool for you to write the instructions of your computer programs.
Without knowledge of a programming language, you cannot develop software.

I hear that there are many programming languages such as C, C++, C#, Objective-C, Java, Swift, Ruby, Python, JavaScript, PHP, F#, Kotlin, Clojure, Go, and Lisp.
How many programming languages should I know?

As many as possible. However, at this stage, you should first learn about the structure of a computer program and a procedural language (e.g., C or C++).

What can I do after finishing learning programming language?

You will be able to write programs that tell a computer to:

  • perform calculations,
  • count the occurrences of a string,
  • store and search for a string,
  • sort a list of numbers, or
  • display an image.

What should I do now?

Please read this book to learn programming using the C language: Stephen Prata (2011). C Primer Plus. Pearson.

Alternatively, you can read this book (from Chapter 1 to Chapter 9), to learn programming using the C++ language: Stephen Prata (2012). C++ Primer Plus. Pearson.

Alternatively, you can read these books to learn programming using the Python language:,

Alternatively, you can read this book (from Chapter 1 to Chapter 11), to learn programming using the Ruby language: Chris Pine (2013). Learn to Program: The Facets of Ruby Series. The Pragmatic Bookshelf.

Alternatively, you can read these books to learn programming using the Go language:

After that, if you would like to study system programming in depth, please read one of the following books:

After that, if you would like to build your vocabulary and gain in-depth knowledge of programming, especially the relationship between mathematics and programming, as well as the ideas of functional programming and logic programming, then please read the book or the notes below:

Terminology Review:

  • Computer Programs.
  • Compilers.
  • Just-In-Time Compilers.
  • Interpreters.
  • Structured Programming.
  • Procedural Programming.
  • Object-Oriented Programming.
  • Functional Programming.
  • Declarative Programming.
  • Logic Programming.
  • Primitive Types: int, float, double, string, date/time, null.
  • Basic Constructs: variables & assignments, pointers, declarations, functions, macro.
  • Control Flow: if/else, while, switch, for, break, continue, recursion, exception, parallelism, signal, jump.
  • User-defined Types: struct, class, type.
  • Data Structures: Arrays, Lists, Linked Lists, Dictionaries.
  • Object-Oriented Programming: abstraction, encapsulation, class-based inheritance, prototype-based inheritance, polymorphism.
  • Functional Programming: first-class and higher-order functions, no side effects, recursion.
  • Modularity: files, packages, namespaces, libraries, modules.
  • Concurrency: processes, threads, locks, channels, timers, callbacks, events, promises, event loop.
  • Type system: static type, dynamic type.
  • Error handling: try/catch.
  • Metaprogramming: reflection, template programming, DSL.
    • Clojure.

    After finishing programming, please click on Topic 4 – Introduction to Data Structures and Algorithms to continue.