PHP Tips & Notes
Compile PHP 5.6 on CentOS
Step 1: Install required dependencies
Before we start compiling PHP, we need to install some required dependencies. Open the terminal and type the following command:
yum install gcc make openssl-devel libxml2-devel bzip2-devel libcurl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel
This command will install all the necessary dependencies required to compile PHP.
Step 2: Download PHP 5.6
Next, we need to download the PHP 5.6 source code from the official website. Open the terminal and run the following command:
wget https://www.php.net/distributions/php-5.6.40.tar.gz
This command will download the PHP 5.6 source code to your server.
Step 3: Extract the source code
Once the download is complete, we need to extract the source code. Run the following command to extract the source code:
tar -zxvf php-5.6.40.tar.gz
This command will extract the source code to a new directory named ‘php-5.6.40’.
Step 4: Configure PHP
Now that we have extracted the source code, we need to configure PHP for our server. Run the following command to configure PHP:
cd php-5.6.40
./configure --prefix=/usr/local/php5.6 --with-config-file-path=/usr/local/php5.6/etc --with-apxs2=/usr/sbin/apxs --enable-mbstring --with-curl --with-openssl --with-zlib --with-gettext --with-gd --with-jpeg-dir=/usr/lib --with-png-dir=/usr/lib --with-freetype-dir=/usr/lib --with-mcrypt
This command will configure PHP with the required options.
Step 5: Compile PHP
Once the configuration is complete, we can now compile PHP. Run the following command to compile PHP:
make
This command will compile PHP with the options we configured in the previous step.
Step 6: Install PHP
After the compilation is complete, we can now install PHP. Run the following command to install PHP:
make install
This command will install PHP on your server.
Step 7: Verify PHP installation
Finally, we can verify the PHP installation by running the following command:
/usr/local/php5.6/bin/php -v
This command will display the PHP version installed on your server.
Install PHP on Ubuntu
- For PHP 8.3
sudo apt install php8.3 -y
- For PHP 8.2
sudo apt install php8.2 -y
- For PHP 7.4
sudo apt install php7.4 -y
Install PHP Extensions
sudo apt install phpX.X-extension_name
sudo apt install php8.3-mysql
Install phpMyAdmin on CentOS
Prerequisites
Before proceeding with the installation process, you must have the following prerequisites:
- A CentOS server with root access
- Apache web server installed and running
- PHP installed and running
- MySQL or MariaDB installed and running
Installing phpMyAdmin
To install phpMyAdmin on CentOS, follow the steps below:
- Open a terminal window and log in as root.
-
Run the following command to install the EPEL repository:
yum install epel-release
-
Once the repository is installed, run the following command to install phpMyAdmin:
yum install phpMyAdmin
-
After the installation process is complete, open the phpMyAdmin configuration file using your preferred text editor:
vim /etc/httpd/conf.d/phpMyAdmin.conf
-
Uncomment the following line by removing the ‘#’ symbol at the beginning of the line:
# Require ip 127.0.0.1
-
Save and close the file.
-
Restart the Apache web server:
systemctl restart httpd
-
Open a web browser and navigate to your server’s IP address followed by ‘/phpMyAdmin’. For example, if your server’s IP address is 192.168.1.100, navigate to:
<http://192.168.1.100/phpMyAdmin>
-
You will be prompted to enter your MySQL/MariaDB username and password. Once you have entered them, click on the ‘Go’ button.
PHP Error Summary
PHP configure error mcrypt.h not found
download libmcrypt
wget http://jaist.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
exact
tar -zxvf libmcrypt-2.5.8.tar.gz
config compile parameter
cd libmcrypt-2.5.8
./configure
compile and install
make && make install
PHP 5.6 failed to open configuration file
Problem
After PHP is compiled and installed, it fails to start, prompting
1 [23-Jun-2014 12:27:02] ERROR: failed to open configuration file '/usr/local/php/etc/php-fpm.conf': No such file or directory (2)
2 [23-Jun-2014 12:27:02] ERROR: failed to load configuration file '/usr/local/php/etc/php-fpm.conf'
3 [23-Jun-2014 12:27:02] ERROR: FPM initialization failed
Reason: The configuration file is not ready
Solution
Copy php-fpm.conf.default to php-fpm.conf
cp php-fpm.conf.default php-fpm.conf
Call Python in PHP code
phpy
is a Python
and PHP
interoperability library that allows you to use Python
functions and libraries in PHP
, or use PHP
packages in Python
. However, it is not language embedding. The encoding still uses their respective native syntax.
phpy
enables PHP
to call all Python
packages, including popular libraries such as PyTorch
, transformers
, TensorFlow
, as well as scientific computing libraries like Numpy
, Pandas
, Scikit
, and graphical interface libraries such as PyQt
, wxPython
.
- Currently, it only supports Linux platform (theoretically can support all operating systems, to be implemented)
- Does not support Python multi-threading and
async-io
features
Calling Python from PHP
Compile and install phpy.so
as an extension, then modify php.ini
to add extension=phpy.so
.
Example:
$os = PyCore::import("os");
$un = $os->uname();
echo strval($un);
Calling PHP in Python
You can directly use it as a C++ Module
by importing and loading it.
import phpy
content = phpy.call('file_get_contents', 'test.txt')
o = phpy.Object('redis')
assert o.call('connect', '127.0.0.1', 6379)
rdata = phpy.call('uniqid')
assert o.call('set', 'key', rdata)
assert o.call('get', 'key') == rdata
Both ZendVM
and CPython VM
are created within the same process. They directly call each other using C functions within the process stack space. The only overhead is the conversion between zval
and PyObject
structures, making it highly efficient.
Example of implementing a GUI using tkinter
<?php
$tkinter = PyCore::import('tkinter');
$root = $tkinter->Tk();
$root->title('windows');
$root->geometry("500x500");
$root->resizable(False, False);
$button = $tkinter->Button($root, text: "Click Me!!", command: PyCore::fn(function () {
var_dump(func_get_args());
echo 'click me!!' . PHP_EOL;
}));
$button->pack();
$tkinter->mainloop();
Reference
https://www.php.net/
- Top PHP Monitoring Tools
https://www.atatus.com/blog/php-monitoring-tools/
- How to Install PHP
https://tecadmin.net/how-to-install-php-on-ubuntu-24-04/
- Mastering PHP Configuration
https://www.atatus.com/blog/php-configuration-php-value-php-admin-value-and-php-flag-directives/
- Install a LAMP server
https://rdr-it.io/en/ubuntu-22-04-install-a-lamp-server-linux-apache-mariadb-php/
- Install Lighttpd with MariaDB and PHP-FPM
https://www.howtoforge.com/how-to-install-lighttpd-with-mariadb-and-php-fpm-on-ubuntu-22-04/
- Setup Nginx with PHP-FPM
https://tecadmin.net/how-to-setup-nginx-with-php-fpm-on-ubuntu-24-04/
https://github.com/swoole/phpy