Linux Essentials-centos 7.4 Under source code compilation build Lamp Architecture

Source: Internet
Author: User
Tags bz2 curl openssl phpmyadmin

CentOS 7.4 Build Lamp
Lamp:linux, Apache, MySQL, PHP

Directory:
The first part of the preparatory work
Second part installs Apache service
The third part installs the MySQL service
Part IV builds PHP operating environment
Part V Lamp Architecture Application

The first part of the preparatory work
One: server: Linux system-centos 7.4;
IP Address: 192.168.80.10

Client: Take WIN7 as an example, test the result of verification, and the server in the same network segment;
IP Address: 192.168.80.2

Two: Download the compressed package
http://httpd.apache.org/download.cgi//http Compression Pack
http://apr.apache.org/download.cgi//http Plug-in package
http://mirrors.sohu.com/mysql///mysql Compression Pack
http://www.php.net/downloads.php//php Compression Pack
https://www.phpmyadmin.net///phpmyadmin Compression Pack

Apr-1.6.2.tar.gz and apr-util-1.6.0.tar.gz are required plugins for httpd2.4 later versions and must be installed
phpMyAdmin is a Web application that is written in PHP and used to manage the MySQL database, which is used to verify after the lamp is built.

Put the compressed package under the Linux system

Third: Close the firewall with SELinux

Second part installs Apache service
One: Install the compilation tools and plugins
[[email protected] ~]# yum-y install \

GCC \
gcc-c++ \
Make \
Pcre-devel \
Expat-devel \
Perl

Two: Unzip:
[Email protected] ~]# Tar XF apr-1.6.2.tar.gz
[Email protected] ~]# Tar XF apr-util-1.6.0.tar.gz
[Email protected] ~]# Tar XF httpd-2.4.29.tar.bz2

Put the plug-in into the httpd directory
[Email protected] ~]# MV apr-1.6.2 HTTPD-2.4.29/SRCLIB/APR
[Email protected] ~]# MV apr-util-1.6.0 httpd-2.4.29/srclib/apr-util

Three: Configuration (custom personalization)
[[Email protected] ~]# CD httpd-2.4.29//must enter the installation directory
[Email protected] httpd-2.4.29]#/configure \

--PREFIX=/USR/LOCAL/HTTPD \//Specifies to install the HTTPD program into the/USR/LOCAL/HTTPD directory
--ENABLE-SO \//Enable dynamic load module function
--enable-rewrite \//Enable Web page address rewriting for website optimization and Directory Migration
--enable-charset-lite \//enable character set support to support Web pages that are encoded using a variety of character sets
--ENABLE-CGI//Enable CGI scripting support for extended Web site application access

IV: Compilation and Installation
[[email protected] httpd-2.4.29]# make && make install

To add a httpd service to a system service
[Email protected] httpd-2.4.29]# CP/USR/LOCAL/HTTPD/BIN/APACHECTL/ETC/INIT.D/HTTPD
[Email protected] httpd-2.4.29]# VI/ETC/INIT.D/HTTPD
Add the following two lines (Note that "#" cannot be omitted):

Save exit
[[email protected] httpd-2.4.29]# chkconfig--add httpd//Add httpd to service Manager
[[email protected] httpd-2.4.29]# Systemctl daemon-reload//heavy-duty system System Manager

V: Edit httpd master configuration file
[Email protected] httpd-2.4.29]# vi/usr/local/httpd/conf/httpd.conf
Modify the following content:
ServerName www.aa.com
Save exit

Optimized execution path (the original path of the executing program file is not in the PATH environment variable, do a soft link to make it executable)
[Email protected] httpd-2.4.29]# ln-s/usr/local/httpd/conf/httpd.conf/etc/
[Email protected] httpd-2.4.29]# ln-s/usr/local/httpd/bin/*/usr/local/bin/

Check for syntax errors
[Email protected] httpd-2.4.29]# httpd–t
Or: [[email protected] httpd-2.4.29]# apachectl–t

View Program version

Six: Start the service
[Email protected] httpd-2.4.29]# systemctl start httpd
[[email protected] httpd-2.4.29]# Systemctl enable httpd//set httpd to boot
[Email protected] httpd-2.4.29]# NETSTAT-ANPT | grep 80//View httpd service Run status

