Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed explanation of lamp (compilation and installation, module or php-fpm) of CentOS 6 system

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

LAMP refers to a group of free software acronyms that are usually used together to run dynamic websites or servers:

1. Linux; operating system

2. Apache; web server

3. MariaDB or MySQL, database management system (or database server)

4. PHP, Perl or Python, scripting language

Experimental requirements:

(1) the three are separated from two or three hosts

(2) one virtual host is used to provide phpMyAdmin; and the other virtual host is used to provide wordpress

(3) xcache

(4) try that mpm is a non-prefork mechanism

IP system software 192.168.1.102CentOS 6.7httpd (event) 192.168.1.103CentOS 6.7 phpmurfpmJournal xcache192.168.1.104 CentOS 6.7mariadb

CentOS 6:

PHP-5.3.2-: does not support fpm mechanism by default; you need to patch and compile and install it yourself.

Httpd-2.2: fcgi protocol is not supported by default. You need to compile this module by yourself.

Solution: compile and install httpd-2.4,apr,apr-util version 1.4fujie phpmae 5.3.3+

Experimental installation version: httpd-2.4.10 + apr-1.5.0+ apr-util-1.5.3 + php-5.4.40 + xcache-3.2.0 + mariadb-5.5.46

192.168.1.102 host, compiling and installing httpd-2.4.10 + apr-1.5.0 + apr-util-1.5.3

Httpd-2.4.10 requires newer versions of apr and apr-util, so you need to upgrade them in advance, here using source code compilation and installation.

Package download address for apr and apr-util: https://archive.apache.org/dist/apr/

Download address of httpd program source package: https://archive.apache.org/dist/httpd/

1. Install the development environment package group and development package

# hwclock-s / / synchronize software time to hardware time

# yum grouplist / / View package groups

# yum groupinstall "Development Tools"Server Platform Development"-y / / Development environment package group

# yum install pcre-devel-y / / httpd-2.4.10 compilation process depends on pcre-devel package

2. Compile and install apr

# tar xf apr-1.5.0.tar.bz2

# cd apr-1.5.0

#. / configure-prefix=/usr/local/apr

# make & & make install

3. Compile and install apr-util

# tar xf apr-util-1.5.3.tar.bz2

# cd apr-util-1.5.3

#. / configure-prefix=/usr/local/apr-util-with-apr=/usr/local/apr

# make & & make install

4. Compile, install and configure httpd-2.4.10

4.1 compilation and installation

# rpm-qa httpd

Httpd-2.2.15-45.el6.centos.x86_64

# yum remove httpd-y / / Uninstall the httpd previously installed in the rpm package

# tar xf httpd-2.4.10.tar.bz2

# cd httpd-2.4.10

# / configure-- prefix=/usr/local/apache24-- sysconfdir=/etc/httpd24-- enable-so-- enable-ssl-- enable-cgi-- enable-cgid-- enable-rewrite-- enable-modules=most-- enable-mods-shared=most-- enable-mpms-shared=all-- with-mpm=event-- with-zlib-- with-pcre-- with-apr=/usr/local/apr-- with-apr-util=/usr/local/apr-util

# make & & make install

/ / sysconfdir=/etc/httpd24 specifies the location where the profile is installed

/ / enable-so supports dynamic sharing module (DOS). Without this module, PHP cannot work with apache.

/ / enable-ssl supports ssl function

/ / enable-proxy supports agents

/ / enable-proxy-fcgi supports fcgi

/ / enable-cgi supports cgi

/ / enable-rewrite supports URL rewriting

/ / which modules are enabled for enable-modules=most

/ / enable-mpms-shared=all supports multiprocessing module

/ / with-mpm=event sets the default module to prefork module

/ / with-zlib supports compression libraries to facilitate the sending and receiving of compressed pages, and can save bandwidth when spreading over the Internet.

/ / with-pcre supports regular expressions extended by cre and supports more powerful regular expression parsing.

4.2 modify the httpd.pid path. The default installation path is / usr/local/apache24/logs

# / usr/local/apache24/bin/apachectl start

