In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Content:
Part 1: compile and install LAMP (php works as a module)
Part 2: compile and install LAMP (php works as fpm)
Part one:
In the previous introduction, we know
There are probably several ways to combine apache and php:
The first is to compile php directly into the module of apache and work in a modular way of module.
Second: CGI, Universal Gateway Interface, apache communicate with hph based on CGI
The third way: fastcgi, it is also a kind of protocol, under this module, the two of them are combined like this:
Originally, php is run as a module or both php parsers, not listening to receive requests from others on a socket, but for others to call for use as a process, which may be running as someone else's child process, but hph working under a module like fastcgi enables itself as a service process.
He listens on a socket and can accept requests from the client at any time. He also has a main process. In order to respond to requests from multiple users, he will enable multiple sub-processes, which we can also call worker processes.
He also has a free process, as soon as a customer requests him to immediately use the idle process to respond to the client's request and return the result to the front-end caller, he does not have this ability before the php5.3.3 version, so he can only work in the module and CGI mode, and after 5.3.3 this module is directly incorporated into the php module, this kind of module is called php-fpm.
So in the future, when compiling php, if you want to combine with apache, you have to compile it into php-fpm, which is based on the working mode of fastcgi, and start the service process, which means that he communicates with the front-end caller through sockets. Now that the communication is based on sockets, the front-end web server and the back-end php server can work on different hosts, realizing the so-called layering mechanism.
Apache will not deal with the database, he is a static web server, dealing with the database is the application, as the source driver of the application can establish a session between an API and the server, and then he will send it to the database through our mysql statement, and the database will return the results to the application, not the php process, but the code executed in the php process.
Compile and install LAMP
1. Prepare a clean operating system and prepare the compilation environment
2. Preparation of relevant compiled source packages
3. Select the version to be compiled and installed (centos6.8+httpd2.4.10+mariadb5.5.46+php5.6.4)
4. Compile, install and test LAMP
1. Prepare the environment for compilation and installation:
# yum groupinstall "Development Tools"Server Platform Development"-y
2. Prepare the relevant source packages:
Download address:
Related to apache compilation
Apr= "http://mirrors.aliyun.com/apache/apr/apr-1.5.2.tar.bz2"
Aprutil= "http://mirrors.aliyun.com/apache/apr/apr-util-1.5.4.tar.bz2"
HTTPD= "http://mirrors.aliyun.com/apache/httpd/httpd-2.4.23.tar.gz"
Related to PHP compilation:
PHP= "http://mirrors.sohu.com/php/php-5.4.28.tar.gz"
LibmytRPM= "http://mirrors.aliyun.com/epel/6/x86_64/libmcrypt-2.5.8-9.el6.x86_64.rpm"
LibdelRPM= "http://mirrors.aliyun.com/epel/6/x86_64/libmcrypt-devel-2.5.8-9.el6.x86_64.rpm"
Related to mariadb compilation:
MYSQL= "http://cdn.mysql.com//archives/mysql-5.5/mysql-5.5.41-linux2.6-x86_64.tar.gz"
The compilation and installation order of the operation here: apache--mariadb--PHP
First, compile and install apache
1. Solve the dependency relationship
Httpd-2.4.10 requires newer versions of apr and apr-util, so it needs to be upgraded in advance. Apr can be understood as the middle converter, so apache can run on multiple platforms such as windows, linux, MAC and so on. There are two ways to upgrade, one is to compile and install through the source code, the other is to upgrade the rpm package directly.
(1) compile and install apr
# tar xf apr-1.5.2.tar.bz2# cd apr-1.5.2#. / configure-- prefix=/usr/local/apr# make & & make install
(2) compile and install apr-util
# tar xf apr-util-1.5.4.tar.bz2# cd apr-util-1.5.4#. / configure-- prefix=/usr/local/apr-util-- with-apr=/usr/local/apr# make & & make install
(3) the httpd-2.4.10 compilation process also depends on the pcre-devel software package, which needs to be installed in advance. This software package comes with the system CD, so just find it and install it.
# yum install pcre-devel-y
2. Compile and install httpd-2.4.10
# tar xf httpd-2.4.10.tar.bz2# cd httpd-2.4.10#. / configure-- prefix=/usr/local/apache2-- sysconfdir=/etc/httpd-- enable-so-- enable-ssl-- enable-rewrite-- enable-modules=most-- enable-mpms-shared=all-- with-mpm=prefork-- with-pcre-- with-zlib-- with-apr=/usr/local/apr-- with-apr-util=/usr/local/apr-util/# make & & make install
3. Start httpd:
[root@localhost php-5.6.4] # echo "export PATH=/usr/local/apache2/bin:$PATH" > / etc/profile.d/httpd.sh [root@localhost php-5.6.4] # source / etc/profile.d/httpd.sh
Second, install mariadb-5.5.46
1. There are three ways to install mysql:
Rpm package installation
Binary universal package installation
Compilation and installation of source code
Here is a demonstration of binary general package installation, note: there is a difference between binary general package and source package naming, do not be confused, binary package generally with the word linux, such as mariadb-5.5.46-linux-x86_64.tar.gz is binary package, and mariadb-5.5.46.tar.gz is the source package!
Here is a demonstration of storing database files in a directory
Here, it is assumed that the mount directory is / mydata, and then you need to create the / mydata/data directory as the directory for storing mysql data.
2. Create a user to run the process in a secure way:
# groupadd-r mysql# useradd-g mysql-r-s / sbin/nologin# mkdir-pv / mydata/data# chown-R mysql:mysql / mydata/data
3. Install and initialize mysql-5.5.46
# 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# chown-R mysql:mysql. # scripts/mysql_install_db-- user=mysql-- datadir=/mydata/data
4. Provide the main configuration file for mysql:
# cd / usr/local/mysql# cp support-files/my-large.cnf / etc/my.cnf
Modify the configuration:
Thread_concurrency = 2 # and modify the value of thread_concurrency in this file to the number of your CPU multiplied by 2datadir = / mydata/data # need to add the location of the mysql data file as specified in the following line
5. 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
You can then start the service test to use.
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:
6. 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
7. Output the header file of mysql to the path of system header file / usr/include:
This can be done by simply creating a link:
# ln-sv / usr/local/mysql/include / usr/include/mysql
8. 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
Then have the system reload the system library:
# ldconfig
9. Modify the PATH environment variable so that the system can directly use the relevant commands of mysql.
# vim / etc/profile.d/mysql.sh export PATH=/usr/local/mysql/bin:$PATHsource / etc/profile.d/mysql.sh
3. Compile and install php-5.6.4
1. Resolve dependencies:
If you want the compiled php to support mcrypt extensions, you need to install two rpm packages:
# rpm-ivh libmcrypt-2.5.8-9.el6.x86_64.rpm# rpm-ivh libmcrypt-devel-2.5.8-9.el6.x86_64.rpm
2. Compile and install php-5.6.4
# yum install-y libxml2-devel# tar xf php-5.6.4.tar.xz# cd php-5.6.4#./configure-- prefix=/usr/local/php-- with-mysql=/usr/local/mysql-- with-openssl-- with-mysqli=/usr/local/mysql/bin/mysql_config-- enable-mbstring-- with-freetype-dir-- with-jpeg-dir-- with-png-dir-- with-zlib-- with-libxml-dir=/usr-- enable -xml-enable-sockets-with-apxs2=/usr/local/apache2/bin/apxs-with-mcrypt-with-config-file-path=/etc-with-config-file-scan-dir=/etc/php.d-enable-maintainer-zts# make# make intall
Note: if httpd uses the threading model MPM, an additional-- enable-maintainer-zts option is required
Note: if you want to run php as fpm, you need to remove the-- with-apxs option at compile time and add the-- enable-fpm option
Provide the configuration file for php (located in the unzipped source package directory):
# cp php.ini-production / etc/php.ini
3. Edit the apache configuration file httpd.conf to support php with apache
# vim / etc/httpd/httpd.conf
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
Then restart httpd or have it reload the configuration file to test whether php is working properly.
4. Install phpMyAdmin here for test and verification:
1. Decompress phpMyAdmin-4.4.14.1-all-languages.zip
2. Move phpMyAdmin-4.4.14.1-all-languages to the root directory of the web site and name it pma directory: / usr/local/apache2/htdocs/pma
3. Enter the pma directory and enable the default to the configuration file
Cp libraries/config.default.php config.inc.php
4. Edit the configuration file and set the corresponding database account and password
5. Test the web site that opens the directory, and as long as you can log on to the database, it shows that A+M+P has worked successfully.
The test is normal, and at this point, LAMP has been compiled and works.
The second part, compile and install LAMP (php works as fpm)
First, compile and install LAMP
1. Compile and install:
As in the previous steps, except that when compiling and installing PHP, remove the-- with-apxs option and add the-- enable-fpm option
# / configure-- prefix=/usr/local/php-- with-mysql=/usr/local/mysql-- with-openssl-- with-mysqli=/usr/local/mysql/bin/mysql_config-- enable-mbstring-- with-freetype-dir-- with-jpeg-dir-- with-png-dir-- with-zlib-- with-libxml-dir=/usr-- enable-xml-- enable-sockets-- with-mcrypt-- with-config-file-path=/etc-- with-config -file-scan-dir=/etc/php.d-enable-maintainer-zts-enable-fpm
2. Provide configuration files for php:
# cp php.ini-production / etc/php.ini
3. 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
4. Provide configuration files for php-fpm:
# cp / usr/local/php/etc/php-fpm.conf.default / usr/local/php/etc/php-fpm.conf
5. Edit the configuration file of 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 (the last line below):
Pid = / usr/local/php/var/run/php-fpm.pid
6. Then you can start php-fpm:
# service php-fpm start
Use the following command to verify (if there are several php-fpm processes in the output of this command, the startup is successful):
[root@localhost fpm] # ss-tanlState Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 50 *: 3306 *: * LISTEN 0 32 *: 21 *: * LISTEN 0 128: 22:: * LISTEN 0 128 *: 22 *: * LISTEN 0 100:: 1:25:: * LISTEN 0 100 127.0.0.1 root@localhost fpm 25 *: * [root@localhost fpm] # service php-fpm startStarting php-fpm done [root@localhost fpm] # ss-tanlState Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 127.0.1 9000 *: * LISTEN 0 50 *: 3306 *: * LISTEN 0 32 *: 21 *: * LISTEN 0 128: 22:: * LISTEN 0 128 *: 22 *: * LISTEN 0 100:: 1:25:: * LISTEN 0 100 127.0.0.1 25 *: * [root@localhost fpm] #
By default, fpm listens on port 9000 at 127.0.0.1, or you can use the following command to verify that it is listening on the corresponding socket.
2. Configure httpd
1. Enable the relevant modules of httpd
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.soLoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
At the same time, annotate the module of libphp5.so
# LoadModule php5_module modules/libphp5.so
2. Configure the central host to support the use of fcgi (you can also configure a virtual host, which is similar, so I won't demonstrate it here)
Add two lines similar to the following in the corresponding virtual host.
ProxyRequests Off # closes the forward agent ProxyPassMatch ^ / (. *\ .php) $fcgi://127.0.0.1:9000/usr/local/apache2/htdocs/$1 # to send requests for files ending in .php to the php-fpm process. Php-fpm needs to know at least the directory and URI that are running, so these two parameters are specified directly after fcgi://127.0.0.1:9000. The other parameters have been encapsulated by mod_proxy_fcgi.so and do not need to be specified manually.
3. Edit the apache configuration file httpd.conf so that apache can recognize the page in php format and support the home page in php format.
# vim / etc/httpd/httpd.conf 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
The test is successful and the php page can be accessed.
3. Test phpMyAdmin:
Here, install phpMyAdmin again for test verification:
1. Decompress phpMyAdmin-4.4.14.1-all-languages.zip
2. Move phpMyAdmin-4.4.14.1-all-languages to the root directory of the web site and name it pma directory: / usr/local/apache2/htdocs/pma
3. Enter the pma directory and enable the default to the configuration file
Cp libraries/config.default.php config.inc.php
4. Edit the configuration file and set the corresponding database account and password
$cfg ['Servers'] [$I] [' user'] = 'nihao';$cfg [' Servers'] [$I] ['password'] =' 123456'
5. Test the web site that opens the directory, and as long as you can log on to the database, it shows that A+M+P has worked successfully.
The test is normal, and at this point, LAMP has been compiled and works.
OK, please follow my blog for more articles.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.