Build Lamp on CentOS 7

Source: Internet
Author: User
Tags php server

Requirements: HTTPD's dynamic and static resources are available in two hosts, and MySQL is also a single host. The HTTPD service provides a virtual host, a virtual host is used to provide phpMyAdmin, and another virtual host is used to provide WordPress. Installation uses XCache to speed up PHP services.

Scenario: 1 hosts as httpd server, 1 hosts do PHP server, use PHP-FPM mode, 1 hosts as MySQL database server.

Preparation: Three hosts, configure Yum source.

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/7F/35/wKiom1cW2CzjWAOTAABM6RKxY-Q689.png "title=" 1.png " alt= "Wkiom1cw2czjwaotaabm6rkxy-q689.png"/>



First step: Configure the HTTPD server

    1. Yum Install httpd Pack

      ~]# Yum Install httpd

      650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/7F/33/wKioL1cW28rhbrVzAAAj5RwrD20320.png "title=" 2.png " alt= "Wkiol1cw28rhbrvzaaaj5rwrd20320.png"/>

Start the service

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/7F/35/wKiom1cW25bCJoaOAACSq9rNlgw574.png "title=" 3.png " alt= "Wkiom1cw25bcjoaoaacsq9rnlgw574.png"/>


To test if a service page is available

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/7F/35/wKiom1cW3BnDyXVsAAIn92zBOGg558.png "title=" 4.png " alt= "Wkiom1cw3bndyxvsaain92zbogg558.png"/> httpd service is working properly


2. Configure the virtual host and define the dynamic page forwarding to the PHP server.

Comment out the main service page path

~]# vim/etc/httpd/conf/httpd.conf

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/7F/33/wKioL1cW36DRP4nJAAAjcecF8Bc927.png "title=" 5.png " alt= "Wkiol1cw36drp4njaaajcecf8bc927.png"/>

Add a configuration file that defines the virtual host and defines the forwarding.

~]# touch/etc/httpd/conf.d/virtualhost.conf

~]# vim/etc/httpd/conf.d/virtualhost.conf

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/7F/36/wKiom1cW413BLRwoAAD81BWCDds485.png "title=" 6.png " alt= "Wkiom1cw413blrwoaad81bwcdds485.png"/>


3. Test the virtual host

~]# touch/var/virtualhost/a/check.html

~]# vim/var/virtualhost/a/check.html

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7F/33/wKioL1cW5Zmyu_i7AAAFH_QaRtQ818.png "title=" 7.png " alt= "Wkiol1cw5zmyu_i7aaafh_qartq818.png"/>

~]# touch/var/virtualhost/b/check.html

~]# vim/var/virtualhost/b/check.html

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/7F/33/wKioL1cW5g7CYWQpAAADNfx7DHs112.png "title=" 8.png " alt= "Wkiol1cw5g7cywqpaaadnfx7dhs112.png"/>

Define IP addresses that resolve www.a.com and www.b.com to the HTTPD server in the host that accesses the test

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/7F/36/wKiom1cW5gDTE8UnAABI0vTy-58265.png "style=" float: none; "title=" 9.png "alt=" Wkiom1cw5gdte8unaabi0vty-58265.png "/>

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/7F/36/wKiom1cW5gCQsWzKAABJIIOlyNI317.png "style=" float: none; "title=" 10.png "alt=" Wkiom1cw5gcqswzkaabjiiolyni317.png "/>

Note: Thehttpd-2.4:rpm package installs a default compilation that supports the FCGI module, and you can use HTTPD-M to view the modules that have already been loaded.

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/7F/37/wKiom1cW8vfwB1UfAAAQIUeF0qQ715.png "title=" 10.5. PNG "alt=" Wkiom1cw8vfwb1ufaaaqiuef0qq715.png "/>


4. Use Systemctl enable Httpd.service to set the service to boot



Step Two: Configure the PHP server

    1. Yum Install PHP-FPM Pack

~]# Yum Install php-fpm

View status

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/7F/33/wKioL1cW6O-SKYx3AAAjugmiLsk299.png "title=" 11.png "alt=" Wkiol1cw6o-skyx3aaajugmilsk299.png "/>


2. Modify the configuration file

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/7F/34/wKioL1cW7LWQTaZ6AABCcH6rdJY983.png "style=" float: none; "title=" 12.png "alt=" Wkiol1cw7lwqtaz6aabcch6rdjy983.png "/>

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/7F/36/wKiom1cW6_XhUPneAABAJMWQx08648.png "style=" float: none; "title=" 13.png "alt=" Wkiom1cw6_xhupneaabajmwqx08648.png "/>

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/7F/34/wKioL1cW7LaxYpSbAAAtIRTMipY660.png "style=" float: none; "title=" 14.png "alt=" Wkiol1cw7laxypsbaaatirtmipy660.png "/>

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/7F/36/wKiom1cW6_agEOdwAAAiSI03jfU927.png "style=" float: none; "title=" 15.png "alt=" Wkiom1cw6_ageodwaaaisi03jfu927.png "/>

