Manually install and compile LAMP

Manually install and compile LAMP


This time I mainly introduce the LAMP architecture and the whole process of manual installation and configuration. The process is written in detail as much as possible. The relevant software packages are prepared in advance, and the corresponding folders are created.

Insert picture description here
[[email protected] opt]# mkdir httpd mysql php

1. Apache website service

1.1 Origin of Apache

  • Originated from A Patchy Server, the famous open source web service software
  • In 1995, the 1.0 version of the Apache service program was released
  • Maintained by the Apache Software Foundation (ASF)
  • The latest name is "Apache HTTP Server"
  • Official site: htp://

1.2 Main features

  • Open source code, cross-platform application
  • Support multiple web programming languages
  • Modular design, stable operation, good safety

1.3 Software version


  • The current highest version is 1.3, stable operation
  • Good backward compatibility, but lacks some newer features


  • The current highest version is 2.4
  • Has more features
  • Compared with 1.X, there is a big difference in configuration management style

1.4 Advantages of Compiling and Installing Apache Service

  • With greater freedom, functions can be customized
  • Get the latest software version in time
  • Universally applicable to most Linux versions, easy to transplant

Obtain the source code package of the Apache server

  • Reference address: htp://

1.5 Directory structure of httpd service

Main directories and files

  • Service directory: /usr/local/httpd/
  • Main configuration file: /usr/local/httpd/conf/httpd.conf
  • Web directory: /usr/local/httpd/htdocs/
  • Service script: /usr/local/httpd/bin/apachectl
  • Executing program: /usr/local/httpd/bin/httpd
  • Access log: /usr/local/httpd/log/access_log
  • Error log: /usr/local/httpd/log/error_log

1.6 httpd.conf configuration file

Commonly used global configuration parameters

  • ServerRoot: Service Directory
  • Listen: listening IP address and port number
  • User: The identity of the user running the service
  • Group: The identity of the group running the service
  • ServerAdmin: Administrator mailbox
  • ServerName: The domain name of the website server
  • DocumentRoot: The root directory of the web document
  • DirectoryIndex: The default index page file
  • ErrorLog: Set the path of the error log file
  • LogLevel: The level of logging, the default is warn

Commonly used global configuration parameters (continued)

  • CustomLog: The location of the access log file
  • PidFile: The file that saves the PID number of the httpd process
  • AddDefaultCharset: Set the default character set encoding of web pages in the site
  • Timeout: network connection timeout, the default is 300 seconds
  • KeepAlive: Whether to keep the connection, optional On or Off
  • MaxKeepAliveRequests: Maximum number of requested files per connection
  • KeepAliveTimeout: The timeout period when keeping the connected state
  • Include: other configuration files that need to be included

1.5 Compile and install httpd server

Unzip the package and move it to the source package directory

[[email protected] opt]# cd httpd
[[email protected] httpd]# tar xjvf httpd-2.4.29.tar.bz2 
[[email protected] httpd]# tar xzvf apr-1.6.2.tar.gz
[[email protected] httpd]# tar xzvf apr-util-1.6.0.tar.gz
[[email protected] httpd]# mv apr-1.6.2 httpd-2.4.29/srclib/apr
[[email protected] httpd]# mv apr-util-1.6.0 httpd-2.4.29/srclib/apr-util

Install compiler and other tools

[[email protected] httpd]# yum -y install \
> gcc \       '编译器'
> gcc-c++ \   '编译器'
> make \      'make工具'
> pcre-devel \  '支持正则表达式的工具'
> expat-devel \  '使网站能解析标签语言的工具'
> perl        'Perl语言工具'


[[email protected] httpd]# cd httpd-2.4.29/
[[email protected] httpd-2.4.29]# ./configure \
> --prefix=/usr/local/httpd \  '指定路径'
> --enable-so \               '开启核心功能模块'
> --enable-rewrite \          '开启重写功能,如防盗链保护'
> --enable-charset-lite \     '开启字符集'
> --enable-cgi                '开启通用网关接口'

make compile and install

[[email protected] httpd-2.4.29]# make
[[email protected] httpd-2.4.29]# make install

Configure startup script

[[email protected] httpd-2.4.29]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd   '将启动脚本复制到/etc/init.d/初始化脚本文件中,并重命名为httpd'
[[email protected] httpd-2.4.29]# vim /etc/init.d/httpd
Insert picture description here
[[email protected] httpd-2.4.29]# chkconfig --add httpd   '将httpd加入到SERVICE管理器'

Edit configuration file

[[email protected] httpd-2.4.29]# vim /usr/local/httpd/conf/httpd.conf
Insert picture description here

Insert picture description here

Create a soft connection for the configuration file

[[email protected] httpd-2.4.29]# ln -s /usr/local/httpd/conf/httpd.conf /etc/  '创建httpd.conf配置文件的软链接到/etc下面'
[[email protected] httpd-2.4.29]# ln -s /usr/local/httpd/bin/* /usr/local/bin/ '将httpd的命令文件创建软链接到/usr/local/bin下'
[[email protected] httpd-2.4.29]# httpd -t
Syntax OK  ’此时可以使用相关命令‘
[[email protected] httpd-2.4.29]# apachectl -t
Syntax OK

Turn off the firewall and turn on the service

[[email protected] httpd-2.4.29]# systemctl stop firewalld.service
[[email protected] httpd-2.4.29]# setenforce 0
[[email protected] httpd-2.4.29]# service httpd start
[[email protected] httpd-2.4.29]# netstat -anpt | grep 80
tcp        0      0*               LISTEN      34233/httpd 
Insert picture description here

Two, MySQL compilation and installation

2.1 Introduction to MySQL

  • MySQL is an open source relational database management system (RDBMS) that uses the most commonly used database management language-Structured Query Language (SQL) for database management.
  • MySQL is open source, so anyone can download it under the General Public License and modify it according to individual needs.
  • MySQL is a true multi-threaded, multi-user SQL database service, which has attracted much attention for its speed, reliability and adaptability. Most people think that MySQL is the best choice for managing content when transactional processing is not required.

2.2 MySQL compilation and installation

Install related packages

[[email protected] mysql]# yum install -y ncurses-devel autoconf cmake
[[email protected] mysql]# tar xzvf mysql-5.6.26.tar.gz

cmake configuration

[[email protected] mysql]# cd mysql-5.6.26/
[[email protected] mysql-5.6.26]# cmake \
> -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ '指定路径'
> -DDEFAULT_CHARSET=utf8 \  '指定字符集'
> -DDEFAULT_COLLATION=utf8_general_ci \  '指定字符集'
> -DEXTRA_CHARSETS=all \  '指定字符集'
> -DSYSCONFIDIR=/etc \   '指定配置文件目录'
> -DMYSQL_DATADIR=/home/mysqI/ \  '指定数据文件目录,由mysql用户管理'
> -DMYSQL_UNIX_ADDR=/home/mysql/mysql.sock  '指定通信文件,连接数据库的必要文件'

make compile and install

[[email protected] mysql-5.6.26]# make
[[email protected] mysql-5.6.26]# make install

Copy configuration files and script files

[[email protected] mysql-5.6.26]# cp support-files/my-default.cnf /etc/my.cnf
[[email protected] mysql-5.6.26]# cp support-files/mysql.server /etc/init.d/mysqld

Configure script files and command environment

[[email protected] mysql-5.6.26]# chmod 755 /etc/init.d/mysqld  '增加执行权限'
[[email protected] mysql-5.6.26]# chkconfig --add /etc/init.d/mysqld  '将mysqld添加到service服务器中'
[[email protected] mysql-5.6.26]# cd /etc/init.d/
[[email protected] init.d]# chkconfig --level 35 mysqld on  '设置mysqld在运行级别3和5都是开启的'
[[email protected] init.d]# echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile  '设置mysql命令到/etc/profile中寻找'
[[email protected] init.d]# source /etc/profile  '使命令不需重启立即生效'
[[email protected] init.d]# echo $PATH  '查看环境'

Add user

[[email protected] init.d]# useradd -s /sbin/nologin mysql  '添加用户,指定shell,禁止用户登录系统'
[[email protected] init.d]# chown -R mysql.mysql /usr/local/mysql/  '设置属主和属组'

Initialize the database

[[email protected] init.d]# cd /usr/local/mysql/scripts/
[[email protected] scripts]# /usr/local/mysql/scripts/mysql_install_db \
> --user=mysql \
> --ldata=/var/lib/mysql \
> --basedir=/usr/local/mysql/ \
> --datadir=/home/mysql/

Edit startup script

[[email protected] scripts]# vim /etc/init.d/mysqld 
basedir=/usr/local/mysql	'添加工作路径'
datadir=/home/mysql			'添加数据路径'
Insert picture description here

Start the service and set the user password

[[email protected] scripts]# service mysqld start
[[email protected] scripts]# netstat -anpt | grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      64078/mysqld 
[[email protected] scripts]# mysqladmin -u root -p password "abc123"  '给root用户设置密码'
[[email protected] scripts]# mysql -u root -p
Enter password: 
mysql> show databases; '查看或显示当前用户权限范围以内的数据库'
| Database           |
| information_schema |
| mysql              |
| performance_schema |
| test               |
4 rows in set (0.00 sec)