# / usr/local/apache24/bin/apachectl stop

# vim / etc/httpd24/httpd.conf

Pidfile "/ var/run/httpd.pid" / / add this line under ServerRoot "/ usr/local/apache24"

# / usr/local/apache24/bin/apachectl start

# ls / var/run / / found that httpd.pid appears

4.3 modify the PATH environment variable so that the system can directly use apachectl-related commands

# vim / etc/profile.d/httpd24.sh

Export PATH=/usr/local/apache24/bin:$PATH

Edit the configuration file (valid globally and still valid after restarting shell) at this point, the environment variable will not take effect immediately, but it will be valid for the newly logged in user, and then the new user login will be verified

4.4. provide SysV service script / etc/rc.d/init.d/httpd24

# vim / etc/rc.d/init.d/httpd24 / / is as follows

#! / bin/bash

#

# httpd Startup script for the Apache HTTP Server

#

# chkconfig:-85 15

# description: Apache is a World Wide Web server. It is used to serve\

# HTML files and CGI.

# processname: httpd

# config: / etc/httpd24/httpd.conf

# config: / etc/sysconfig/httpd24

# pidfile: / var/run/httpd.pid

# Source function library.

. / etc/rc.d/init.d/functions

If [- f / etc/sysconfig/httpd24]; then

. / etc/sysconfig/httpd24

Fi

# Start httpd in the C locale by default.

HTTPD_LANG=$ {HTTPD_LANG- "C"}

# This will prevent initlog from swallowing up a pass-phrase prompt if

# mod_ssl needs a pass-phrase from the user.

INITLOG_ARGS= ""

# Set HTTPD=/usr/sbin/httpd.worker in/ etc/sysconfig/httpd to use a server

# with the thread-based "worker" MPM; BE WARNED that some modules may not

# work correctly with a thread-based MPM; notably PHP will refuse to start.

# Path to the apachectl script, server binary, and short-form for messages.

Apachectl=/usr/local/apache24/bin/apachectl

Httpd=$ {HTTPD-/usr/local/apache24/bin/httpd}

Prog=httpd

Pidfile=$ {PIDFILE-/var/run/httpd.pid}

Lockfile=$ {LOCKFILE-/var/lock/subsys/httpd}

RETVAL=0

Start () {

Echo-n $"Starting $prog:"

LANG=$HTTPD_LANG daemon-- pidfile=$ {pidfile} $httpd $OPTIONS

RETVAL=$?

Echo

[$RETVAL = 0] & & touch ${lockfile}

Return $RETVAL

}

Stop () {

Echo-n $"Stopping $prog:"

Killproc-p ${pidfile}-d 10$ httpd

RETVAL=$?

Echo

[$RETVAL = 0] & & rm-f ${lockfile} ${pidfile}

}

Reload () {

Echo-n $"Reloading $prog:"

If! LANG=$HTTPD_LANG $httpd $OPTIONS-t > & / dev/null; then

RETVAL=$?

Echo $"not reloading due to configuration syntax error"

Failure $"not reloading $httpd due to configuration syntax error"

Else

Killproc-p ${pidfile} $httpd-HUP

RETVAL=$?

Fi

Echo

}

# See how we were called.

Case "$1" in

Start)

Start

Stop)

Stop

Status)

Status-p ${pidfile} $httpd

RETVAL=$?

Restart)

Stop

Start

Condrestart)

If [- f ${pidfile}]; then

Stop

Start

Fi

Reload)

Reload

Graceful | help | configtest | fullstatus)

$apachectl $@

RETVAL=$?

*)

Echo $"Usage: $prog {start | stop | restart | condrestart | reload | status | fullstatus | graceful | help | configtest}"

Exit 1

Esac

Exit $RETVAL

Then give the script execution permission:

# chmod + x / etc/rc.d/init.d/httpd24

Add to the list of services:

# chkconfig-add httpd24

Power on and start automatically

# chkconfig httpd24 on

Start the service

# service httpd24 start

# ss-tnl

Additional: here httpd compiles and installs to specify the MPM module type as event. If you want to switch the type in MPM, you can edit the main configuration file.

For example: change to prefork model

# vim / etc/httpd24/httpd.conf / / Edit the generated main configuration file

Include / etc/httpd24/extra/httpd-mpm.conf / / remove the comments and enable the extra module

# LoadModule mpm_event_module modules/mod_mpm_event.so / / comment out the current model

Change LoadModule mpm_prefork_module modules/mod_mpm_prefork.so / / to the type of MPM module to be used

After restarting the httpd service, it was found that the MPM module type was switched to the prefork model.

# httpd-M

Second, 192.168.1.104 host computer, general binary format to install mariadb-5.5.46

1. Download pressurized mariadb

Download the mysql version of the platform locally, and download it at https://downloads.mariadb.com/archives/.

# tar xf mariadb-5.5.46-linux-x86_64.tar.gz-C / usr/local

# cd / usr/local/

# ln-sv mariadb-5.5.46-linux-x86_64/ mysql

# cd mysql

2. Create users to run processes in a secure manner

# groupadd-r-g 306 mysql

# useradd-g 306-r-u 306 mysql

# chown-R mysql:mysql / usr/local/mysql/*

3. Prepare the file system for data storage

Create a new logical volume and mount it to a specific directory. It is assumed that the mount directory of its logical volume is / mydata, and then you need to create the / mydata/data directory as the directory where the mysql data is stored.

# mkdir / mydata/data-pv

# chown-R mysql.mysql / mydata/data

# chmod 750 / mydata/data

4. Initialize mysql-5.5.46

# cd / usr/local/mysql

# scripts/mysql_install_db-user=mysql-datadir=/mydata/data

5. Provide the main configuration file for mysql

# cd / usr/local/mysql

# cp support-files/my-large.cnf / etc/my.cnf

# vim / etc/my.cnf

# cat / proc/cpuinfo / / View the number of CPU

And modify the value of thread_concurrency in this file to multiply the number of your CPU by 2. For example, use the following line here:

Thread_concurrency = 2

You also need to add the location of the data file under [mysqld]:

Datadir = / mydata/data

6. Provide sysv service scripts for mysql

# cd / usr/local/mysql

# cp support-files/mysql.server / etc/rc.d/init.d/mysqld

# chmod + x / etc/rc.d/init.d/mysqld

Add to the list of services:

# chkconfig-add mysqld

# chkconfig mysqld on

7. Start the mysql service

# service mysqld start

8. Modify the PATH environment variable so that the system can directly use the relevant commands of mysql

At this point, you must specify the full path to enter the mysql command line interface. If you want to enter the command line directly using mysql, you need to edit the configuration file (globally valid and still valid after restarting shell, invalid for the current shell, you need to log out and log in again)

# vim / etc/profile.d/mysql.sh

Export PATH=/usr/local/mysql/bin:$PATH

In order to install mysql in accordance with the system usage specifications and export its development components to the system for use, you also need to perform the following steps:

9. Output the man manual of mysql to the search path of the man command

Edit / etc/man.config and add the following line:

MANPATH / usr/local/mysql/man

10. Output the header file of mysql to the system header file path / usr/include

# ln-sv / usr/local/mysql/include / usr/include/mysql

11. Output the library file of mysql to the system library to find the path

# echo'/ usr/local/mysql/lib' > / etc/ld.so.conf.d/mysql.conf

12. Reload the system library

# ldconfig

13. Create and authorize wordpress and phpMyAdmin users

MariaDB [(none)] > CREATE DATABASE wpdb; / / create wordpress database

MariaDB [(none)] > GRANT ALL ON wpdb.* TO wpuser@'192.168.1.%' IDENTIFIED BY 'wppass'; / / authorized wordpress user

MariaDB [(none)] > FLUSH PRIVILEGES

MariaDB [(none)] > CREATE DATABASE pma; / / create phpMyAdmin database

Query OK, 1 row affected (0.00 sec)

MariaDB [(none)] > GRANT ALL ON pma.* TO pmauser@'192.168.1.%' IDENTIFIED BY 'pmapass'

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)] > FLUSH PRIVILEGES

