Tag Archives: PHP

How to Manually Install PHP 7.4 for Windows Server 2019

Motivation:

To understand how PHP works with IIS in order to be able to update PHP to any version to address compatibility or security issues.

Using a tool to install PHP for IIS, for example Microsoft Web Platform Installer 5.0 https://www.microsoft.com/web/downloads/platform.aspx, restricts us from using only versions supported by the tool.

Solution:

  • Install CGI for IIS.
  • 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

Open a Command Prompt, execute below command and ensure that NO WARNINGS APPEAR.

php -version
  • Create phpinfo.php file with below content in the website folder and test the result.
<?php
phpinfo();
?>

 

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 7.1 for Windows Server 2016

Motivation:

To understand how PHP works with IIS in order to be able to update PHP to any version to address compatibility or security issues.

Using a tool to install PHP for IIS, for example Microsoft Web Platform Installer 5.0 https://www.microsoft.com/web/downloads/platform.aspx, restricts us from using only versions supported by the tool.

Solution:

  • Install CGI for IIS.
  • Download VC14 x86 Non Thread Safe package here or under PHP 7.1 section from http://windows.php.net/download/
  • Extract the ZIP file to C:\Program Files (x86)\php-7.1.33-nts-Win32-VC14-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.1.33-nts-Win32-VC14-x86\ext"

extension=php_curl.dll
extension=php_mbstring.dll
extension=php_mysqli.dll
extension=php_pdo_mysql.dll
extension=php_openssl.dll

error_log = "C:\Program Files (x86)\php-7.1.33-nts-Win32-VC14-x86\php_errors.log"

error_log = syslog
  • Add C:\Program Files (x86)\php-7.1.33-nts-Win32-VC14-x86 to System Path.
  • Download x86 package of WinCache 2.0 for PHP 7.1  here or from https://www.iis.net/downloads/microsoft/wincache-extension
  • Extract and copy the php_wincache.dll file to C:\Program Files (x86)\php-7.1.33-nts-Win32-VC14-x86\ext
    folder.
  • 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 (x86)\php-7.1.33-nts-Win32-VC14-x86\php-cgi.exe"
Name = PHP 7.1
Request Restrictions = File or folder
php -version
  • Create phpinfo.php file with below content in the website folder and test the result.
<?php
phpinfo();
?>

 

Topic 7 – 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 just 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. Please read this Semmy Purewal (2014). Learning Web App Development. O'Reilly Media book first to get familiar with web application development.
After that you will have 4 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 path, 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 they will still take us much time to learn how to apply implementation of an approach in real world solutions.
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 second and third option.
The first option is ASP.NET Core. Please read 
- this "Adam Freeman (2017). Pro ASP.NET Core MVC 2. Apress" book or 
- this "Dino Esposito (2018). Programming ASP.NET Core. Pearson Education" book.
A complementary part for this option is ASP.NET Web Forms. Please read this "Imar Spaanjaars (2014). Beginning ASP.NET 4.5.1: in C# and VB" book.
The second option is PHP world.  Please read 
- this Luke Welling and Laura Thomson (2016). PHP and MySQL Web Development. Addison-Wesley Professional book or
- this Robin Nixon (2018). Learning PHP, MySQL & JavaScript. O'Reilly book.

After that depending on your projects you can read these books below.
- Brad Williams, David Damstra and Hal Stern (2015). Professional WordPress: Design and Development. Wrox.
The third option is Java world. You will need to read 2 books for this option. Please get this "Cay S. Horstmann (2012). Core Java Volume I--Fundamentals" book and read it if you are not familiar with Java language.

