Centos 7 Compile and install LAMP environment

Source: Internet
Author: User



Objective



LAMP refers to a set of free software names that are typically used together to run dynamic Web sites or servers.



L:linux Operating System



A:apache (httpd) Web Services



M:mysql (MARIADB) database service



P:php/perl/python/ruby Script programming language






This article is mainly in the CentOS 7 environment installation, CentOS 6 with part of the description









First, the installation of http2.4



Centos 7 Default installation httpd 2.4,centos 6 default installation httpd2.2



Centos 7: If http2.4 is not installed, install via Yum


Yum-y Install httpd


Centos 6: Can only be installed by compiling



You must install development tools and server Platform development two pack groups in advance, as well as install Prce-devel packages, Prce packages can be installed via Yum


yum -y groupinstall "Development tools"
yum -y groupinstall "Server Platform Development"
yum -y prce-devel


httpd2.4 requires 1.4 or more versions of APR and Apr-util, so get both the source bundle first






Apr compilation and Installation


Tar xf apr-1.4.6.tar.bz2 -C /usr/local //tar the source package to /usr/local directory
Cd /usr/local/apr-1.4.6
./configure --prefix=/usr/local/apr //Configure the source and specify the installation directory
Make && make install // compile and install the source code


Apr-util Compilation and Installation


tar xf apr-util-1.4.1.tar.bz2 -C /usr/local
cd /usr/local/apr-util-1.4.1/
./configure --prefix=/usr/local/apr-util
make && make install


HTTPD Compilation and Installation


Tar xf httpd-2.4.10.tar.bz2 -C /usr/local

Cd /usr/local/httpd-2.4.10

./configure --prefix=/usr/local/apache //Specify the installation directory
--sysconfdir=/etc/httpd24 //Specify the configuration file directory
--enable-so //Enable module function
--enable-ssl //Enable ssl encryption
--enable-cgi //Enable cgi function
--enable-rewrite //can be overloaded
--with-zlib //Use zlib data
--with-pcre /use pcre data
--with-apr=/usr/local/apr //The associated program apr and directory
--with-apr-util=/usr/local/apr-util //The associated program apr-util and directory
--enable-modules=most //Maximize all modules
--enable-mpms-shared=all //Separately list all MPM modules
--with-mpm=perfork //Use perfork mode

Make && make install 


The./configure parameters can be used./configure--help View



The above is to list the meaning of each parameter, so in the layout of the division, in the configuration of the relevant parameters are separated by a space















Second, the installation of MARIADB



The default use of MySQL in CentOS 6 is mariadb, which is used by default in CentOS 7






Installation of MARIADB


Yum-y Install mariadb-server.x86_64systemctl start mariadb//Start MARIADB Service


installation of MySQL


Yum-y Install Mysql-serverservice mysqld start