Query OK, 0 rows affected (0.00 sec)

Third, 192.168.1.103 host, compile and install php-5.4.40

1. Solve the dependency relationship

After configuring the yum source (system installation source and epel source), execute the following command:

# yum groupinstall "Server Platform Development"Development tools"-y

# yum install bzip2-devel libmcrypt-devel libxml2-devel mhash mhash-devel libmcrypt-devel libmcrypt- y

2. Compile and install php-5.4.40

Download the source package to the local directory and download it to http://mirrors.sohu.com/php/.

# tar xf php-5.4.40.tar.bz2

# cd php-5.4.40

#. / configure-- prefix=/usr/local/php-- with-openssl-- with-mysql=mysqlnd-- with-pdo-mysql=mysqlnd-- enable-mbstring-- with-freetype-dir-- with-jpeg-dir-- with-png-dir-- with-zlib-- with-libxml-dir=/usr-- enable-xml-- enable-sockets-- enable-fpm-- with-mcrypt-- with-config-file-path=/etc-- with-config-file-scan-dir=/etc / php.d-with-bz2-enable-maintainer-zts

To support fpm, you need to remove-- with-apxs2=/usr/local/apache/bin/apxs and add-- enable-fpm, noting that both cannot exist at the same time.

Note: if you are using PHP5.3 or above, you can specify mysqlnd in order to link to the MySQL database, so that you do not need to install MySQL or MySQL development packages on this machine. Mysqlnd is available since php 5.3 and can be bound to it at compile time (without having to rely on specific MySQL client library bindings), but it has been the default since PHP 5.4.

#. / configure-with-mysql=mysqlnd-with-pdo-mysql=mysqlnd-with-mysqli=mysqlnd

# make-j 4 & & make install

3. Provide configuration files for php:

# cp php.ini-production / etc/php.ini

4. Configure php-fpm

Provide a SysV init script for php-fpm and add it to the service list:

# cp sapi/fpm/init.d.php-fpm / etc/rc.d/init.d/php-fpm

# chmod + x / etc/rc.d/init.d/php-fpm

# chkconfig-add php-fpm

# chkconfig php-fpm on

Provide a configuration file for php-fpm:

# cp / usr/local/php/etc/php-fpm.conf.default / usr/local/php/etc/php-fpm.conf

Edit the configuration file for php-fpm:

# vim / usr/local/php/etc/php-fpm.conf

Configure the relevant options for fpm to the values you need, and enable the pid file:

Pm.max_children = 50

Pm.start_servers = 5

Pm.min_spare_servers = 2

Pm.max_spare_servers = 8

Pid = run/php-fpm.pid / / enable

Listen = 192.168.1.103 Phantom 9000

Listen.allowed_clients = 192.168.1.102

Then you can start php-fpm and check port 9000.

# service php-fpm start

4. 192.168.1.103 host, install xcache to accelerate php: (the version of xcache that can support php-5.4 must be 2.0 +)

Download address https://xcache.lighttpd.net/pub/Releases

1. Compile and install

# tar xf xcache-3.2.0.tar.bz2

# cd xcache-3.2.0

# / usr/local/php/bin/phpize

#. / configure-enable-xcache-with-php-config=/usr/local/php/bin/php-config

# make & & make install

At the end of the installation, something like the following line appears:

2. Edit php.ini and integrate php and xcache:

First import the sample configuration provided by xcache into php.ini

# mkdir / etc/php.d

# cp / root/xcache-3.2.0/xcache.ini / etc/php.d

Edit configuration file / etc/php.d/xcache.ini

# vim / etc/php.d/xcache.ini

Under [xcache-common], modify it to read as follows:

Extension = / usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so

Note: if there are multiple extension command lines in the php.ini file, make sure that this new line comes first.

Fifth, 192.168.1.102 host, configure httpd-2.4.10

1. Edit the httpd master configuration file, shut down the central host, enable the virtual host configuration file, and enable the relevant modules of httpd.

# vim / etc/httpd24/httpd.conf

