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

Compile and install LAMP based on CentOS6.7

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

I. download the required software

The test machine environment is:

Httpd2.4 download: http://mirrors.cnnic.cn/apache//httpd/httpd-2.4.25.tar.bz2

Apr download: http://mirrors.hust.edu.cn/apache//apr/apr-1.5.2.tar.bz2

Apr-util download:

Http://mirrors.hust.edu.cn/apache//apr/apr-util-1.5.4.tar.bz2

Mariadb 10.1.21 download: https://downloads.mariadb.org/ official website download currently do not know what reason can not download, need to go through special channels (you know) to get the latest software.

Php5.6.30 download: http://php.net/get/php-5.6.30.tar.bz2/from/a/mirror

At present, the latest version has reached 7.1.2 or conservatively chose the 5.6 version. Compiling php depends on other packages, so install it through yum in advance

Yum install libxml2-devel bzip2-devellibmcrypt-y

Download Xcache php acceleration tool: http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz

The packages you need to rely on to compile xcache are M4 and autoconf.

Yum install M4 autoconf-y

Phpmyadmin download:

Https://files.phpmyadmin.net/phpMyAdmin/4.6.6/phpMyAdmin-4.6.6-all-languages.zip

II. Httpd installation

The lower version of apr installed in centos6.7 requires a newer version of httpd2.4 to compile, while upgrading the existing version of the system apr package directly through yum may result in other software that depends on this package, because the upgrade of apr makes it impossible to start, so just to be on the safe side, compile the new version manually.

1. Apr installation

~] # tar-jxf apr-1.5.2.tar.bz2-C / usr/local/src~] # tar-jxf apr-util-1.5.4.tar.bz2-C / usr/local/src~] # cd / usr/local/src/apr-1.5.2~] #. / confirure-prefix=/usr/local/apr~] # make & & make install # apr installation completed ~] # cd / usr/local/src/apr-util-1.5.4~] # . / configure-prefix=/usr/local/apr-util-with-apr=/usr/local/apr # with-apr parameter specifies the package on which apr-util is compiled If not specified, the default installation path of the system will be found at compile time. ~] # make & & make install

Many people will wonder what apr does, and why this package is used every time it is compiled.

The purpose of APR (Apache portable Run-time libraries,Apache Portable Runtime Library), like its name, is to provide an underlying supporting interface library for upper-level applications that can be used across multi-operating system platforms.

The biggest function of APR is socket scheduling.

2. Httpd installation

Extract the downloaded httpd-2.4.25 to the / usr/local/src directory

~] # tar-jxf httpd-2.4.25.tar.bz2-C / usr/local/src~] # cd / usr/local/src/httpd-2.4.25~] #. / configure-prefix=/usr/local/apache-sysconfdir=/etc/apache-enable-so-enable-ssl-enable-cgi-enable-rewrite-with-zlib-with-pcre-with-apr=/usr/local/apr-with-apr-util=/usr/local/apr-util-enable-modules=most-enable-mpms-shared=all -with-mpm=prefork~] # make-j 4 & & make install# is configured before startup after installation is completed Add startup user and group ~] # groupadd-r-g 80 apache~] # useradd-r-g apache-u 80 apache# to provide service script for apache ~] # vim / EtcUnip rc.dhand init. D Apache is a World Wide Web server apachehammer scratch Startup script for theApache 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/httpd/conf/httpd.conf# config:/etc/sysconfig/httpd#pidfile: / var/run/httpd.pid # Sourcefunction library../etc/rc.d/init.d/functions if [- f/etc/sysconfig/httpd]; then. / etc/sysconfig/httpdfi # Starthttpd in the C locale by default.HTTPD_LANG=$ {HTTPD_LANG- "C"} # Thiswill prevent initlog from swallowing up a pass-phrase prompt if# mod_sslneeds a pass-phrase from the user.INITLOG_ARGS= "# SetHTTPD=/usr/sbin/httpd.worker in/ etc/sysconfig/httpd to use a server# withthe thread-based" worker "MPM; BE WARNED that some modules may not# workcorrectly with a thread-based MPM; notably PHP will refuse to start. # Path tothe apachectl script, server binary, and short-form for messages.apachectl=/usr/local/apache/bin/apachectlhttpd=$ {HTTPD-/usr/local/apache/bin/httpd} prog=httpdpidfile=$ {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 toconfiguration syntax error" failure $"not reloading $httpd dueto configuration syntax error" else killproc-p ${pidfile} $httpd-HUP RETVAL=$? Fi echo} # See howwe 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 1esac exit $RETVAL~] # chmod + x / etc/rc.d/init.d/apache~] # chkconfig-add apache~] # service apache start # Test whether the startup is successful

