The LAMP (Linux-Apache-MySQL-PHP) website architecture is currently a popular Web framework, including: Linux operating system, Apache network server, MySQL database, perl, PHP, or Python programming language. All components are open-source software and are internationally mature architecture frameworks. Many popular commercial applications adopt this architecture. Compared with the Java/J2EE architecture, LAMP features rich Web resources, lightweight, and fast development. compared with the NET architecture, LAMP has the advantages of common, cross-platform, high performance and low price. Therefore, LAMP is the preferred platform for enterprises to build websites, regardless of its performance, quality, and price.
For the high-traffic and high-concurrency website system architecture, in addition to using high-performance servers, Server Load balancer, and CDN on the hardware, the following aspects should be emphasized in the software architecture: high-performance operating systems (OS), high-performance Web servers, high-performance databases, and high-efficiency programming languages are used.
The package I selected is a httpd-2.2.25.tar.gz mysql-5.1.34.tar.gz php-5.4.19.tar.gz
#! /Bin/bash
APACHEDIR =/usr/local/apache
MYSQLDIR =/usr/local/mysql
PHPDIR =/usr/local/php
HTTPD = httpd-2.2.25
MYSQL = mysql-5.1.34
Php-5.4.19 = PHP
Compression type of the tar.tar.gz tar package
APACHEMBER = 81 value returned after apache configuration fails
APACHENU = 82 value returned after apache fails to start
MYSQLMBER = 83 value returned after mysql configuration fails
MYSQLNU = 84 value returned after mysql initialization fails
MYSQLNUMBER = 85 value returned after mysql fails to start
PHPMBER = 86 php value returned after configuration failure
HTTPDPORT = $ (lsof-I: 80 | awk 'nr = 2 {print $1} ') process name that occupies port apache80
MYSQLPORT = $ (lsof-I: 3306 | awk 'nr = 2 {print $1} ') process name that occupies port mysql3306
Netstat-nl | grep: 80 &>/dev/null check whether port 80 is enabled
If [$? -Eq 0]; then
Pkill-9 $ HTTPDPORT: Kill the process name that occupies port 80
Else
Echo "80 port already by release"
Fi
Netstat-nl | grep: 3306 &>/dev/null check whether port mysql3306 is occupied
If [$? -Eq 0]; then
Pkill-9 $ MYSQLPORT: Kill the process name occupying port 3306
Else
Echo "3306 port already by release"
Fi
For package in {gcc, gcc-c ++, openssl-devel, openssl, ncurses-devel, libtermcap-devel, ncurses, libtermcap, libxml2, libxml2-devel} build a lazy environment for installing the LAMP source package
Do
Rpm-q $ package &>/dev/null determine whether these packages are installed
If [$? ! = 0]; then
Yum-y install $ package installation without Installation
Else
Echo "$ package already install"
Fi
Done
Echo "----------------------------------------------------------------------"
Echo "install apache"
Sleep 3
Cd/root enter the home directory (because I put my source code package under my home directory)
Tar-zxf/root/$ HTTPD $ TAR unzip apache files
Cd/root/$ HTTPD enter the decompressed directory
./Configure -- prefix = $ APACHEDIR -- enable-so -- enable-rewrite \ for configuration
-- Enable-ssl -- enable-cgi -- enable-charset-lite \
-- Enable-suexec -- with-suexec-caller = daemon \
-- With-suexec-docroot = $ APACHEDIR/htdocs homepage File Location
If [$? -Eq 0]; then
Make & make install after compilation
Else
Echo "apache install failed"
Exit $ APACHEMBER: the value of the returned value has been defined on the front of the number.
Fi
Cp $ APACHEDIR/bin/apachectl/etc/init. d/apache prepare for the apache STARTUP script and start it at/etc/init. d /.
Sed-I '2c # chkconfig: 35 85 15'/etc/init. d/apache Add the startup user mode to the apache Startup Script
Sed-I '3c # description: Apache is a world web server '/etc/init. d/apache description
Sed-I '/# ServerName/s/www.examle.com/?#/' $ APACHEDIR/conf/httpd. conf allows all domain names to be changed to their own domain names without modification
Ln-s $ APACHEDIR/bin/*/usr/sbin/connect apache commands for later use
Chkconfig -- add apache as startup
Service apache start apache service
Chkconfig apache on is set to boot
If [$? -Eq 0]; then
Echo "------------------------------------------------------------------------"
Echo "install mysql"
Sleep 3
Id mysql &>/dev/null determine whether the mysql user exists
If [$? ! = 0]; then
Useradd mysql
Else
Echo "user mysql already exist"
Fi
Cd/root
Tar-zxf/root/$ MYSQL $ TAR
Cd/root/$ MYSQL
./Configure -- prefix = $ MYSQLDIR -- with-charset = utf8 \
-- With-collation = utf8_general_ci \
-- With-extra-charsets = all \
-- Exec-prefix = $ MYSQLDIR \
-- With-client-ldflags =-all-static \
-- With-mysqld-ldflags =-all-static \
-- With-innodb -- with-plugins = partition
If [$? -Eq 0]; then
Make & make install
Else
Echo "mysql install failed"
Exit & MYSQLMBER
Fi
Test-f/etc/my. cnf
If [$? -Eq 0]; then
Mv/etc/my. cnf/etc/my. conf
Cp support-files/my-medium.cnf/etc/my. cnf
Else
Cp support-files/my-medium.cnf/etc/my. cnf
Fi
Cp support-files/mysql. server/etc/init. d/mysql & chmod + x/etc/init. d/mysql
Cp support-files/mysql. server/etc/rc. d/init. d/mysql & chmod + x/etc/rc. d/init. d/mysql
Chkconfig -- add mysql
Chown-R mysql. mysql $ MYSQLDIR /*
Ln-s $ MYSQLDIR/bin/*/usr/sbin/
Ln-s $ MYSQLDIR/lib/mysql/*/usr/lib64/
Ln-s $ MYSQLDIR/include/mysql/*/usr/include/
Sed-I's/^ skip-federated $/# skip-federated/'/etc/my. cnf
Mysql_install_db -- user = mysql
If [$? -Eq 0]; then
:
Else
Echo "mysql servier initialize failed"
Exit $ MYSQLNUMBER
Fi
Else
Echo "apache start failed please check up after the continue"
Exit $ APACHENU
Fi
Service mysql restart
Chkconfig mysql on
If [$? -Eq 0]; then
Echo "-----------------------------------------------------------------------"
Echo "install php"
Sleep 3
Cd/root
Tar-zxf/root/$ PHP $ TAR
Cd/root/$ PHP
./Configure -- prefix = $ PHPDIR -- with-apxs2 = $ APACHEDIR/bin/apxs \
-- With-mysql = $ MYSQLDIR -- with-config-file-php = $ PHPDIR \
-- Enable-mbstring -- enable-sockets \
If [$? -Eq 0]; then
Make & make install
Else
Echo "php install failed"
Exit $ PHPMBER
Fi
Cp php. ini-development $ PHPDIR/php. ini
Sed-I '311a AddType application/x-httpd-php. php' $ APACHEDIR/conf/httpd. conf
Sed-I '168c DirectoryIndex index.html index. php' $ APACHEDIR/conf/httpd. conf
Service apache stop & service apache start & chkconfig apache on
Else
Echo "mysql start failed please check up after the continue"
Exit $ MYSQLNU
Fi
For delete in {$ MYSQL, $ PHP, $ HTTPD}
Do
Rm-rf/root/$ delete
Done
Test
Vim/usr/local/apache/htdocs/index. php
<? Php
Phpinfo ();
?>
This is the php test webpage.
Vim/usr/local/apache/htdocs/test. php
<? Php
$ Links = mysql_connect ("localhost", "root ","");
If ($ links ){
Echo "like db OK !!!";
}
Else {
Echo "link db no !!!";
}
?>
Mysql php-based test webpage
Recommended reading:
Install the LAMP \ Vsftpd \ Webmin \ phpMyAdmin service and settings in Ubuntu 13.04
Compile and install LAMP in CentOS 5.9 (Apache 2.2.44 + MySQL 5.6.10 + PHP 5.4.12)
Source code for Web server architecture in RedHat 5.4 build the LAMP environment and application PHPWind
Build a WEB Server Linux + Apache + MySQL + PHP in the LAMP source code Environment