# DocumentRoot "/ usr/local/apache24/htdocs" / / comment out this line

Include / etc/httpd24/extra/httpd-vhosts.conf / / find and enable this line

LoadModule log_config_module modules/mod_log_config.so / / confirm that this line is enabled. Mod_log_config will be used in the virtual host configuration file.

Since Apache httpd 2.4there has been a special module for the implementation of FastCGI, this module is mod_proxy_fcgi.so, it is actually an extension of the mod_proxy.so module, so both modules have to be loaded

LoadModule proxy_module modules/mod_proxy.so / / enable

LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so / / enable

Add the following two lines

AddType application/x-httpd-php .php

AddType application/x-httpd-php-source .phps

Navigate to DirectoryIndex index.html

Modified to:

DirectoryIndex index.php index.html

2. Edit the configuration file of the virtual host

1) configure the configuration file of the virtual host to support the use of fcgi

# vim / etc/httpd24/extra/httpd-vhosts.conf

Modify as follows

2) provide default access page and log storage directory for virtual host

# location of logs created by mkdir / var/log/httpd24 / /

# mkdir / apps/vhosts/ {b.netrec. Org}-pv / / httpd hosts and php hosts both need to create access paths

# create a test page on the vim / apps/vhosts/b.net/index.php / / php host

# create a test page on the vim / apps/vhosts/c.org/index.php / / php host

3) restart the service and test the physical host browser

# httpd-t / / habitually do configuration syntax testing

Syntax OK

# service httpd24 restart

Then windows host plus 192.168.1.102 host name resolution

Browsers access www.b.net and www.c.og

VI. 192.168.1.103 host, configure wordpress and phpMyAdmin for virtual host installation

1. Install wordpress / / php host

1) download and configure wordpress

# cd / apps/vhosts/b.net/

# ls / / download wordpress package (download address: https://wordpress.org/download/)

Wordpress-4.3.1-zh_CN.zip

# unzip wordpress-4.3.1-zh_CN.zip

# cd wordpress/

# mv wp-config-sample.php wp-config.php

# vim wp-config.php

# scp-r / apps/vhosts/b.net/wordpress root@192.168.1.102:/apps/vhosts/b.net/ at this point, you need to put the wordpress file of the php host under the page access path of the httpd host

2) httpd host

# httpd-t / / Test syntax

Syntax OK

# service httpd24 restart

3) windows browser visits www.b.net/wordpress and fill in the relevant content according to the information previously authorized.

2. Install phpMyAdmin

1) download and decompress phpMyAdmin

# cd / apps/vhosts/c.org

# ls

PhpMyAdmin-4.4.14.1-all-languages.zip / / download phpMyAdmin package (https://www.phpmyadmin.net/downloads/)

# unzip phpMyAdmin-4.4.14.1-all-languages.zip

# mv phpMyAdmin-4.4.14.1-all-languages pma

# cd pma

# mv config.sample.inc.php config.inc.php

2) configure phpMyAdmin

# openssl rand-base64 18 / / generate a random number

FUDTA121uzwkoWMr4m4DGKQv

# vim config.inc.php / / Edit configuration file

# scp-r / apps/vhosts/c.org/pma root@192.168.1.102:/apps/vhosts/c.org / / at this point, you need to put the pma file of the php host under the page access path of the httpd host

3) httpd host

# httpd-t / / Test syntax

Syntax OK

# service httpd24 restart

4) windows browser visits www.c.org/pma and fill in the relevant content according to the information previously authorized.

At this point, the seemingly vast lamp compilation project is over, if there is anything wrong or even missing, I hope Daniel will criticize and point out. Previously thought that a host installation of lamp is relatively simple, now understand, mainly to find out the relationship between them, several host installations are the same. Personal summary: when configuring the system, you need to be clear about the relationship between various programs, when you encounter difficulties, you need to combine the corresponding log files to see where there is something wrong, and when you configure the files, you need to make the necessary backups. after the configuration is completed, you can test the grammar test, don't blindly ask Baidu and ask others, use your own brains.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report