By default, the system firewall forbids communication on port 80. When compiling and installing on the Internet, the firewall will be turned off for convenience. I think it is not possible to close the firewall in the production environment, and it is estimated that no one has done so. Port 80 will be used now, as well as ports 3306 and 9000 used by mariadb and php.

~] # iptables-I INPUT-p ctp-m multiport-dports80,8080,3306,9000-m state-state NEW,ESTABLISHED-j ACCEPT# Note: firewall policies are generally audited from top to bottom, so this policy is added directly to the top to avoid conflicts with other policies. ~] # setenforce 0 # sets selinux to Permissive mode. Later, the htdocs directory may be directed to another path. If it is not set to Permissive, it will be inaccessible.

Finally, fill in the IP address of the test machine in the browser, and the following display will be displayed if the configuration is successful.

III. Mariadb installation

First set the mysql user mysql group.

~] # groupadd-r-g 36 mysql~] # useradd-r-g mysql-u 36 mysql

The package used here is in binary format, which can be unzipped to a specific path and then simply configured for use.

In the production environment, the database files will be stored separately in a larger space. In this test machine, there are two hard drives simulated, and each of the two hard drives is divided into 50G space to form a logical volume to store the data files. Here are the specific operations.

~] # yum install lvm2 # this step can be skipped if the lvm management tool is installed in the system ~] # pvcreate / dev/sd {aforme b} 3 # add the partition in the hard disk areb to the physical volume ~] # vgcreate-s 16m datavg / dev/sd {a B} 3 # add two physical volumes to the datavg physical volume group ~] # lvcreate-L 50g-n marialv datavg # divide the physical volume group into 50g space to create marialv logical volumes ~] # mkfs-t ext4-M1-L "mariadata"-b 2048/dev/datavg/marialv # format marialv logical volumes ~] # mount / dev/datavg/marialv / data/~] # mkdir / data/mariadb-p # create data storage path ~] # chown mysq:mysql / data/mariadb # change the group owner of the mariadb directory to prepare the mysql# to this data storage location If you need to boot and mount this directory, you need to modify the / etc/fstab file ~] # tar-zxf mariadb-10.1.21-linux-x86_64.tar.gz-CAccord cd local ~] # cd / usr/local~] # ln-s mariadb-10.1.21 mysql # default installation configuration is in the mysql directory, so you need to make a link to the unzipped database to facilitate future database upgrade and update the link directly. ~] # cd mysql~] # chown-R root:mysql. / * # modify all files in the package to belong to the root user mysql group ~] # scripts/mysql_install_db-- datadir=/data/mariadb-user=mysql # this step should be noted that mysql_install_db can only be performed in the scripts directory. After execution, o (╯□╰) o is installed without accident.

Don't rush to run it, there will be a little adjustment later, because mariadb doesn't have a configuration file or startup script! Next, let's do these two well.

Still operate in the mysql directory, which needs to be noted.