Seven: Validation
Accessing the server with the WIN7 client
Browser access: http://192.168.80.10

Validation successful
(Note that the default content of the Web page is:/usr/local/httpd/htdocs/index.html)

The third part installs the MySQL service
One: Install the compilation tools and plugins
[[email protected] ~]# yum-y install \

ncurses \
Ncurses-devel \
Bison \
CMake

Second: Establish database program users
[[email protected] ~]# useradd-s/sbin/nologin MySQL

Three: Unzip the MySQL installation package
[Email protected] ~]# tar XF mysql-boost-5.7.20.tar.gz-c/opt/

Four: Configuration (personalized configuration and optimization project)
[Email protected] ~]# cd/opt/mysql-5.7.20/
[Email protected] mysql-5.7.20]# cmake \

-dcmake_install_prefix=/usr/local/mysql \//define the installation directory
-dmysql_unix_addr=/usr/local/mysql/mysql.sock \//Connection Database socket path
-DSYSCONFDIR=/ETC \//Specify initialization parameter file directory (MY.CNF)
-DSYSTEMD_PID_DIR=/USR/LOCAL/MYSQL \//Database directory
-DDEFAULT_CHARSET=UTF8 \//Specifies the character set encoding used by default
-DDEFAULT_COLLATION=UTF8_GENERAL_CI \//Specifies the character set collation used by default, Utf8_general_ci is a universal rule for UTF-8 character set
-dwith_innobase_storage_engine=1 \//Support InnoDB engine
-dwith_archive_storage_engine=1 \
-dwith_blackhole_storage_engine=1 \
-dwith_perfschema_storage_engine=1 \//install support database partition
-dmysql_datadir=/usr/local/mysql/data \
-dwith_boost=boost \
-dwith_systemd=1
(Note: If there is an error in the process of CMake, when the error is resolved, you need to put the source directory
CMakeCache.txt file Delete, and then re-cmake, otherwise the error remains)

V: Compile and install
[[email protected] mysql-5.7.20]# make
[[email protected] mysql-5.7.20]# make install

To set permissions on a database directory
[Email protected] mysql-5.7.20]# chown-r mysql.mysql/usr/local/mysql/

VI: Edit MySQL master configuration file
[Email protected] mysql-5.7.20]# VI/ETC/MY.CNF
(All contents are deleted and replaced with the following contents)
[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

[Email protected] mysql-5.7.20]# chown mysql:mysql/etc/my.cnf

Six: Setting Environment variables
[Email protected] mysql-5.7.20]# echo ' path=/usr/local/mysql/bin:/usr/local/mysql/lib: $PATH ' >>/etc/profile
Add these two paths to the environment variable and put them in the profile file to start from running, otherwise it won't take effect
[[email protected] mysql-5.7.20]# echo ' export PATH ' >>/etc/profile
Set as a global variable to make it use a wider environment
[[email protected] mysql-5.7.20]# source/etc/profile//immediate effect

Seven: Initializing the database
[Email protected] ~]# cd/usr/local/mysql/
[Email protected] mysql]# bin/mysqld \

--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data

Eight: Add system services
[email protected] mysql]# CP usr/lib/systemd/system/mysqld.service/usr/lib/systemd/system/
[Email protected] mysql]# Systemctl daemon-reload

Nine: Start MySQL service
[Email protected] mysql]# systemctl start mysqld
[Email protected] mysql]# NETSTAT-ANPT | grep 3306//view service run status

[[email protected] mysql]# Systemctl enable MYSQLD//set to boot

Ten: Accessing Database operations
[Email protected] mysql]# mysqladmin-u root-p password "abc123"
Set password for root account to abc123
Note: Prompt input is the original password (original no password, direct return)
[[email protected] mysql]# mysql-u root–p//Login Database
Note: There is a password plus "-P", if no password is not added "-P"


Database installation configuration successful, exit enter "Quit"

Part IV builds PHP operating environment
One: Installation tools and plug-ins
[[email protected] ~]# yum-y install \

Libjpeg \
Libjpeg-devel \
Libpng libpng-devel \
FreeType freetype-devel \
LIBXML2 \
Libxml2-devel \
Zlib zlib-devel \
Curl curl-devel \
OpenSSL Openssl-devel
(Note: If an error occurs during Setup, modify the following file to add a row)
Vi/usr/local/httpd/bin/apxs
#!/usr/bin/perl–w