~]# mkdir/var/lib/php/session

~]# Chown Apache:apache/var/lib/php/session


3. Start the service to view the status

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/7F/36/wKiom1cW7OHAwxjKAACAw1Mawik017.png "title=" 16.png "alt=" Wkiom1cw7ohawxjkaacaw1mawik017.png "/>


4. Add the test page under the resource path of the PHP server and test

~]# vim/var/phppage/a/check.php

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/7F/37/wKiom1cW76eDRAG-AAAH_ROmp8Y932.png "title=" 17.png "alt=" Wkiom1cw76edrag-aaah_romp8y932.png "/>

~]# vim/var/phppage/b/check.php

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/7F/37/wKiom1cW8H-yhtG5AAAILhlKLrM290.png "title=" 18.png "alt=" Wkiom1cw8h-yhtg5aaailhlklrm290.png "/>

Access

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/7F/37/wKiom1cW8QWxSE9BAAC-0f9lef4807.png "style=" float: none; "title=" 19.png "alt=" Wkiom1cw8qwxse9baac-0f9lef4807.png "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/7F/34/wKioL1cW8cbQ31_eAADNALPAJP4523.png "style=" float: none; "title=" 20.png "alt=" Wkiol1cw8cbq31_eaadnalpajp4523.png "/>



5. Install the Php-mysql package (communication protocol between PHP and MySQL)

~]# Yum Install Php-mysql

And then reload the service

~]# Systemctl Reload Php-fpm.service

6. Use Systemctl enable Php-fpm.service to set the service to boot



Part III: Configuring the MySQL server


    1. Yum Install MARIADB Pack

      ~]# Yum Install Mariadb-server

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7F/37/wKiom1cW96eT7SDZAAAhSeHgWSw503.png "title=" 21.png "alt=" Wkiom1cw96et7sdzaaahsehgwsw503.png "/>


2. Start the service

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/7F/38/wKiom1cXD_7woDxpAAEz57ifTW8552.png "title=" 22.png "alt=" Wkiom1cxd_7wodxpaaez57iftw8552.png "/>


3. Testing

Create a test user and database

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/7F/38/wKiom1cXEA3hJ5jRAAC4yrON0ZQ070.png "title=" 23.png "alt=" Wkiom1cxea3hj5jraac4yron0zq070.png "/>

Add a test page under the path where the page resource is placed on the PHP server

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/7F/36/wKioL1cXFOrhJv9EAAAbbXX6ONo804.png "title=" 28.png "Style=" Float:none; "alt=" Wkiol1cxforhjv9eaaabbxx6ono804.png "/>


650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/7F/39/wKiom1cXFCnCm_uSAAAjH2WKq3Y182.png "style=" float: none; "title=" 24.png "alt=" Wkiom1cxfcncm_usaaajh2wkq3y182.png "/>

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/7F/36/wKioL1cXFOmxvyOaAAAjFNMLqq8327.png "style=" float: none; "title=" 25.png "alt=" Wkiol1cxfomxvyoaaaajfnmlqq8327.png "/>

Access test

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/7F/39/wKiom1cXFCnjOcXvAAB-mkpcJak200.png "style=" float: none; "title=" 26.png "alt=" Wkiom1cxfcnjocxvaab-mkpcjak200.png "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/7F/39/wKiom1cXFCriYk5dAABsfeB_oZw803.png "style=" float: none; "title=" 27.png "alt=" Wkiom1cxfcriyk5daabsfeb_ozw803.png "/>


4. Use Systemctl enable Mariadb.service to set the service to boot


Lamp is set up to provide service normally.


Fourth step: Using www.a.com This virtual host provides phpMyAdmin, with www.b.com this virtual host to provide WordPress


1. Prepare the Phpmyadmin,wordpress source package

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/7F/37/wKioL1cXGTuidPtvAAAW2eL6GL0247.png "title=" 29.png "alt=" Wkiol1cxgtuidptvaaaw2el6gl0247.png "/>


2. Unzip to the path where the page resource is placed

~]# Unzip phpmyadmin-4.4.14.1-all-languages.zip-d/var/phppage/a


3. Edit its configuration file

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/7F/37/wKioL1cXHhLzQ4eCAADf-pHmIIs502.png "title=" 31.png "alt=" Wkiol1cxhhlzq4ecaadf-phmiis502.png "/>

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/7F/37/wKioL1cXHnPQjIB9AABzkLoR3SY493.png "title=" 30.png "alt=" Wkiol1cxhnpqjib9aabzklor3sy493.png "/>


4. Access

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/7F/39/wKiom1cXH0axQjYCAACxnQdLecI006.png "title=" 32.png "alt=" Wkiom1cxh0axqjycaacxnqdleci006.png "/>


It is already accessible, but there are some places in the page that cannot be displayed. This is because this page is composed of dynamic resources and static resources, and the HTTPD server just forward the dynamic resource request to the PHP server, the static resource is provided by HTTPD, it now does not have this resource under the resource path, so this page is not full. Principle visible

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/7F/37/wKioL1cXIZbT0C5hAAB3558nBF8829.jpg "title=" QQ picture 20160420142202.jpg "alt=" Wkiol1cxizbt0c5haab3558nbf8829.jpg "/>

Solution: Place a copy of the phpMyAdmin source file under the resource placement path on the httpd server so that the page can be displayed completely.

Now we want to visit phpMyAdmin this page, we need to give the domain name and also specify the URL. It's too much trouble.

There are two solutions to solve.

First scenario: Modify the configuration of a virtual host, modify the DocumentRoot path, and modify the forwarded path at the same time

Documentroot/var/virtualhost/a/phpmyadmin-4.4.14.1-all-languages

Proxypassmatch ^/(. *\.php) $ fcgi://192.168.0.132:9000/var/phppage/a/phpmyadmin-4.4.14.1-all-languages/$1

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/7F/3A/wKiom1cXKo3Ty0fgAABeulGXmAg373.png "title=" 33.png "alt=" Wkiom1cxko3ty0fgaabeulgxmag373.png "/>

Then use the HTTPD-T to test the configuration file syntax, and then reload the following configuration file.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/7F/3A/wKiom1cXKqCQCMKQAACppld4fgU956.png "title=" 34.png "alt=" Wkiom1cxkqcqcmkqaacppld4fgu956.png "/> A second scenario: Place all phpMyAdmin source files directly under the DocumentRoot path. The PHP server is placed directly under the specified forward path.

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/7F/3A/wKiom1cXK8Hxrpn_AAC3hBNPI3M936.png "title=" 36.png "alt=" Wkiom1cxk8hxrpn_aac3hbnpi3m936.png "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/7F/39/wKiom1cXJYvh1-OEAAC-3DyldSA157.png "title=" 35.png "alt=" Wkiom1cxjyvh1-oeaac-3dyldsa157.png "/>



Decorate WordPress

~]# Unzip wordpress-4.3.1-zh_cn.zip-d/var/phppage/b

]#]# CP wp-config-sample.php wp-config.php

]# Vim wp-config.php

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/7F/38/wKioL1cXLwLAtu_YAABt21MV1AU622.png "title=" 37.png "alt=" Wkiol1cxlwlatu_yaabt21mv1au622.png "/>

Note: This allows WP to log in and use the database users need to be created in advance.

Subsequent processes are similar to configuration phpMyAdmin, and are not duplicated.


Fifth step: Install XCache, improve the speed of processing PHP requests


1. Do a stress test before installing

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/7F/38/wKioL1cXMMHDXjAPAABniOwMB_I064.png "style=" float: none; "title=" 38.png "alt=" Wkiol1cxmmhdxjapaabniowmb_i064.png "/>

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/7F/3A/wKiom1cXMAHTS5BAAAC6fw_wlz0512.png "style=" float: none; "title=" 39.png "alt=" Wkiom1cxmahts5baaac6fw_wlz0512.png "/>


This time we use the compiler to install XCache

Preparation: Download a XCache source package, install development tools and the server Platform Development package group. Install the Php-devel package.


2. Start compiling

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/7F/3B/wKiom1cXNTGixJRTAADwC0s-ElY828.png "title=" 40.png "alt=" Wkiom1cxntgixjrtaadwc0s-ely828.png "/>

If this step is not a problem, do make and then execute make instal.

After the installation is complete, add the configuration file, and then let the service reload.

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/7F/3B/wKiom1cXNX-i1J0ZAAAZIX-Wlyc461.png "title=" 42.png "alt=" Wkiom1cxnx-i1j0zaaazix-wlyc461.png "/>


3. One more stress test

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/7F/3B/wKiom1cXNfrwmcWwAABocFn0Wz4275.png "style=" float: none; "title=" 43.png "alt=" Wkiom1cxnfrwmcwwaabocfn0wz4275.png "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/7F/39/wKioL1cXNrvwZ7MMAACz-q-df1Q772.png "style=" float: none; "title=" 44.png "alt=" Wkiol1cxnrvwz7mmaacz-q-df1q772.png "/>

Compared with two pressure tests, it can be seen that the PHP request processing speed increased by about 3 times times after the XCache was installed.




Build Lamp on CentOS 7

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.