Extensible Markup Language [XML] is a markup language similar to HTML, but the difference between HTML and XML is HTML has predefined tags but in XML we can create our own tags. The format of XML is standardized, if we share or transmit the XML over other systems and platform the receiver still will be able to parse the data due to the standardized XML syntax. XHTML, MathML, SVG, XUL, XBL, RSS, RDF, etc are some languages based on XML. The php-xml package is a dependency package and it depends on the default version of PHP in Ubuntu. This package contains different types of modules for PHP like DOM, WDDX, XML, SimpleXML, and XSL modules.
Nội dung chính
- Installation of php-xml in Ubuntu
- Cài đặt PHP trên Ubuntu
- Chạy PHP với Nginx
- Chạy nhiều phiên bản PHP trên cùng server
- Sử dụng lệnh dnf trên CentOS
- Cài đặt PHP 8 khi mạng bị chặn
Installation of php-xml in Ubuntu
Step 1: Verify the installation of php-xml on ubuntu. Before installing php-xml in Ubuntu first we check it is already present in the system or not. So open terminal on your ubuntu system and run the following command
dpkg –list | grep php-xml
If you get no result like in the given image, then follow the steps below to install php-xml.
Step 2: To install php-xml in Ubuntu, update your system packages using the following command.
sudo apt-get update -y
Step 3: After updating system packages now we install the php-xml using the following command.
sudo apt-get install -y php-xml
Step 4: Now we again verify the installation using the following command.
dpkg –list | grep php-xml
So this is how we install php-xml in Ubuntu.
If you cannot access the extensions classes then it is not loaded.
I think you opened a bug report, to which I responded that your configure line is malformed.
The configure line you want to use is:
./configure --enable-pthreads --enable-maintainer-zts
The above command will build pthreads as a DSO.
./configure --enable-pthreads=static --enable-maintainer-zts
The above command will build pthreads statically into PHP.
Both are equally supported by 5.3, 5.4 and even 5.5.
Additionally, if you are overwriting your system
installation then you should use a specific --prefix
, for example, if you php executable is at /usr/bin
[ which you can ascertain with "which php" ], then --prefix=/usr
will overwrite your system installation.
Clean out your old installations [ do make uninstall if the sources are still available ]. Start again, ensure you are either, overwriting the system installation or isolating this one completely.
Please update the bug report when you have worked it out.
Cài đặt PHP trên Ubuntu
Chúng ta sẽ cài đặt PHP 8.1.
Xóa PHP và các extension cũ:
sudo apt remove php php-*
sudo apt list --installed | grep phpsudo apt autoremove
sudo apt update
sudo apt list --upgradable sudo apt dist-upgrade
Thêm repository [bước này chỉ cần thực hiện một lần]:
sudo add-apt-repository ppa:ondrej/php
sudo apt update
Kiểm tra các package PHP có:
sudo apt-cache search php
Cài đặt và các extension thường dùng:
VERSION=8.1
sudo apt install php${VERSION}
for EXTENSION in common cli mysql mysqlnd gd mbstring xml zip curl ldap fileinfo redis bcmath; do sudo apt install php${VERSION}-${EXTENSION}; done
Cài extension php-fpm
để chạy PHP với Nginx:
sudo apt install php${VERSION}-fpm
Cài extension php-dev
để có lệnh phpize
để compile extension từ source [cài extension rar]:
sudo apt install php${VERSION}-dev
Câu lệnh tổng hợp chạy cho nhanh:
sudo apt install php8.1 \
php8.1-common \
php8.1-cli \
php8.1-mysql \
php8.1-mysqlnd \
php8.1-gd \
php8.1-mbstring \
php8.1-xml \
php8.1-zip \
php8.1-curl \
php8.1-ldap \
php8.1-fileinfo \
php8.1-redis \
php8.1-gmp \
php8.1-bcmath \
php8.1-fpm
Hiển thị danh sách các phiên bản PHP đã cài đặt [bạn có thể thiết lập luôn phiên bản mặc định]:
sudo update-alternatives --config php
Kiểm tra lại:
php --version
Tham khảo:
phly, boy, phly :: Managing Multiple PHP versions via the ondrej/php PPA
Chạy PHP với Nginx
Nginx hỗ trợ các module để giao tiếp với các trình xử lý PHP như FastCGI. Bài viết này sẽ hướng dẫn bạn cài đặt Nginx chạy php-fpm trên Ubuntu và CentOS.
Cài đặt
Đầu tiên phải cài PHP. Xem hướng dẫn ở đây. Chú ý cài extension php-fpm. Tên php-fpm nghĩa là PHP FastCGI process manager.
Tiếp theo cài Nginx. Xem hướng dẫn ở đây.
Tiếp theo cài php-fpm:
sudo apt install php8.1-fpm
Kiểm tra:
sudo systemctl status php8.1-fpm sudo systemctl start php8.1-fpm sudo systemctl stop php8.1-fpm sudo systemctl restart php8.1-fpm sudo systemctl enable php8.1-fpm
Cấu hình
Bây giờ bạn cần phải cấu hình Nginx để chạy PHP thông qua php-fpm.
Để cấu hình Nginx chạy php-fpm, bạn cần phải chỉnh sửa file config /etc/nginx/conf.d/default.conf
như sau:
server {
listen 80;
listen 443;
server_name localhost;
root /usr/share/nginx/html;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_split_path_info ^[.+\.php][/.+]$;
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
# fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
}
Chú ý chỉnh lại đường dẫn
fastcgi_pass
cho đúng thực tế.
Với Ubuntu [Debian], đường dẫn là:
unix:/var/run/php/php8.1-fpm.sock
Với CentOS [RedHat], đường dẫn là:
127.0.0.1:9000
Chạy nhiều phiên bản PHP trên cùng server
Để chạy từng phiên bản PHP trên mỗi web app, chúng ta chỉ cần chỉnh đường dẫn fastcgi_pass
cho đúng.
Ví dụ, chúng ta có hai phiên bản PHP là 7.2 và 8.1.
Ở Ubuntu, web app thứ nhất trỏ đến đường dẫn sau:
unix:/var/run/php/php7.2-fpm.sock
Web app thứ hai trỏ đến đường dẫn sau:
unix:/var/run/php/php8.1-fpm.sock
Ở CentOS, web app thứ nhất trỏ đến đường dẫn sau:
127.0.0.1:9072
Web app thứ hai trỏ đến đường dẫn sau:
127.0.0.1:9080
Ở CentOS, chúng ta cần chỉnh cổng của php-fpm. Chỉnh listen =
127.0.0.1:9000
ở file /etc/php-fpm.d/www.conf
như sau:
sudo sed -i 's/:9000/:9072/' /etc/opt/rh/rh-php72/php-fpm.d/www.conf sudo sed -i 's/:9000/:9080/' /etc/opt/rh/rh-php81/php-fpm.d/www.confsed -i 's/:9000/:9056/' /etc/opt/remi/php56/php-fpm.d/www.conf sed -i 's/:9000/:9072/' /etc/opt/remi/php72/php-fpm.d/www.conf
sudo grep -E '^\s*listen\s*=\s*[a-zA-Z/]+' /etc/php-fpm.d/www.conf
TODO
Sử dụng lệnh dnf trên CentOS
sudo dnf install //rpms.remirepo.net/enterprise/remi-release-8.rpm sudo dnf module list php sudo dnf module reset php sudo dnf module enable php:remi-7.3 sudo dnf install php73 php73-php-fpm -y sudo dnf module reset php sudo dnf module enable php:remi-7.4 sudo dnf install php74 php74-php-fpm -y sudo systemctl start php73-php-fpm sudo systemctl enable php73-php-fpm sudo systemctl status php73-php-fpm sudo systemctl start php74-php-fpm sudo systemctl enable php74-php-fpm sudo systemctl status php74-php-fpm unix:/var/opt/remi/php73/run/php-fpm/www.sock unix:/var/opt/remi/php74/run/php-fpm/www.sock
Tham khảo How To Run Multiple PHP Versions on One Server Using Apache and PHP-FPM on CentOS 8 | DigitalOcean.
Kiểm tra
Để kiểm tra xem bạn đã chạy được Nginx sử
dụng php-fpm hay chưa, bạn chỉ cần xem thông tin phpinfo[]
của máy chủ.
Tạo một file test.php
trong thư mục root của bạn:
vi /var/www/html/test.php
Nội dung của file: