CentOS 7.3 Builds Apache+PHP7+web SVN+MariaDB Web Server (2017-08-20)

Keywords: PHP svn Apache vim

Note: This tutorial is installed using clean CentOS 7. If you have installed other environments or software, which involves kernel upgrades, please backup properly, which may lead to incompatibility or other problems with the installed software.

Disclaimer: This tutorial is written only from personal experience and may not be suitable for all system environments. I will not be responsible for any irreparable loss (such as data loss) during the course of using this tutorial.

Again, before using this tutorial, please backup the existing data properly! Please backup the existing data properly before using this tutorial! Please backup the existing data properly before using this tutorial!

If you have problems in using the methods in this tutorial, you may leave a message, and I will try my best to help solve them within my capabilities.

The final server environment configuration in this article:

Apache 2.7.27
subversion1.9.7
MariaDB10.2.28
php7.1.8

Let's start with the tutorial.

I. Upgrading Kernels and Software Packages

[root@instance-l79ltvo6 ~]# yum -y update
...    
Complete!

Until the console outputs Complete! Explain that the upgrade is complete, it's better to restart it.

[root@instance-l79ltvo6 ~]# reboot

Installation of apache 2.4.27

First install some basic dependencies

[root@instance-l79ltvo6 ~]# yum install -y gcc gcc-c++ openssl-devel zlib-devel
//Create a soft folder in the root directory, where all the software for this tutorial will be placed.
[root@instance-l79ltvo6 ~]# mkdir soft 
[root@instance-l79ltvo6 ~]# cd soft

Then start installing apr, apr-util, PCRE three dependencies, and finally install apache

1. Install apr

[root@instance-l79ltvo6 ~]# wget https://mirror.tuna.tsinghua.edu.cn/apache/apr/apr-1.6.2.tar.gz
[root@instance-l79ltvo6 ~]# tar zxf apr-1.6.2.tar.gz
[root@instance-l79ltvo6 ~]# cd apr-1.6.2/
[root@instance-l79ltvo6 ~]# ./configure --prefix=/usr/local/apr
[root@instance-l79ltvo6 ~]# make && make install
[root@instance-l79ltvo6 ~]# cd. // / Return to the parent directory

Because we use apr 1.6.2 dependencies, we have to use apr-util 1.6.0, apr-util 1.6.0.
Expat is no longer bundled, but needs expat support, so we have to install expat manually first. Otherwise, there will be an error when compiling apache.

2 Install expat

[root@instance-l79ltvo6 ~]# wget https://sourceforge.net/projects/expat/files/expat/2.2.3/expat-2.2.3.tar.bz2
[root@instance-l79ltvo6 ~]# tar jxf expat-2.2.3.tar.bz2
[root@instance-l79ltvo6 ~]# cd expat-2.2.3/
[root@instance-l79ltvo6 ~]# ./configure --prefix=/usr/local/expat
[root@instance-l79ltvo6 ~]# make && make install
[root@instance-l79ltvo6 ~]# cd. // / Return to the parent directory

3 Install apr-util

[root@instance-l79ltvo6 ~]# wget  https://mirror.tuna.tsinghua.edu.cn/apache/apr/apr-util-1.6.0.tar.gz
[root@instance-l79ltvo6 ~]# tar zxf apr-util-1.6.0.tar.gz
[root@instance-l79ltvo6 ~]# cd apr-util-1.6.0/
[root@instance-l79ltvo6 ~]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr --with-expat=/usr/local/expat
[root@instance-l79ltvo6 ~]# make && make install
[root@instance-l79ltvo6 ~]# cd. // / Return to the parent directory

4 Install pcre

[root@instance-l79ltvo6 ~]# wget http://sourceforge.mirrorservice.org/p/pc/pcre/pcre/8.41/pcre-8.41.tar.gz
[root@instance-l79ltvo6 ~]# tar zxf pcre-8.41.tar.gz
[root@instance-l79ltvo6 ~]# cd pcre-8.41/
[root@instance-l79ltvo6 ~]# ./configure --prefix=/usr/local/pcre
[root@instance-l79ltvo6 ~]# make && make install
[root@instance-l79ltvo6 ~]# cd. // / Return to the parent directory

5 Install apache

[root@instance-l79ltvo6 ~]# wget http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.27.tar.gz
[root@instance-l79ltvo6 ~]# tar zxf httpd-2.4.27.tar.gz
[root@instance-l79ltvo6 ~]# cd httpd-2.4.27/
[root@instance-l79ltvo6 ~]# ./configure \
--prefix=/usr/local/apache \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util \
--with-pcre=/usr/local/pcre \
--with-ssl \
--with-zlib \
--with-mpm=worker \
--enable-rewrite \
--enable-so \
--enable-ssl \
--enable-cache \
--enable-disk-cache \
--enable-file-cache \
--enable-mem-cache \
--enable-headers \
--enable-expires \
--enable-deflate \
--enable-dav \
--enable-dav-fs \
--enable-cgi \
--enable-proxy \
--enable-proxy-fcgi
//Here, please open the relevant modules according to your own actual situation.
[root@instance-l79ltvo6 ~]# make && make install
[root@instance-l79ltvo6 ~]# cd. // / Return to the parent directory

6 Modify apache configuration file

Edit/usr/local/apache/conf/httpd.conf

#LoadModule ssl_module modules/mod_ssl.so //Remove # Open SSL
#LoadModule rewrite_module modules/mod_rewrite.so  //Remove # and open rewrite
#ServerName www.example.com:80    //Remove # and change www.example.com:80 to your IP:80 or domain name
#Include conf/extra/httpd-vhosts.conf     //Remove # and turn on virtual host configuration
//If you need to install the svn service, you need to turn it on
#LoadModule dav_module modules/mod_dav.so//Get rid of

Find the following code and replace it

<Directory />
    AllowOverride none
    Require all denied
</Directory>
//Modified to
<Directory />
    Options Indexes FollowSymLinks    //If you don't need to display directories, remove Indexes
    AllowOverride ALL    //Open rewrite
    Require all granted
</Directory>

Edit / usr/local/apache/conf/extra/httpd-vhosts.conf, delete all, and add the following code

<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs"
    ServerName your IP    //Your IP address
    ErrorLog "logs/Your IP-error_log"
    CustomLog "logs/Your IP-access_log" common
</VirtualHost>

7 Adding Startup Services

[root@instance-l79ltvo6 ~]# cp /usr/local/apache/bin/apachectl  /etc/rc.d/init.d/
[root@instance-l79ltvo6 ~]# mv /etc/rc.d/init.d/apachectl /etc/rc.d/init.d/httpd
[root@instance-l79ltvo6 ~]# cd /etc/rc.d/init.d/

Edit httpd and add the following code under #!/bin/sh

# Comments to support chkconfig on RedHat Linux
# chkconfig: 2345 90 90
# description:http server

Registration service

[root@instance-l79ltvo6 ~]# chkconfig --add httpd
[root@instance-l79ltvo6 ~]# chkconfig httpd on

Add apache to system environment variables

[root@instance-l79ltvo6 ~]# vim /etc/profile.d/httpd.sh
//Write in
export PATH=$PATH:/usr/local/apache/bin
//Execution permission is granted after saving
[root@instance-l79ltvo6 ~]# chmod 0777 /etc/profile.d/httpd.sh
[root@instance-l79ltvo6 ~]# source /etc/profile.d/httpd.sh

8 Start apache

First check the configuration file for errors

[root@instance-l79ltvo6 ~]# /usr/local/apache/bin/apachectl -t
Syntax OK    //No problem. It can be started directly.

Start apache

[root@instance-l79ltvo6 ~]# systemctl start httpd.service

Then open the browser, enter your IP address and see It works!, indicating that apache started successfully.

It works!

III. Install subversion 1.9.7

(If no svn service is required, please skip)

1 Install scons

[root@instance-l79ltvo6 ~]# cd /root/soft
[root@instance-l79ltvo6 ~]# wget http://sourceforge.mirrorservice.org/s/sc/scons/scons/2.5.1/scons-2.5.1.tar.gz
[root@instance-l79ltvo6 ~]# tar zxf scons-2.5.1.tar.gz
[root@instance-l79ltvo6 ~]# cd scons-2.5.1/
[root@instance-l79ltvo6 ~]# python setup.py install --prefix=/usr/local/scons
[root@instance-l79ltvo6 ~]# cd. // / Return to the parent directory

2 Install serf

[root@instance-l79ltvo6 ~]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/serf/serf-1.3.9.tar.bz2
[root@instance-l79ltvo6 ~]# tar xf serf-1.3.9.tar.bz2
[root@instance-l79ltvo6 ~]# cd serf-1.3.9/
[root@instance-l79ltvo6 ~]# /usr/local/scons/bin/scons prefix=/usr/local/serf APR=/usr/local/apr APU=/usr/local/apr-util
[root@instance-l79ltvo6 ~]# /usr/local/scons/bin/scons install
[root@instance-l79ltvo6 ~]# cd. // / Return to the parent directory

3 Compile subverion

[root@instance-l79ltvo6 ~]# wget http://www.sqlite.org/2017/sqlite-amalgamation-3190300.zip
[root@instance-l79ltvo6 ~]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/subversion/subversion-1.9.7.tar.gz
[root@instance-l79ltvo6 ~]# tar zxf subversion-1.9.7.tar.gz
[root@instance-l79ltvo6 ~]# unzip sqlite-amalgamation-3190300.zip
[root@instance-l79ltvo6 ~]# mv /root/soft/sqlite-amalgamation-3190300 /root/soft/subversion-1.9.7/sqlite-amalgamation
[root@instance-l79ltvo6 ~]# cd subversion-1.9.7/
[root@instance-l79ltvo6 ~]# ./configure \
--prefix=/usr/local/svn \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util \
--with-serf=/usr/local \
--enable-mod-activation \
--with-apache-libexecdir=/usr/local/apache/modules \
--with-apxs=/usr/local/apache/bin/apxs  \
--without-berkeley-db
[root@instance-l79ltvo6 ~]# make && make install

Create a non-logged-in user named SVN for SVN

[root@instance-l79ltvo6 ~]# useradd svn -s /sbin/nologin

Add svn to system environment variables

[root@instance-l79ltvo6 ~]# vim /etc/profile.d/svn.sh
//Add to
export PATH=$PATH:/usr/local/svn/bin
//Execution permission is granted after saving
[root@instance-l79ltvo6 ~]# chmod 0777 /etc/profile.d/svn.sh
[root@instance-l79ltvo6 ~]# source /etc/profile.d/svn.sh

Create a serf-1.3.9.conf at / etc/ld.so.conf.d/, specify the lib directory, otherwise the svn startup will report an error

[root@instance-l79ltvo6 ~]# vim /etc/ld.so.conf.d/serf-1.3.9.conf
//Add to
/usr/local/lib
//Refresh after saving
[root@instance-l79ltvo6 ~]# /sbin/ldconfig -v

4 Configure subverion

Let's first create a test project

[root@instance-l79ltvo6 ~]# mkdir -p /data/svn
[root@instance-l79ltvo6 ~]# cd /data/svn
[root@instance-l79ltvo6 ~]# svnadmin create test

Then we open / data/svn/test / and find that some directories are created automatically.

conf
db
format
hooks
locks
README.txt

The file in conf is to configure the personnel and authority of the project, but if multiple projects are the same as developers, it will have to be configurated many times, which is very troublesome, so we need to configure the permission once to apply directly to all projects.

[root@instance-l79ltvo6 ~]# cp /data/svn/test/conf/authz  /data/svn/authz
[root@instance-l79ltvo6 ~]# cp /data/svn/test/conf/passwd  /data/svn/passwd
[root@instance-l79ltvo6 ~]# cp /data/svn/test/conf/svnserve.conf  /data/svn/svnserve.conf
//Then set up a user password. Here's an example of creating a root user. The demonstration here is to encrypt the password instead of storing it in plaintext.
[root@instance-l79ltvo6 ~]# htpasswd -c /data/svn/passwd root
New password:       //Input password
Re-type new password:    //Enter the password again

In this way, the root user is created, and the same is true for other users. Next we need to modify the configuration file

[root@instance-l79ltvo6 ~]# vim /data/svn/svnserve.conf
//Delete everything and add the following code
[general]
anon-access = read
auth-access = write
password-db = passwd
authz-db = authz
[sasl]
//Preservation
[root@instance-l79ltvo6 ~]# vim /data/svn/authz
//Delete everything and add the following code
[aliases]
# joe = /C=XZ/ST=Dessert/L=Snake City/O=Snake Oil, Ltd./OU=Research Institute/CN=Joe Average

[groups]
administrators = root

[/]
@administrators=rw

[test:/]
* = r
//Preservation

Let's try to start the svn service

[root@instance-l79ltvo6 ~]# svnserve --config-file /data/svn/svnserve.conf -d -r /data/svn

No error was reported, indicating that the startup was successful.
Change the owner of / data/svn / directory to svn

[root@instance-l79ltvo6 ~]# chown -R svn:svn /data/svn

Finally, we need to modify the apache configuration file
Edit/usr/local/apche/conf/httpd.conf

//find
User daemon
Group daemon
//Modified to
User svn
Group svn

Edit / usr/local/apache/conf/extra/httpd-vhost.conf and replace the content you just edited with

<VirtualHost *:80>
    ServerName Your IP
    ErrorLog "logs/Your IP-error_log"
    CustomLog "logs/Your IP-access_log" common
    <Location /svn>
      DAV svn
      #support more repositories
      SVNParentPath /data/svn

      #list all repositories
      #SVNListParentPath on
      AuthType Basic
      AuthName "Please input Username and Password"
      AuthUserFile /data/svn/passwd
      AuthzSVNAccessFile /data/svn/authz
      Require valid-user
    </Location>
</VirtualHost>

Then stop the apache service

[root@instance-l79ltvo6 ~]# systemctl stop httpd.service

Check the apache configuration file for errors

[root@instance-l79ltvo6 ~]# /usr/local/apache/bin/apachectl -t
Syntax OK    //No problem. It can be started directly.

Restart apache

[root@instance-l79ltvo6 ~]# systemctl start httpd.service