MARIADB configuration file:/etc/my.cnf,/etc/my.cnf.d/*.cnf



Modify the/etc/my.cnf file



Add the following values


Innodb_file_per_table = ON//Generate database list skip_name_resolve = ON//No reverse solution


Once the installation is complete, run the mysql_secure_installation once and configure the MARIADB.


[[Email protected] ~]#  mysql_secure_installationnote: running all parts  OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQLSERVERS IN  production use! please read each step carefully! In order to log into mysql to secure it, we ' ll need the  currentpassword for the root user. if you ' ve just installed  mysql, andyou haven ' t set the root password yet, the  Password will be blank,so you should just press enter here. enter current password for root  (Enter for none):               //First run direct carriage return ok, successfully used  Password, moving on ... Setting the root password&nBsp;ensures that nobody can log into the mysqlroot user without  the proper authorisation. set root password? [y/n]                         //whether to set the root user password, enter Y and return to new  password:                                     //set the root user's password re-enter new password:                           // Re-enter password password updated successfully! Reloading privilege tables. ...  success! By default, a mysql installation has an anonymous user, allowing  anYoneto log into mysql without having to have a user account  created forthem. this is intended only for testing, and to  make the installationgo a bit smoother. You should remove  Them before moving into aproduction environment. Remove anonymous users? [y/n]                     //Delete anonymous user, delete ...  success! normally, root should only be allowed to connect from  ' localhost ' .  thisensures that someone cannot guess at the root password  from the network. disallow root login remotely? [y/n]              //prohibit root telnet, prohibit ...  success! By default, mysql comes with a database named  ' Test '  that  Anyone canaccess. this is also intended only for testing, and  should be removedbefore moving into a production environment. remove test database and access to it? [y/n]     / /delete Test database, delete- dropping test database...... success!- removing privileges on  test database...... success! Reloading the privilege tables will ensure that all changes made  so farwill take effect immediately. reload privilege tables now? [y/n]               //whether to reload the permissions table, reload ...  success! Cleaning up ... All done! if you ' Ve completed all of&nbsP;the above steps, your mysqlinstallation should now be secure. thanks for using mysql!


Go to MySQL to configure



Related formats:



Mysql>grant all on db_name.tbl_name to [email protected] ' host ' identified by ' password '


GRANT all on testdb.* to ' root ' @ ' 172.16.%.% ' identified by "Chunlanyy";


Set up users and passwords


FLUSH privileges;            Clear permissions Create DATABASE Testab; Create an Testab data form





Third, the installation of PHP


Yum-y Install PHP


Compile and install:






Four, lamp environment test:



Because HTTPD is implemented as an HTTP protocol server, it can only respond and handle client requests statically, and in order to enable the server to respond dynamically to requests from clients, there are three ways to achieve this:



1) using the CGI protocol: the HTTPD server forwards the request through the CGI protocol to the interpreter of the program, the interpreter returns the running result to the HTTPD server, and then the interpreter destroys



2) using module, compile php into httpd extension module, through httpd dynamic call module to achieve



3) FastCGI: With FPM (FastCGI process Manager), let PHP run a single Apache-type model service, listen to a socket, and generate multiple child processes to handle the response, while the main process is only responsible for managing requests and controlling the health of the child processes. At this point, HTTP becomes a fastcgi client, and FastCGI becomes a simplified version of the HTTP protocol that enables PHP and HTTP to be used for communication.






PHP and HTTP used in a common way by compiling httpd PHP processing module, let httpd own PHP program, or use a dedicated PHP application Server PHP-FPM, it is responsible for processing PHP programs.












a.php Test combined with httpd



Modifying a data file for a previously configured virtual host



Change/data/virhost/www1/index.html to/data/virhost/www1/index.php



vim/data/virhost/www1/index.php



Change the content to the following PHP test code


<php? Phpinfo ();? >


Restart HTTPD Service



Systemctl Restart httpd



Access 172.16.45.21 from the browser to see the Phpinfo page



Where the virtual host configuration file/etc/httpd/conf.d/virhost1.conf content is as follows:


<virtualhost *:80>servername www1.chunlanyy.comdocumentroot "/DATA/VIRHOST/WWW1" <directory "/data/virhost /WWW1 ">options noneallowoverride nonerequire all granted</directory></virtualhost>
[[email protected] modules]# ifconfigeno16777736:flags=4163<up,broadcast,running,multicast> MTU inet 1 72.16.45.21 netmask 255.255.0.0 Broadcast 172.16.255.255





b.php connection to MySQL test



In the case where the MARIADB has been configured in the previous article



Modify the above file vim/data/virhost/www1/index.php content as follows:


<?php $conn = mysql_connect (' 172.16.45.21 ', ' root ', ' Chunlanyy ');                if ($conn) echo "OK"; else echo "Failure";? >


When you start the PHP service, when you access 172.16.45.21 through the browser, an OK indicates that the connection is normal



Systemctl Stop PHP display failure



Centos 7 Compile and install LAMP environment


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.