Centos7 build a LAMP environment (compiler installation)

1. Check system version

[niemx@localhost ~]$ cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

2, install the software ready

(1) Apr 1.5.2.tar.bz2

Apache Portable Runtime (APR) is an Apache web server support library. It provides a set of maps to the underlying operating system (OS), application programming interfaces (API). If the operating system does not support a particular function, APR will provide a simulation. Therefore, the programmer can use the APR for transplant programs across different platforms. APR for Tomcat is the biggest role socket scheduling.

Download http://archive.apache.org/dist/apr/apr-1.5.2.tar.bz2

(2) apr-util-1.5.4.tar.bz2

apr and apr-util are provided for the upper application runtime. Providing the operating system data structures and interface package C does not stl library. Apparently many of the software are based on the apache apr / apr-util-based library development. apr-util only provides more operating system data structures and package interface only on the basis of apr.

Download http://archive.apache.org/dist/apr/apr-util-1.5.4.tar.bz2

(3)pcre-8.43.tar.gz

PCRE (PerlCompatibleRegularExpressions) is a Perl library, including perl-compatible regular expression library. These use when performing regular expression pattern matching using the same syntax and semantics Perl5 is useful. httpd build process need to rely on pcre-devel package.

Download https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz

(4)httpd-2.4.41.tar.gz

httpd for the Apache HTTP server program. Direct execution of the program can start the server service.

Download http://www.apache.org/dist/httpd/httpd-2.4.41.tar.gz

(5) mysql-5.6.25.tar.gz

First check the linux version of the system to select the corresponding source package mysql download source packages.

[niemx@localhost ~]$ uname -a
Linux localhost.localdomain 3.10.0-957.10.1.el7.x86_64 #1 SMP Mon Mar 18 15:06:45 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

Download https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.46.tar.gz

(6)php-5.6.37.tar.bz2

Download https://www.php.net/distributions/php-5.6.37.tar.bz2

** direct download linux source packages may be slower, you can download good in the windows, and then install lrzsz, use SecureCRT transferred to the linux server **

3, compile and install apache

(1) Installation apr

# Tar -xjvf Apr 1.5.2.tar.bz2
# Cd apr-1.5.2
# ./configure --prefix=/usr/local/apr
# make && make install
(2) Installation apr-util
# Tar -xjvf apr-util-1.5.4.tar.bz2
# Cd April-util-1.5.4
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make && make install
(3) Installation pcre
# tar -zxvf pcre-8.43.tar.gz
# cd pcre-8.43
# ./configure --prefix=/usr/local/pcre
# make && make install
(4) create a user group
# groupadd -r apache
# useradd -r -g apache apache
(5) Installation httpd
# tar -zxvf httpd-2.4.41.tar.gz
# cd httpd-2.4.41
# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre=/usr/local/pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=event
---------------------------------------------------------------------------------------------------
The following error:
**checking whether to enable mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures**
Not installed openssl-devel
Solution: yum install openssl-devel
然后重新执行./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre=/usr/local/pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=event
---------------------------------------------------------------------------------------------------
#make && make install
(6) configured and arranged boot apache
# We /etc/httpd/httpd.conf
(1) Search ServerName www.example.com:80 remove the front Notes
(2) to modify DocumentRoot / home / htdocs, and below this line in a <Directory to / home / htdocs this is the root directory is set www
# mkdir -p /home/htdocs 
# cp /usr/local/apache/htdocs/index.html /home/htdocs
# cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
# Vi httpd add the following two lines of text (#! / Bin / sh below) in the first row
# Chkconfig: 2345 90 90 # Note to the front with the # sign
# Description: http server # Note to the front with the # sign
Register for the service
# Chkconfig --add httpd # all boot mode from the start
Under # chkconfig httpd on # 345 boot mode from the start
(7) off the firewall, to verify whether the installation was successful apache
Check firewall status
# systemctl status firewalld.service
Temporarily turn off the firewall
# systemctl stop firewalld.service
Permanently turn off the firewall
# systemctl status firewalld.service
Start apache
# /usr/local/apache/bin/apachectl start
Browser to access the server IP address appears "It works" represents a successful installation apache
Close apache
# /usr/local/apache/bin/apachectl stop
4, compile and install MySQL
(1) Create a user group
# mkdir /usr/local/mysql
# mkdir /home/data
# groupadd -r mysql
# useradd -g mysql -r -s /sbin/nologin -M -d /home/data mysql
# chown -R mysql:mysql /home/data
# chown -R mysql:mysql /usr/local/mysql
(2) Installation
From mysql5.5 onwards, mysql source installation started using cmake, and set the source compiler configuration script
# yum -y install cmake
# yum -y install ncurses-devel
# Tar -xzvf mysql-5.6.46.tar.gz
# cd mysql-5.6.46
# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/home/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
# make && make install
(3) initialize the mysql database
Copy service script start
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
# chmod 700 /etc/init.d/mysqld
Changing environment variables
# echo 'PATH=/usr/local/mysql/bin:$PATH' >>/etc/profile
# source /etc/profile
Modify the configuration file
# vim /etc/my.cnf

[mysqld]
server_id=1
port=3306
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock
log_bin=/usr/local/mysql/mysql-bin
log_error=/var/log/mysql.log
character-set-server=utf8

[client]
socket=/usr/local/mysql/mysql.sock

Forgot your password for the mysql
vi /etc/my.cnf
in the last line added on: skip-grant-tables
to save and exit and restart mysql,
mysql> use mysql;

mysql> UPDATE user SET authentication_string = password ( 'root') WHERE User = 'root'; (no version of the password field) // new password characters in single quotation marks to be set even

mysql> update user set password = password ( 'root') where user = 'root'; (versioned password field)

mysql>quit;

/Etc/my.cnf delete files inside the "skip-grant-tables". The final restart, enter the new password on it.

5, compile and install PHP

(1) resolve dependencies

# yum -y install bzip2-devel libmcrypt-devel libxml2-devel

Installation libmcrypt-devel configure source epel

# rpm -Uvh https://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64/Packages/e/epel-release-7-12.noarch.rpm

# yum clean all

# yum makecache

# yum update

# yum install -y libmcrypt-devel

(2) installed php

# Tar -xjvf php-5.6.37.tar.bz2

# cd php-5.6.37

# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml  --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt  --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2  --enable-maintainer-zts

# make && make install

(3) modify the configuration

# Cp php.ini-production /etc/php.ini

# vim /etc/httpd/httpd.conf

<IfModule unixd_module>

...

User apache
Group apache

...

</IfModule>

<IfModule dir_module>
  DirectoryIndex index.php index.html
</IfModule>

<IfModule mime_module>

...

AddType application/x-httpd-php  .php

...

</IfModule>

Httpd restart

# service httpd restart

------------------------------------------------------------------

**/usr/local/apache/bin/apachectl: line 95: lynx: command not found**

Error solution: # yum install lynx -y

-----------------------------------------------------------------

(4) writing test code

Testing index.php page the following example:
    <?php
      $link = mysql_connect('127.0.0.1','root','root');
      if ($link)
        echo "mysql connected success.";
      else
        echo "mysql connected faild.";
      mysql_close();
      phpinfo();
    ?>

Guess you like

Origin www.cnblogs.com/niemx1030/p/11934398.html