Mysql] # cp support-files/mysql.server / etc/rc.d/init.d/mysqld # add startup script mysql] # chkconfig-add mysqldmysql] # mkdir / etc/mariadbmysql] # cp support-files/my-larg.cnf / etc/mariadb/my.cnf# provides three configuration files for different hardware in the support-files directory, which can be selected according to the hardware of your system. Here you select my-larg.cnf# to edit my.cnf and add the following three options: mysql] # vim / etc/mariadb/my.cnf [client] # password = your_passwordport = 3306#socket = / tmp/mysql.socksocket = / data/mariadb / mysql.sock# Herefollows entries for some specific programs# TheMariaDB server [mysqld] port = 3306socket = / data/mariadb / mysql.sock#... Omit other unchanged options thread_concurrency= 8 # this parameter can be changed according to your own server hardware configuration Generally multiply the number of CPU by 2datadir=/data/mariadb # database storage path innodb_file_per_table= on # each data table storage type is independent skip_name_resolve = on # skip database reverse resolution hostname mysql] # bin/mysql_secure_installation # you can set the password for root Some operations such as deleting anonymous users can be configured to run the service mysqld start startup service ~] # ss-nat | grep 3306 # you can see that the port has been started.

IV. PHP installation

PHP can be compiled and installed in different ways according to the way httpd is compiled. The previous httpd mpm was compiled in event mode, and the php here is also compiled in modules mode.

Resolve dependencies before installation, and install bzip2-devel, libmcrypt-devel, and libxml2-devel development packages.

~] # yum install bzip-devel libmcrypt-devel libxml2-devel-y~] # tar-Jxf php-5.6.30.tar.xz-C / usr/local/src # decompress to the src directory ~] # cd / usr/local/src/php-5.6.30~] #. / 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/apache/bin/apxs-with-mcrypt-with-config-file-path=/etc/php-with-config-file-scan-dir=/etc/php/php.d-with-bz2-enable-maintainer-zts # these parameters are too brain-burning Recite o (╯□╰) o for two days.

The following is a description of the role of these parameters.

Prefix: specify the installation path

With-mysql: indicates that the mysql location is dependent

With-openssl: when you rely on the openssl module, you don't need to specify the default installation location of the system. You can find it yourself.

With-mysqli: another interface for Mysql database interaction.

Enable-mbstring: enable support for multi-byte characters, which must be enabled for Chinese.

With-freetype-dir: indicates the font format so that the php page supports more font display.

With-jpeg-dir: you can use php to work with pictures in jpeg format.

With-png-dir: you can use php to work with pictures in png format.

With-zlib: start the zlib compression transfer function.

With-libxml-dir: supports processing of documents in XML format.

Enable-xml: enable the xml feature.

Enable-sockets: enable php to support communication based on socket.

With-apxs2: specifies the httpd third-party module compilation tool.

With-mcrypt: supports encryption and decryption of libraries.

With-config-file-scan-dir: specify the path where all PHP configuration files are stored.

With-bz2: supports bz2 encryption.

Enable-maintainer-zts: this can be omitted if httpd is compiled using prefork mode, and this parameter must be added if you are compiling with event or worker mode.

Php] # make-j 4percent & after the make install# compilation is complete, you can use httpd-M to see that the php5 module has been added to the httpd. Php] # cp php.ini-production/etc/php/php.ini # add configuration file for php ~] # vim/etc/apache/httpd.conf # modify httpd configuration file to support files in php format # find AddType and add two configuration messages below: AddTypeapplication/x-httpd-php .phpAddTypeapplication / x-httpd-php-source .phps # find DirectoryIndex add index.php~ before index.html] # serviceapache reload # httpd reread configuration File ~] # mv/usr/local/apache/htdocs/index.html / usr/local/apache/htdocs/index.php

Type the IP address of the test machine in the browser, and this test page normally appears to prove that the installation is successful!

Fifth, install Xcache to speed up PHP

~] # tar-zxf xcache-3.2.0.tar.gz-C / usr/local/src/~] # cd / usr/local/src/xcache-3.2.0/xcache-3.2.0] # / usr/local/php/bin/phpize # generate the configure compilation script xcache-3.2.0 using php's phpize tool] #. / configure-enable-xcache-with-php-config=/usr/local/php/bin/php -configxcache-3.2.0] # make & & make install# Note: there will be the following message at the end of the installation: # Installing sharedxtensions:/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226# copy the path

Next, integrate php into xcache.

