Details of the service setup process of LAMP architecture system

  • 2020-05-24 06:42:15
  • OfStack

LAMP architecture is widely used in enterprises. At present, many e-commerce companies, game companies and mobile Internet companies mostly adopt this architecture. LAMP means Linux, Apache, MySQL, PHP. The following documents the setup of the LAMP architecture system services.

1. MySQL database installation

1. System environment

CentOS 6.4 esen 86_64 Mini version installed

2. Basic software package installation


[root@vip ~]# yum install gcc vim make wget -y

3. Download


#  Enter the source directory 
[root@vip ~]# cd /usr/local/src
#  download MySQL The installation package 
[root@vip src]# wget downloads.mysql.com/archives/get/file/mysql-5.5.40-linux2.6-x86_64.tar.gz

4. Unzip the installation


#  Unpack the 
[root@vip src]# tar -zxf mysql-5.5.40-linux2.6-x86_64.tar.gz
#  Set the installation path 
[root@vip src]# mv mysql-5.5.40-linux2.6-x86_64 /usr/local/mysql

5. Set up MySQL users


[root@vip src]# useradd -s /sbin/nologin -M mysql

6. Prepare the data catalog


#  Enter the MySQL The installation directory 
[root@vip src]# cd /usr/local/mysql
#  create MySQL The data directory 
[root@vip mysql]# mkdir -p /var/lib/mysql
#  Set directory permissions 
[root@vip mysql]# chown -R mysql:mysql /var/lib/mysql

7. Initialize the database


