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

Vue+Openlayer uses modify to modify the complete code of the element

Vue+Openlayer uses modify to modify elements. The...

How to insert 10 million records into a MySQL database table in 88 seconds

The database I use is MySQL database version 5.7 ...

Introduction to using the MySQL mysqladmin client

Table of contents 1. Check the status of the serv...

Example of asynchronous file upload in html

Copy code The code is as follows: <form action...

How to customize at and cron scheduled tasks in Linux

There are two types of scheduled tasks in Linux s...

How to detect Ubuntu version using command line

Method 1: Use the lsb_release utility The lsb_rel...

Example code for evenly distributing elements using css3 flex layout

This article mainly introduces how to evenly dist...

In-depth understanding of Vue's data responsiveness

Table of contents 1. ES syntax getter and setter ...

How to configure NAS on Windows Server 2019

Preface This tutorial installs the latest version...

Layui implements sample code for multi-condition query

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

A brief talk about the diff algorithm in Vue

Table of contents Overview Virtual Dom principle ...