Xcache-3.2.0] # cp xcache.ini / etc/php/php.d/xcache-3.2.0] # vim / etc/php/php.d/xcache.ini# find the line at the beginning of zend_extension and modify it as follows: zend_extension = / usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/xcache.so

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

So far, installing php in modules mode is complete! You think everything's all right? You are still too young, so let's try fcgi mode to recompile and install phpads! Do you think I have nothing to do for half a month, huh? )

VI. Start

Take a break! So capricious! We have to open a new section. Hey, hey!

7. Compile and install PHP in fpm mode

Http can be recompiled in the same way as before to avoid conflicts, but it is important to note that if you want to change the previous installation path or something, it is best to make clean it.

The following is to recompile php:

Php] #. / configure-prefix=/usr/local/php5.6-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-enable-fpm-with-mcrypt-with-config-file-path=/etc/php5.6-with-config-file-scan- Dir=/etc/php5.6/php.d-with-bz2

You can see that fpm mode compilation does not require two parameters, apxs and maintainer

Php] # make-j 4 & & make installphp] # cp php.ini-production / etc/php5.6/php.ini

The php installed in this way provides services as independent services, so you need to provide startup scripts and configuration files for it.

The configuration file already exists in the sapi/fpm directory of the compiled package, so you can copy it directly to the / etc/rc.d/init.d directory

Php] # cp sapi/fpm/init.d.php-fpm / etc/rc.d/init.d/php-fpmphp] # chmod + x / etc/rc.d/init.d/php-fpm # set execution permissions for scripts php] # chkconfig-add php-fpmphp] # cp / usr/local/php5.6/etc/php-fpm.conf.default/usr/local/php5.6/etc/php-fpm.conf# add configuration files for startup scripts And add and modify the configuration information php5.6] # vim / usr/local/php5.6/etc/php-fpm.confpm.max_children= 50pm.startroomservers= 5pm.minglspareroomservers= 2pm.maxroomspareroomservers8 [global] Pid file; Note: thedefault prefix is / usr/local/php/var; Default Value:none;pid = run/php-fpm.pidpid = / usr/local/php5.6/var/run/php-fpm.pidphp configuration complete startup try ~] # service php-fpm start # if the startup is successful

The following configuration options for httpd are configured to support php format files

~] # vim / etc/apache/httpd.conf# finds mod_proxy and mod_proxy_fcgi modules to remove comments, starts this function, saves and exits LoadModule proxy_modulemodules/mod_proxy.soLoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so AddTypeapplication/x-httpd-php .phpAddType application/x-httpd-php-source .phpsDirectoryIndex index.php index.html#, and reloads httpd configuration ~] # service apache reload

Oh, by the way, there is another particularly important thing: when the Php compiled in fpm mode provides services to httpd, the httpd is equivalent to the front end of the server. When a dynamic request for php is received, the request is sent to the back-end Php server for processing through reverse proxy configuration. The following is to enable the virtual machine configuration in httpd and configure the virtual machine to reverse proxy.

1. The operation of configuring the virtual host in httpd2.4 is different from 2.2, in which the virtual host is set as a separate module to load, which needs to be enabled and disabled for the DocumentRoot central host, and the configuration is posted below:

~] # vim / etc/apache/httpd.conf#DocumentRoot "/ usr/local/apache/htdocs" # Note # Virtual hostsInclude / etc/apache/extra/httpd-vhosts.conf # enable this item # Save exit

two。 Edit / etc/apache/extra/httpd-vhosts.conf virtual host configuration file, where all httpd2.4 virtual hosts are configured

DocumentRoot "/ usr/local/apache/htdocs/" ServerName www.testphp.comErrorLog "logs/testphp.com-error_log" CustomLog "logs/testphp.com-access_log" combined Options None AllowOverride None Require allgranted ProxyRequests Off # close the forward agent ProxyPassMatch ^ / (. *\ .php) $fcgi://127.0.0.1:9000/usr/local/apache/htdocs/$1

Reload the httpd configuration after saving and exiting

So far, all the configurations have been completed, and the ordeal of more than half a month has finally been sorted out. Let's take a look at adding https to the middle to further expand its functions. Stop here first!

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