[root@vip mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/var/lib/mysql
when specifying MySQL privileges !
Installing MySQL system tables...
OK
Filling help tables...
OK # see 2 a OK Indicates successful initialization 

8. Copy the configuration file


[root@vip mysql]# /bin/cp support-files/my-large.cnf /etc/my.cnf

9. Copy the startup script


#  Copy startup script 
[root@vip mysql]# /bin/cp support-files/mysql.server /etc/init.d/mysqld
#  Grant executable permissions 
[root@vip mysql]# chmod 755 /etc/init.d/mysqld

Modify the startup script


[root@vip mysql]# vim /etc/init.d/mysqld
#  Change the Settings as follows 
basedir=/usr/local/mysql
datadir=/var/lib/mysql

11. Add MySQL to the service


#  Added to the service The list of 
[root@vip mysql]# chkconfig --add mysqld
#  Set to boot 
[root@vip mysql]# chkconfig mysqld on

12. Start the MySQL service


#  Enter the source directory 
[root@vip ~]# cd /usr/local/src
#  download MySQL The installation package 
[root@vip src]# wget downloads.mysql.com/archives/get/file/mysql-5.5.40-linux2.6-x86_64.tar.gz
0

13. View to verify that MySQL started the process


[root@vip mysql]# ps -e | grep mysql
 1830 pts/1  00:00:00 mysqld_safe
 2121 pts/1  00:00:00 mysqld

14. Configure the MySQL environment variable

Add the MySQL client command path to the PATH environment variable.


#  Set up the PATH The environment variable 
[root@vip mysql]# echo 'export PATH=$PATH:/usr/local/mysql/bin' > /etc/profile.d/mysql.sh
[root@vip mysql]# source /etc/profile.d/mysql.sh

15. Log on to MySQL test


#  Enter the source directory 
[root@vip ~]# cd /usr/local/src
#  download MySQL The installation package 
[root@vip src]# wget downloads.mysql.com/archives/get/file/mysql-5.5.40-linux2.6-x86_64.tar.gz
3

2. Apache service installation

apache can be installed by way of yum, also can be installed by way of source code compilation, where the source code compilation method for installation.

1. System environment

CentOS 6.4 x86_64 Mini version installed

2. Download the unzip apache installation package


#  Enter the source directory 
[root@vip ~]# cd /usr/local/src
#  download MySQL The installation package 
[root@vip src]# wget downloads.mysql.com/archives/get/file/mysql-5.5.40-linux2.6-x86_64.tar.gz
4

3. Install the necessary libraries and tools


#  Enter the source directory 
[root@vip ~]# cd /usr/local/src
#  download MySQL The installation package 
[root@vip src]# wget downloads.mysql.com/archives/get/file/mysql-5.5.40-linux2.6-x86_64.tar.gz
5

4. Configure the compilation parameters


#  Enter the source directory 
[root@vip ~]# cd /usr/local/src
#  download MySQL The installation package 
[root@vip src]# wget downloads.mysql.com/archives/get/file/mysql-5.5.40-linux2.6-x86_64.tar.gz
6

5. Compile and install


[root@vip httpd-2.2.31]# make && make install
[root@vip httpd-2.2.31]# echo $?

6. Configure the apache environment variable


[root@vip httpd-2.2.31]# echo 'export PATH=$PATH:/usr/local/apache2/bin' > /etc/profile.d/http.sh
[root@vip httpd-2.2.31]# source /etc/profile.d/http.sh

7. Start and stop of apache


#  Enter the source directory 
[root@vip ~]# cd /usr/local/src
#  download MySQL The installation package 
[root@vip src]# wget downloads.mysql.com/archives/get/file/mysql-5.5.40-linux2.6-x86_64.tar.gz
9

8. Add apache to the system service


#  Copy service script 
[root@vip httpd-2.2.31]# cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd
[root@vip httpd-2.2.31]# vim /etc/init.d/httpd  #  The first 1 Add below the line 2 line 
#!/bin/sh
# chkconfig: 2345 61 61
# description: Apache
#  Add to system services   And set the boot to start 
[root@vip httpd-2.2.31]# chkconfig --add httpd
[root@vip httpd-2.2.31]# chkconfig httpd on

9. Verify whether the service is normal


[root@vip httpd-2.2.31]# service httpd start
httpd: apr_sockaddr_info_get() failed for vip  #  Warning message appears 
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

Solution to the warning message: remove ServerName www. example. com: # 80 lines of comments.

3. Installation of PHP system

1. Download the unzip installer


[root@vip ~]# cd /usr/local/src
[root@vip src]# wget http://cn2.php.net/get/php-5.5.38.tar.gz/from/this/mirror -O php-5.5.38.tar.gz
[root@vip src]# tar zxf php-5.5.38.tar.gz

Download dependent libraries and tools


[root@vip src]# yum install -y epel-release
[root@vip src]# yum install -y libxml2-devel openssl openssl-devel bzip2 bzip2-devel \
libjpeg-devel libpng libpng-devel freetype freetype-devel libmcrypt-devel

3. Compile, configure and install options


[root@vip php-5.5.38]# cd php-5.5.38
[root@vip php-5.5.38]# ./configure \
--prefix=/usr/local/php \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-config-file-path=/usr/local/php/etc \
--with-mysql=/usr/local/mysql \
--with-libxml-dir \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-iconv-dir \
--with-zlib-dir \
--with-bz2 \
--with-openssl \
--with-mcrypt \
--enable-soap \
--enable-gd-native-ttf \
--enable-mbstring \
--enable-sockets \
--enable-exif \
--disable-ipv6

4. Compile and install


[root@vip php-5.5.38]# make && make install
[root@vip php-5.5.38]# echo $?

5. Copy the php configuration file


[root@vip php-5.5.38]# cp php.ini-production /usr/local/php/etc/php.ini

6. Configure the php environment variable


[root@vip php-5.5.38]# echo 'export PATH=$PATH:/usr/local/php/bin' > /etc/profile.d/php.sh
[root@vip php-5.5.38]# source /etc/profile.d/php.sh

At this point, php has completed the basic build and installation, and php will have to be configured separately for subsequent parsing.

4. Configuration supports php parsing

1. Modify the apache configuration file


<Directory />
  Options FollowSymLinks
  AllowOverride None
  Order deny,allow
  Allow from all  # Deny Modified to Allow
</Directory>

2. Support php script parsing


AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php  #  Add this 1 line 

3. Add php index support


<IfModule dir_module>
  DirectoryIndex index.html index.htm index.php  #  add php The index 
</IfModule>

4. Test the configuration syntax and restart the apache service


[root@vip ~]# apachectl -t
Syntax OK
[root@vip ~]# service httpd restart

5. Test php parsing

Write a test file: / / usr local apache2 / htdocs/index php


<?php
  echo "hello php!"
?>

Command line curl test:


[root@vip htdocs]# curl localhost/index.php
hello php![root@vip htdocs]#

php resolved successfully!


Related articles: