Home>Article>Operation and Maintenance> Detailed explanation of how to install php on centos7

Detailed explanation of how to install php on centos7

藏色散人
藏色散人 Original
2020-08-07 10:03:14 3686browse

How to install php in centos7: first change the yum source and execute the command "#yum search php71w"; then use yum to install php71w and various extensions; finally create a new "index.php" in the web directory for testing That’s it.

Detailed explanation of how to install php on centos7

Recommended: "centos tutorial"

Nginx and httpd in front The installation was all done to support PHP, and then this goal gave me a heavy blow. Let me take my time to talk about the installation and configuration of PHP first.

1. PHP installation

1. Since the yum source of Linux does not exist for php7.x, we need to change the yum source:

#rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm #rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

2. Yum query installation php71w

#yum search php71w

3. Use yum to install php71w and various extensions, just choose what you need.

#yum install php71w php71w-cli php71w-common php71w-devel php71w-embedded php71w-fpm php71w-gd php71w-mbstring php71w-mysqlnd php71w-opcache php71w-pdo php71w-xml
#vim vim /etc/profile 在末尾添加
PATH=$PATH:/usr/local/php/bin  //记得修改为自己php的安装路径 export PATH :wq保存退出
source /etc/profile //运行该句指令使修改生效 php -v //就可以看到PHP版本信息了。

5. To test, create a new index.php in your own Nginx or Apache or self-built web page directory, and edit the content as e2d0e752df2c971bca1fcef6e50119b4

Then Enter 192.169.x.x:80/index.php on the web page. If you can see the php information page, it means your Nginx or httpd is installed successfully.

But I am not so lucky, especially on Nginx.

Since Nginx’s support for PHP requires the installation and startup of the php-fpm extension, at the beginning I installed and configured php-fpm separately, and started running systemctl start php-fpm.service systemctl start nginx,

netstat -lntp, you can see the started ports and services.

But during the test, index.php was always unable to be parsed. Instead, the index.php file was downloaded locally. It was very confusing. Then I gave up the configuration of Nginx and switched to configuring httpd. .

The same thing that has bothered me for a long time is that httpd can parse php files normally when I first started it. However, after I killed the httpd service for a while, I couldn’t reconcile myself to it. When I went to configure Nginx, it was still the same, so I came back to start httpd. At this time, even httpd could not parse php files and could only access html static files. There were also some abnormal phenomena. After careful inspection, I saw the following error in #systemctl status httpd, indicating that the process Process: 2401 failed to start. Thinking that the port with PID 2401 might be occupied, #netstat -anp --checked the status of all ports, but of course no occupancy status was found (speechless and crashed). Later, I restarted the instance and httpd, and it was fine. (I thought it might be due to process startup failure or port occupation, so I cleared the cache. The specific reason is still being explored, so I will make a record here.)

The reason why Nginx fails to parse PHP will continue to be studied. . .

The above is the detailed content of Detailed explanation of how to install php on centos7. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn