Theory + experiment-source code compile and install LAMP

Preface

The LAMP architecture is one of the current mature enterprise website application modes. It refers to a set of systems and related software that work together to provide dynamic website services and application development environments. LAMP is an acronym that specifically includes Linux operating system, Apache web server, MySQL database server, PHP (or Perl, Python) web programming language. This chapter will build the LAMP environment by compiling source code, which can meet the needs of enterprise customization.
When building the LAMP platform, the order of installation of each component is Linux, Apache, MySQL, PHP.
There is no strict order for the installation of Apache and MySQL; the installation of the PHP environment is generally put at the end, responsible for communicating with the Web server and database system to work together.

1. How to compile and install Apache

1. Introduction to Apache

"Apache HTTP Server" is an outstanding representative of open source software projects. It provides web browsing services based on the standard HTTP network protocol and has long maintained more than half of the share in the field of web servers. The Apache server can run on multiple operating system platforms such as Linux, UNIX, and Windows.
Apache server is the software formed after the integration and improvement of several Web server programs that appeared before. Its name comes from "A Patchy Server", which means "formed after modification (patches) based on the code of the original Web service program. Server program".
In 1995, the Apache service program released version 1.0. Since then, the "Apache Group" has been responsible for the management and maintenance of the project; until 1999, the Apache Software Foundation (ASF) was established on the basis of the "Apache Group". ). Currently, the Apache project has been managed and maintained by ASF.
ASF is a non-profit organization, initially only responsible for the management of the "Apache Web" server project. As the demand for Web applications continues to expand, ASF has gradually increased many open source software projects related to Web technology, so Apache now represents more than just the Web The server more broadly represents the many open source software projects managed by ASF. The official website of the ASF Foundation is http://www.apache.org/.
"Apache HTTP Server" is one of the well-known software projects under ASF, its official name is "httpd", which is the historical Apache web server. In the follow-up content, unless otherwise specified, using "Apache" or "httpd" refers to "Apache HTTP Server".

2. Features of Apache

(1) Open source code: This is one of the important features of the Apache server and the basis for other features.
The Apache service program is jointly maintained by many developers all over the world, and anyone can
use it freely , which fully reflects the spirit of open source software.
(2) Cross-platform application: This feature benefits from the open source code of Apache. Apache server can run
on most software and hardware platforms, all UNIX operating systems can run Apache server
, and even Apache server can run well on most Windows system platforms.
The cross-platform nature of the Apache server makes it suitable for widespread use.
(3) Support various web programming languages: The web programming languages ​​supported by the Apache server include Perl, PHP,
Python, Java, etc., and even Microsoft's ASP technology can also be used in the Apache server. Supporting a
variety of commonly used Web programming languages ​​enables Apache to have a wider range of applications.
(4) Modular design: Apache does not concentrate all functions in a single service program, but instead
uses standard modules to achieve proprietary functions as much as possible, which brings good
scalability to the Apache server . Other software developers can write standard module programs to add
other functions that Apache does not have.
(5) Very stable operation: Apache server can be used to build Web sites with heavy traffic
Many well-known corporate websites use Apache as their web service software.
(6) Good security: Apache server has relatively good security, which is a common
feature of open source software . In addition, the Apache maintenance team will provide patches for the discovered vulnerabilities in a timely manner to provide
all users of Apache with the most secure server program.

3. Experiment

