How to install suPHP for PHP5 on CentOS 7 (Peng Ge)

How to install suPHP for PHP5 on CentOS 7 (Peng Ge)

By default, PHP on CentOS 7 runs as apache or nobody. This method requires large permissions to run PHP, which may pose a security risk and may also be affected by other users of the server.

View the PHP information through phpinfo as follows:

apache runs php

As you can see, PHP is currently running as part of Apache, rather than running a separate process for each script. If you want PHP scripts to run as the current user instead of Apache, you can do this by deploying suPHP. Next, we will introduce how to install suPHP on CentOS 7.

First configure the environment required to install suphp:

yum -y groupinstall 'Development Tools'
yum -y install apr-devel
yum -y install httpd-devel

Download suphp installation package:

mkdir temp
cd temp
wget http://suphp.org/download/suphp-0.7.2.tar.gz
tar zxvf suphp-0.7.2.tar.gz

Download and install the suphp patch:

wget -O patchingsuphp.patch https://www.webhostinghero.com/downloads/php/suphp.patch
patch -Np1 -d suphp-0.7.2 < patchingsuphp.patch
cd suphp-0.7.2
autoreconf -if

Run ./configure:

./configure --prefix=/usr/ --sysconfdir=/etc/ --with-apr=/usr

/bin/apr-1-config --with-apache-user=apache --with-setid-mode=owner

--with-logfile=/var/log/httpd/suphp_log

Compile and install:

make
make install

Create suphp.conf in the Apache configuration directory

vi /etc/httpd/conf.d/suphp.conf

And write:

LoadModule suphp_module modules/mod_suphp.so

Create the suphp.conf configuration file in the /etc directory:

vi /etc/suphp.conf

And write the configuration file content as follows:

[global]
;Path to logfile
logfile=/var/log/httpd/suphp.log
;Loglevel
loglevel=info
;User Apache is running as
webserver_user=apache
;Path all scripts have to be in
docroot=/
;Path to chroot() before executing script
;chroot=/mychroot
; Security options
allow_file_group_writeable=true
allow_file_others_writeable=false
allow_directory_group_writeable=true
allow_directory_others_writeable=false
;Check what script is within DOCUMENT_ROOT
check_vhost_docroot=true
;Send minor error messages to browser
errors_to_browser=false
;PATH environment variable
env_path=/bin:/usr/bin
;Umask to set, specify in octal notation
umask=0077
; Minimum UID
min_uid=100
; Minimum GID
min_gid=100

[handlers]
;Handler for php-scripts
x-httpd-suphp="php:/usr/bin/php-cgi"
;Handler for CGI-scripts
x-suphp-cgi="execute:!self"

If you want the domainname directory to run as user user, then change the directory owner property to user, as follows:

chown -R [user].[user] /var/www/html/[domainname]

Finally, find the corresponding domain name in the Apache configuration file and enable suphp:

<FilesMatch ".+\.ph(p[345]?|t|tml)$">
SetHandler None
</FilesMatch>
<IfModule mod_suphp.c>
suPHP_Engine on
<FilesMatch "\.php[345]?$">
SetHandler x-httpd-suphp
</FilesMatch>
suPHP_AddHandler x-httpd-suphp
</IfModule>

Finally restart Apache file. Through the info.php test, we can find that the Server API running the domain name has changed from Apache to CGI/FastCGI, as shown in the following figure:

At this point we have completed CentOS's domain name access settings to run through suph instead of the default Apache Handler. Other domain names need to be set up. Just follow the above steps again.

You may also be interested in:
  • Detailed instructions for installing SuPHP on CentOS 7.2

<<:  MySQL 8.0.16 installation and configuration graphic tutorial under macOS

>>:  An in-depth introduction to React refs

Recommend

In-depth explanation of Set and WeakSet collections in ES6

Table of contents Set is a special collection who...

This article will help you understand JavaScript variables and data types

Table of contents Preface: Kind tips: variable 1....

Mysql 8.0 installation and password reset issues

Mysql 8.0 installation problems and password rese...

Linux 6 steps to change the default remote port number of ssh

The default ssh remote port in Linux is 22. Somet...

Vue basics MVVM, template syntax and data binding

Table of contents 1. Vue Overview Vue official we...

Example of how to upload a Docker image to a private repository

The image can be easily pushed directly to the Do...

Detailed explanation of CocosCreator optimization DrawCall

Table of contents Preface What is DrawCall How do...

Example code for implementing hexagonal borders with CSS3

The outermost boxF rotates 120 degrees, the secon...

Lombok implementation JSR-269

Preface Introduction Lombok is a handy tool, just...

A simple example of how to implement fuzzy query in Vue

Preface The so-called fuzzy query is to provide q...

html+css+js to realize the function of photo preview and upload picture

Preface: When we are making web pages, we often n...

How to solve the mysql insert garbled problem

Problem description: When inserting Chinese chara...

Can MySQL's repeatable read level solve phantom reads?

introduction When I was learning more about datab...

Layui implements sample code for multi-condition query

I recently made a file system and found that ther...