Two: Unpack the installation package
[Email protected] ~]# tar xjvf php-7.1.10.tar.bz2

Three: Configuration (personalized configuration and optimization project)
[Email protected] php-7.1.10]# CD php-7.1.10
[Email protected] 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

Four: Compiling and installing
[[email protected] php-7.1.10]# make
[[email protected] php-7.1.10]# make install

Five: Edit Profile
[[[email protected] php-7.1.10]# CP php.ini-development/usr/local/php/lib/php.ini
//Create configuration file
[[email protected] php-7.1.10]# Vi/usr/local/php/lib/php.ini//Edit configuration file
Mysqli.default_socket =/usr/ Local/mysql/mysql.sock//associating PHP with mysql
Date.timezone = asia/shanghai//time zone Settings
[[email protected] php-7.1.10 ]#/usr/local/php/bin/php–m//Verify the installed module

VI: Associating PHP with Apache services
[[email protected] php-7.1.10]# vi/etc/httpd.conf//Edit Apache configuration file, so httpd support PHP page parsing
Add the following two lines of content:
AddType application/x-httpd-php. php
AddType Application/x-httpd-php-source. Phps
Modify the following content:
DirectoryIndex index.php index.html//Note here that the PHP file must be placed in front, first read
[[email protected] php-7.1.10]# rm-f/usr/local/httpd/htdocs/index.html//delete default HTML file
[[email protected] php-7.1.10]# vi/usr/local/httpd/htdocs/index.php//Edit PHP test page
Add the following content (PHP information)
<?php
Phpinfo ();
?>
Save exit
[Email protected] php-7.1.10]# Systemctl stop httpd
[[email protected] php-7.1.10]# systemctl start httpd//Restart HTTPD service

Seven: Validation

    1. Access 192.168.80.10 with Win7
      (Note: If you cannot access it, check the httpd running state with Netstat)

    2. Test database
      [[email protected] ~]# mysql-u root–p//Login database (enter the root password set above)
      CREATE DATABASE Myadm; Create a database Myadm
      GRANT all on Myadm. To ' myadm ' @ '% ' identified by ' admin123 ';//Authorization
      GRANT all on Myadm.
      To ' myadm ' @ ' localhost ' identified by ' admin123 ';
      Flush privileges; Refresh Permissions

      Restart MySQL Service
      [Email protected] ~]# systemctl restart mysqld

Edit the index.php file (delete the original content, add the following content)
<?php
$link =mysqli_connect (' 192.168.80.40 ', ' myadm ', ' admin123 ');
if ($link) echo "else echo "fail!!";
?>

Restarting the HTTP service
[Email protected] ~]# Systemctl stop httpd
[Email protected] ~]# systemctl start httpd

Access the server address with Win7 192.168.80.10

Validation successful

Part V Lamp Architecture Application
To deploy the phpMyAdmin system:
phpMyAdmin is a Web application that is written in PHP and used to manage MySQL databases.
One: Installation phpMyAdmin
[email protected] ~]# Yum install-y unzip
(because I downloaded the phpmyadmin is the ZIP format compressed package, so to install Unzip command decompression)
Decompression phpMyAdmin
[Email protected] ~]# Unzip phpmyadmin-4.7.6-all-languages.zip-d/opt/
[Email protected] ~]# cd/opt/
[[Email protected] opt]# MV Phpmyadmin-4.7.6-all-languages/usr/local/httpd/htdocs/myadm//Move files to Apache directory

II: Create a phpMyAdmin configuration file
[Email protected] opt]# cd/usr/local/httpd/htdocs/myadm/
[email protected] myadm]# CP config.sample.inc.php config.inc.php

Three: Edit the configuration file
[Email protected] myadm]# VI config.inc.php
$cfg [' Servers '] [$i] [' host '] = ' 127.0.0.1 '; change localhost to IP
Save exit

Quad: Restart Apache Service
[Email protected] myadm]# Systemctl stop httpd
[Email protected] myadm]# systemctl start httpd

V: Verify
Access Http://192.168.80.10/myadm with Win7

Enter the root account and password to log in

Validation successful

Linux Essentials-centos 7.4 Under source code compilation build Lamp Architecture

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.