Then please read 
- this "Tim Downey (2012). Guide to Web Development with Java: Understanding Website Creation" book or 
- this "Nicholas S. Williams (2014). Professional Java for Web Applications" book.
The 4th option is Node world.  Please read this
- this "Jonathan Wexler (2019). Get Programming with Node.js. Manning Publications" book, and
- this "Bruno Joseph D'mello et al. (2017). Web Development with MongoDB and Node. Packt Publishing" book.
After that please read 
- this Kirupa Chinnathambi (2018). Learning React. Addison-Wesley Professional book, and
- this Robin Wieruch (2020). The Road to React - Your Journey to Master Plain Yet Pragmatic React. Leanpub book to learn how to create a single page application (SPA).
After finishing these books if you want to create sophisticated interactive web applications please read 
- this "David Flanagan (2011). JavaScript - The Definitive Guide. Sixth Edition. O'Reilly Media" book and
- this "Kyle Simpson (2015). You Don't Know JS" book.
If you want to convert a web application from one platform to another or create a web application framework please read this "Leon Shklar and Richard Rosen (2009). Web Application Architecture: Principles, Protocols and Practices" book.
After finishing the books please click Topic 8 - Introduction to Mobile Application Development to continue.

 

Topic 4 – 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.

Alright! What should I do now?

Please read this Jim Keogh and Mario Giannini (2004). OOP Demystified. McGraw-Hill book.

Is that all?

Unfortunately, the book is not sufficient for writing real world object-oriented software. Although the book already gives you the fundamental concepts of object-oriented programming the examples are only to illustrate the concepts, not to demonstrate real world situations.

We recommend that you read it first because it introduces basic concepts of object-oriented programming very well. It helps you to distinguish object-oriented concepts from procedural programing concepts very clearly so that you could read other books to dig into real world object-oriented programming in a proper way.

Please read this RB Whitaker (2017). The C# Player's Guide. Starbound Software 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).
After that please take a quick look at  
- this Joseph Albahari and Eric Johannsen (2020). C# 8.0 in a Nutshell: The Definitive Reference. O'Reilly Media book or 
- this Herbert Schildt (2010). C# 4.0 The Complete Reference. McGraw Hill book so that you can refer to a specific topic that needs more 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, Ruby. How many object-oriented programming languages do I need to know?

You should learn as many as possible. However, in this stage, we recommend that you learn only C++ or C# or Java.
C++ is the most used language for creating software systems that need high performance, including games, operating systems, compilers, database management systems, web browsers, graphics editors, medical and engineering applications.
Java and C# are the most used languages for creating enterprise systems.
- If you are required or prefer to learn C++, please read this Bjarne Stroustrup (2013). The C++ Programming Language. Pearson Education book.
- If you are required or prefer to learn Java, please read this Herbert Schildt (2019). Java: The Complete Reference. McGraw-Hill Education book.
After that please read 
- this Matt Weisfeld (2019). The Object-Oriented Thought Process. Pearson Education book and 
- this Bertrand Meyer (1997). Object-Oriented Software Construction. Prentice Hall book to get deeper understanding about object-oriented concepts and learn how to design software using object-oriented approach more efficiently.
After finishing the books please click Topic 5 - Introduction to Windows Programming to continue.

Topic 2 – 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 instructions of your computer programs. Without knowledge of a programming language, you cannot develop any software.

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

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

What should I do now?

Please read this Stephen Prata (2011). C Primer Plus. Pearson book.
Alternatively, you can read from Chapter 1 to Chapter 9 of this Stephen Prata (2012). C++ Primer Plus. Pearson book.

Alternatively, you can read from Chapter 1 to Chapter 9 of this John M. Zelle (2017). Python Programming: An Introduction to Computer Science. Franklin, Beedle & Associates book.

Alternatively, you can read from Chapter 1 to Chapter 11 of this Charles Severance (2013). Python for Informatics: Exploring Information book.

Alternatively, you can read from Chapter 1 to Chapter 11 of this Chris Pine (2013). Learn to Program: The Facets of Ruby Series. The Pragmatic Bookshelf book.
After that please read this Harold Abelson and Gerald Jay Sussman (1996). Structure and Interpretation of Computer Programs. The MIT Press book to get a vocabulary and in-depth knowledge about programming, especially the relationship between mathematics and programming, and ideas of functional programming.
After finishing the books please click Topic 3 - Introduction to Algorithms and Data Structures to continue.