Open Browser Accesshttp:// Your ip/svn/test prompts you to enter your account password and use Tortoise SVN to operate as well.
Enter the account password you just set and display it

test - Revision 0: /

Explain that the configuration was successful and the apache+svn service started successfully

IV. Installation of MariaDB 10.2.8

Reference resources https://segmentfault.com/a/11... Change the relevant version number to 10.2.8

V. Installation of PHP 7.1.8

First install basic dependencies

[root@instance-l79ltvo6 ~]# yum -y install gcc gcc-c++ autoconf automake libtool re2c flex bison php-mcrypt libmcrypt libmcrypt-devel openssl-devel libxml2-devel libcurl-devel libjpeg-devel libpng-devel freetype-devel zlib-devel mcrypt bzip2-devel libicu-devel systemd-devel mhash postgresql-devel libxslt libxslt-devel

Compile PHP

[root@instance-l79ltvo6 ~]# cd /root/soft
[root@instance-l79ltvo6 ~]# wget http://cn.php.net/distributions/php-7.1.8.tar.gz
[root@instance-l79ltvo6 ~]# tar zxf php-7.1.8.tar.gz
[root@instance-l79ltvo6 ~]# cd php-7.1.8/
[root@instance-l79ltvo6 ~]# ./configure \
--prefix=/usr/local/php \
--with-apxs2=/usr/local/apache/bin/apxs \
--with-curl \
--with-freetype-dir \
--with-gd \
--with-gettext \
--with-iconv-dir \
--with-kerberos \
--with-libdir=lib64 \
--with-libxml-dir \
--with-mysqli \
--with-openssl \
--with-pcre-regex \
--with-pdo-mysql \
--with-pdo-sqlite \
--with-pear \
--with-png-dir \
--with-xmlrpc \
--with-xsl \
--with-zlib \
--with-mhash \
--enable-fpm \
--enable-bcmath \
--enable-libxml \
--enable-inline-optimization \
--enable-gd-native-ttf \
--enable-mbregex \
--enable-mbstring \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-xml \
--enable-zip \
--enable-mysqlnd
[root@instance-l79ltvo6 ~]# make && make install
...    //Long wait

Compile successfully

[PEAR] Archive_Tar    - installed: 1.4.3
[PEAR] Console_Getopt - installed: 1.4.1
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util       - installed: 1.4.2
[PEAR] PEAR           - installed: 1.10.5
Wrote PEAR system config file at: /usr/local/php/etc/pear.conf
You may want to add: /usr/local/php/lib/php to your php.ini include_path
/root/soft/php-7.1.8/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin
ln -s -f phar.phar /usr/local/php/bin/phar
Installing PDO headers:           /usr/local/php/include/php/ext/pdo/

Let's copy a copy of php.ini from the source package to / usr/local/php/lib/

[root@instance-l79ltvo6 ~]# cp php.ini-development /usr/local/php/lib/php.ini

Modify apache to support php
Edit/usr/local/apache/conf/httpd.conf

LoadModule php7_module        modules/libphp7.so    //The default is to turn on php7.so
//Find <IfModule mime_module> and add it before </IfModule>.
    AddType application/x-httpd-php .php .php3 .phtml .inc
    AddType application/x-httpd-php-source .phps
//Find DirectoryIndex. HTML and add index.php
DirectoryIndex index.html index.shtml index.cgi index.php index.phtml index.php3

Save and see if httpd.conf has any errors

[root@instance-l79ltvo6 ~]# /usr/local/apache/bin/apachectl -t
Syntax OK    //No problem. It can be started directly.

Add PHP to environment variables

[root@instance-l79ltvo6 ~]# vim /etc/profile.d/php.sh
//join
export PATH=$PATH:/usr/local/php/bin
//Execution permission is granted after saving
[root@instance-l79ltvo6 ~]# chmod 0777 /etc/profile.d/php.sh
[root@instance-l79ltvo6 ~]# source /etc/profile.d/php.sh

Stop apache and restart apache

[root@instance-l79ltvo6 ~]# systemctl stop httpd.service
[root@instance-l79ltvo6 ~]# systemctl start httpd.service

Test PHP

[root@instance-l79ltvo6 ~]# vim /usr/local/apache/htdocs/phpinfo.php
//join
<?php
  phpinfo();
?>

Post-save accesshttp:// Your IP/phpinfo.php
If the relevant information of PHP is successfully accessed, the PHP environment is successfully configured.

End of tutorial

This tutorial has been successfully constructed under CentOS 7.3.
If compilation fails, don't be discouraged. Generally, they lack relevant dependencies and are good at using search engines. If I really don't know how to solve it, leave me a message. I will try my best to help solve it within my ability.
I think this article is useful. Don't forget to praise and collect it.

Posted by zeezack on Tue, 01 Jan 2019 17:57:08 -0800