Three, PHP source code compilation and installation

3.1 Introduction to PHP

  • PHP stands for "Hypertext Preprocessor" and is a universal open source scripting language. PHP is a scripting language executed on the server side, similar to the C language, and is a commonly used website programming language. PHP's unique syntax is a mixture of C, Java, Perl, and PHP's own syntax. Conducive to learning, widely used, mainly suitable for the field of Web development
  • PHP supports most of the popular databases, the operation function at the database level is very powerful, and it can support Unix, Windows, Linux and other operating systems

3.2 PHP compilation and installation

Install related packages

[[email protected] php]# yum -y install \
> gd \
> libpng \
> libpng-devel \
> pcre \
> pcre-devel \
> libxml2-devel \
> libjpeg-devel
[[email protected] php]# tar jxvf php-5.6.11.tar.bz2


[[email protected] php]# cd php-5.6.11/
[[email protected] php-5.6.11]# ./configure \
> --prefix=/usr/local/php5 \  '指定安装路径'
> --with-gd \         '指定GD库'
> --with-zlib \       '支持数据压缩函数库'
> --with-apxs2=/usr/local/httpd/bin/apxs \  '设置Apache服务提供的apxs模块支持程序的文件位置'
> --with-mysql=/usr/local/mysql \  '设置MySQL数据库服务程序的安装位置'
> --with-config-file-path=/usr/local/php5 \  '设置PHP配置文件存放的位置'
> --enable-mbstring  '启用多字节字符串功能,以便支持中文等代码'

make compile and install

[[email protected] php-5.6.11]# make
[[email protected] php-5.6.11]# make install

Edit configuration file

[[email protected] php-5.6.11]# cp php.ini-development /usr/local/php5/php.ini
[[email protected] php-5.6.11]# ln -s /usr/local/php5/bin/* /usr/local/bin/
[[email protected] php-5.6.11]# vim /etc/httpd.conf   '编辑php的默认首页'
Insert picture description here

Insert picture description here

Restart the Apache service and configure the PHP home page

[[email protected] php-5.6.11]# service httpd stop
[[email protected] php-5.6.11]# service httpd start
[[email protected] php-5.6.11]# vim /usr/local/httpd/htdocs/index.html
[[email protected] php-5.6.11]# cd /usr/local/httpd/htdocs/
[[email protected] htdocs]# mv index.html index.php
Insert picture description here

Test whether the PHP webpage can access the MySQL database

Insert picture description here

Fourth, LAMP architecture construction forum

4.1 What is LAMP

  • Currently the most mature enterprise website application mode, which can provide dynamic website application and development environment

4.2 Build composition

  • Linux
  • Apache
  • MySQL
  • PHP/Perl/Python

4.3 Advantages of LAMP

  • low cost
  • Customizable and easy to develop
  • Easy to use, safe and stable

4.4 LAMP Architecture Building Forum

Add bbs database to MySQL database

[[email protected] opt]# unzip
[[email protected] opt]# cp -r upload/ /usr/local/httpd/htdocs/bbs
[[email protected] opt]# cd /usr/local/httpd/htdocs/bbs
[[email protected] bbs]# mysql -u root -p
Enter password: 
mysql> show databases;
| Database           |
| information_schema |
| mysql              |
| performance_schema |
| test               |
4 rows in set (0.01 sec)

mysql > create database bbs ;  'Create database'
Query OK ,  1 row affected ( 0.01 sec )

mysql > show databases ;
+ – – – – – – – – – – +
| Database |
+ – – – – – – – – – – +
| information_schema |
| bbs |
| mysql |
| performance_schema |
| test |
+ – – – – – – – –– – +
5 rows in set ( 0.00 sec )
mysql > use bbs ;
Database changed
mysql > show tables ;
Empty set ( 0.01 sec )

mysql > grant all on bbs . * to'bbsuser' @ '%' identified by'admin123 ' ;
'Set the password admin123 for user bbsuser and set all permissions, all terminals can log in'
Query OK ,  0 rows affected ( 0.00 sec )

mysql > flush privileges ;  'Flush the database'
Query OK ,  0 rows affected ( 0.00 sec )

mysql > exit

Insert picture description here

Insert picture description here

Add permissions

[[email protected] bbs]# chown -R daemon ./config
[[email protected] bbs]# chown -R daemon ./data
[[email protected] bbs]# chown -R daemon ./uc_client
[[email protected] bbs]# chown -R daemon ./uc_server/data
Insert picture description here

Insert picture description here

Insert picture description here

Insert picture description here

Insert picture description here

Insert picture description here