####编译安装HTTP服务####
#####安装Apache所需软件#####
apr-1.6.2.tar.gz
apr-util-1.6.0.tar.gz
httpd-2.4.29.tar.gz
####将上面3个包传到opt目录下####
[root@localhost ~]# cd /opt
[root@localhost opt]# ll
total 81636
-rw-r--r--  1 root root  1071074 Aug 31 15:32 apr-1.6.2.tar.gz
-rw-r--r--  1 root root   565507 Aug 31 15:32 apr-util-1.6.0.tar.gz
-rw-r--r--  1 root root  6567926 Aug 31 15:32 httpd-2.4.29.tar.bz2
-rw-r--r--  1 root root 48833145 Aug 31 15:32 mysql-boost-5.7.20.tar.gz
-rw-r--r--  1 root root 15069098 Aug 31 15:32 php-7.1.10.tar.bz2
-rw-r--r--  1 root root 11475526 Aug 31 15:32 phpMyAdmin-4.7.6-all-languages.zip
drwxr-xr-x. 2 root root        6 Oct 31  2018 rh
[root@localhost opt]# tar xf apr-1.6.2.tar.gz
[root@localhost opt]# tar xf apr-util-1.6.0.tar.gz
[root@localhost opt]# tar xf httpd-2.4.29.tar.bz2
[root@localhost opt]# mv apr-1.6.2 httpd-2.4.29/srclib/apr
[root@localhost opt]# mv apr-util-1.6.0 httpd-2.4.29/srclib/apr-util
##################安装环境#######
[root@localhost opt]# yum -y install \
> gcc \
> gcc-c++ \
> make \
> pcre-devel \
> expat-devel \
> perl
[root@localhost opt]# cd /opt/httpd-2.4.29/
[root@localhost httpd-2.4.29]# ./configure \
> --prefix=/usr/local/httpd \
> --enable-so \
> --enable-rewrite \
> --enable-charset-lite \
> --enable-cgi
###编译及安装###
[root@localhost httpd-2.4.29]# make -j3    ###先make -j3   然后make install   -j3是你核心数,最大不要超过虚拟机的核心数
[root@localhost httpd-2.4.29]# make install
####优化执行路径####
[root@localhost httpd-2.4.29]# ln -s /usr/local/httpd/conf/httpd.conf /etc/
[root@localhost httpd-2.4.29]# ln -s /usr/local/httpd/bin/* /usr/local/bin/
[root@localhost httpd-2.4.29]# httpd -v    ###查看下HTTP版本
Server version: Apache/2.4.29 (Unix)
Server built:   Aug 31 2020 15:55:00
###建立[service].service 配置文件添加系统给服务####
在/lib/systemd/system/目录下,建立一个以.service 结尾的单元(unit)配置文件,
用于控制由 systemd 管理或监控的 httpd 服务
[root@localhost httpd-2.4.29]# cd /lib/systemd/system/
[root@localhost system]# vim httpd.service
[Unit]
Description=The Apache HTTP Server
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/httpd/logs/httpd.pid
ExecStart= /usr/local/bin/apachectl $OPTIONS
ExecrReload= /bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
:wq
[root@localhost system]# systemctl start httpd.service
[root@localhost system]# systemctl enable httpd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@localhost system]# systemctl is-enabled httpd.service
enabled
####httpd.conf修改配置文件###
[root@localhost system]# vi /usr/local/httpd/conf/httpd.conf
ServerName www.51xit.top:80  ###更改下
[root@localhost system]# systemctl restart httpd
[root@localhost system]# netstat -anpt | grep 80
tcp6       0      0 :::80                   :::*                    LISTEN      42997/httpd

Web page verification, if the following interface appears, it shows success
Insert picture description here

Two, MySQL database compilation and installation method

###安装mysql###
[root@localhost ~]# cd /opt
[root@localhost opt]# ll
total 81640
-rw-r--r--   1 root root   1071074 Aug 31 15:32 apr-1.6.2.tar.gz
-rw-r--r--   1 root root    565507 Aug 31 15:32 apr-util-1.6.0.tar.gz
drwxr-xr-x  12  501 games     4096 Aug 31 15:55 httpd-2.4.29
-rw-r--r--   1 root root   6567926 Aug 31 15:32 httpd-2.4.29.tar.bz2
-rw-r--r--   1 root root  48833145 Aug 31 15:32 mysql-boost-5.7.20.tar.gz
-rw-r--r--   1 root root  15069098 Aug 31 15:32 php-7.1.10.tar.bz2
-rw-r--r--   1 root root  11475526 Aug 31 15:32 phpMyAdmin-4.7.6-all-languages.zip
drwxr-xr-x.  2 root root         6 Oct 31  2018 rh
[root@localhost opt]# yum -y install \
> ncurses \
> ncurses-devel \
> bison \
> cmake
[root@localhost opt]# useradd -s /sbin/nologin  mysql
[root@localhost opt]# tar xf mysql-boost-5.7.20.tar.gz
###配置选项###
[root@localhost opt]# cd /opt/mysql-5.7.20/
[root@localhost mysql-5.7.20]# cmake \
> -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
> -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
> -DSYSCONFDIR=/etc \
> -DSYSTEMD_PID_DIR=/usr/local/mysql \
> -DDEFAULT_CHARSET=utf8  \
> -DDEFAULT_COLLATION=utf8_general_ci \
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \
> -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
> -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
> -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
> -DMYSQL_DATADIR=/usr/local/mysql/data \
> -DWITH_BOOST=boost \
> -DWITH_SYSTEMD=1
###编译安装###
[root@localhost mysql-5.7.20]# make -j3
[root@localhost mysql-5.7.20]# make install
###数据库目录进行权限调整###
[root@localhost mysql-5.7.20]# chown -R mysql:mysql /usr/local/mysql/
###建立调整配置文件###
[root@localhost mysql-5.7.20]# vi /etc/my.cnf
[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES

:wq
[root@localhost mysql-5.7.20]# chown mysql:mysql /etc/my.cnf
###设置环境变量###
[root@localhost mysql-5.7.20]# echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
[root@localhost mysql-5.7.20]# echo 'export PATH' >> /etc/profile
[root@localhost mysql-5.7.20]#source /etc/profile 
###初始化数据库###
[root@localhost mysql-5.7.20]# cd /usr/local/mysql/
[root@localhost mysql]# bin/mysqld \
> --initialize-insecure \
> --user=mysql \
> --basedir=/usr/local/mysql \
> --datadir=/usr/local/mysql/data
[root@localhost mysql]# systemctl enable mysqld
Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /usr/lib/systemd/system/mysqld.service.
[root@localhost mysql]# systemctl start mysqld
[root@localhost mysql]# systemctl status mysqld    ### 出现 Active:active(running) 表示成功开启
[root@localhost mysql]# netstat -anpt | grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      114516/mysqld
[root@localhost mysql]# mysqladmin -u root -p password
Enter password:      ### 回车
New password: ******    ###自己输入密码,123456
Confirm new password: ******
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

Three, the method of constructing PHP operating environment

####################安装PHP环境#####
[root@localhost opt]# ll
total 81644
-rw-r--r--   1 root root   1071074 Aug 31 15:32 apr-1.6.2.tar.gz
-rw-r--r--   1 root root    565507 Aug 31 15:32 apr-util-1.6.0.tar.gz
drwxr-xr-x  12  501 games     4096 Aug 31 15:55 httpd-2.4.29
-rw-r--r--   1 root root   6567926 Aug 31 15:32 httpd-2.4.29.tar.bz2
drwxr-xr-x  38 7161 31415     4096 Aug 31 16:25 mysql-5.7.20
-rw-r--r--   1 root root  48833145 Aug 31 15:32 mysql-boost-5.7.20.tar.gz
-rw-r--r--   1 root root  15069098 Aug 31 15:32 php-7.1.10.tar.bz2
-rw-r--r--   1 root root  11475526 Aug 31 15:32 phpMyAdmin-4.7.6-all-languages.zip
drwxr-xr-x.  2 root root         6 Oct 31  2018 rh
[root@localhost opt]# yum -y install \
> libjpeg \
> libjpeg-devel \
> libpng libpng-devel \
> freetype freetype-devel \
> libxml2 \
> libxml2-devel \
> zlib zlib-devel \
> curl curl-devel \
> openssl openssl-devel
[root@localhost opt]# tar xjvf php-7.1.10.tar.bz2
[root@localhost opt]# cd php-7.1.10
[root@localhost php-7.1.10]# ./configure \
> --prefix=/usr/local/php \
> --with-apxs2=/usr/local/httpd/bin/apxs \
> --with-mysql-sock=/usr/local/mysql/mysql.sock \
> --with-mysqli \
> --with-zlib \
> --with-curl \
> --with-gd \
> --with-jpeg-dir \
> --with-png-dir \
> --with-freetype-dir \
> --with-openssl \
> --enable-mbstring \
> --enable-xml \
> --enable-session \
> --enable-ftp \
> --enable-pdo \
> --enable-tokenizer \
> --enable-zip
[root@localhost php-7.1.10]# make -j3
[root@localhost php-7.1.10]# make install
[root@localhost php-7.1.10]# cp php.ini-development /usr/local/php/lib/php.ini
[root@localhost php-7.1.10]# vi /usr/local/php/lib/php.ini
mysqli.default_socket = /usr/local/mysql/mysql.sock
date.timezone = Asia/Shanghai
[root@localhost php-7.1.10]# /usr/local/php/bin/php -m     ###验证安装的模块
[PHP Modules]
Core
ctype
curl
date
dom
fileinfo
filter
ftp
gd
hash
iconv
json
libxml
mbstring
mysqli
mysqlnd
openssl
pcre
PDO
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zip
zlib

[Zend Modules]

[root@localhost php-7.1.10]# vi /etc/httpd.conf   ###在合适的位置新增
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

DirectoryIndex index.php index.html
:wq
[root@localhost php-7.1.10]# rm -f /usr/local/httpd/htdocs/index.html
[root@localhost php-7.1.10]# vi /usr/local/httpd/htdocs/index.php
<?php
phpinfo();
?>
:wq
[root@localhost php-7.1.10]#systemctl restart httpd 

Web page verification, when the following interface appears, it shows success.
Insert picture description here
The following test database is working properly:

[root@localhost php-7.1.10]# mysql -u root -p
Enter password: ******    ###密码,123456
###输入以下内容飞权限账号、密码###
CREATE DATABASE myadm;
GRANT all ON myadm.* TO 'myadm'@'%' IDENTIFIED BY 'admin123';
GRANT all ON myadm.* TO 'myadm'@'localhost' IDENTIFIED BY 'admin123';
flush privileges;
exit     ###退出mysql
[root@localhost php-7.1.10]# vi /usr/local/httpd/htdocs/index.php
<?php
$link=mysqli_connect('20.0.0.21','myadm','admin123');
if($link) echo "<h1>Success!!</h1>";
else echo "Fail!!";
?>
:wq

Web page verification, if the following interface appears, it will show success.
Insert picture description here
If there is a little error, it will show failure. The
IP address error is shown as follows:
Insert picture description here
Insert picture description here

Fourth, the method of deploying and using phpMyAdmin system

[root@localhost ~]# cd /opt
[root@localhost opt]# unzip phpMyAdmin-4.7.6-all-languages.zip -d /opt/
[root@localhost opt]# mv phpMyAdmin-4.7.6-all-languages /usr/local/httpd/htdocs/myadm
[root@localhost opt]# cd /usr/local/httpd/htdocs/myadm
[root@localhost myadm]# cp config.sample.inc.php config.inc.php
[root@localhost myadm]# vi config.inc.php
$cfg['Servers'][$i]['host'] = '127.0.0.1';    ###把localhost 改成IP 31行
:wq

Web page verification, the following interface appears, it shows that you have successfully
Insert picture description here
logged in to the management system with root and the password configured for root. Can manage the database
Insert picture description here

Guess you like

Origin blog.csdn.net/ZG_66/article/details/108320586