LAMP架构

LAMP架构

  • LAMP简介
    Linux+Apache+Mysql/MariaDB+Perl/PHP/Python一组常用来搭建动态网站或者服务器的开源软件,本身都是各自独立的程序,但是因为常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台。
LAMP架构搭建的过程
环境说明:
系统平台IP需要安装的服务
centos7 redhat7192.168.225.128httpd-2.4 mysql-5.7 php php-mysql

lamp平台软件安装次序:

httpd-->mysql-->php
注意:php要求httpd使用prefork MPM
1.安装httpd
//先安装开发工具包
[root@hxdserver ~]# yum groups  install 'Development Tools'
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
没有安装组信息文件
Maybe run: yum groups mark convert (see man yum)
Marked install: Development Tools

//创建apache服务的用户和组
[root@hxdserver ~]# groupadd -r apache
[root@hxdserver ~]# useradd -r -M -s /sbin/nologin -g apache apache

//安装依赖包
[root@hxdserver ~]# yum -y install openssl-devel pcre-devel expat-devel lib tool

下载和安装apr以及apr-util
[root@hxdserver ~]# cd /usr/src/
[root@hxdserver src]# ls
apr-1.6.3.tar.bz2  apr-util-1.6.1.tar.bz2  debug  kernels
[root@hxdserver src]# tar xf apr-1.6.3.tar.bz2 
[root@hxdserver src]# tar xf apr-util-1.6.1.tar.bz2
[root@hxdserver src]# ls
apr-1.6.3  apr-1.6.3.tar.bz2  apr-util-1.6.1  apr-util-1.6.1.tar.bz2  debug  kernels
[root@hxdserver src]# cd apr-1.6.3/
[root@hxdserver apr-1.6.3]# vim configure
 $RM "$cfgfile"   //将此行加上注释,或者删除
 [root@hxdserver apr-1.6.3]# ./configure --prefix=/usr/local/apr
[root@hxdserver apr-1.6.3]# make && make install
[root@hxdserver apr-util-1.6.1]# cd /usr/src/apr-util-1.6.1/
[root@hxdserver apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@hxdserver apr-util-1.6.1]# make && make install
//编译安装httpd
[root@hxdserver ~]# ls
anaconda-ks.cfg  httpd-2.4.34.tar.bz2
[root@hxdserver httpd-2.4.34]# tar xf httpd-2.4.34.tar.bz2 
[root@hxdserver httpd-2.4.34]# cd httpd-2.4.34/


[root@hxdserver httpd-2.4.34]# ./configure --prefix=/usr/local/apache  --sysconfdir=/etc/httpd24  --enable-so  --enable-ssl  --enable-cgi  --enable-rewrite  --with-zlib  --with-pcre  --with-apr=/usr/local/apr  --with-apr-util=/usr/local/apr-util/  --enable-modules=most  --enable-mpms-shared=all  --with-mpm=prefork
[root@hxdserver httpd-2.4.34]# make && make install
//安装后配置
[root@hxdserver ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@hxdserver ~]# source /etc/profile.d/httpd.sh 
[root@hxdserver ~]# ln -s /usr/local/apache/include/ /usr/include/httpd
[root@hxdserver ~]#  echo 'MANPATH /usr/local/apache/man' >> /etc/man.config
[root@hxdserver ~]# vim /etc/httpd24/httpd.conf
ServerName www.example.com:80
//将此行前的#取消
//启动apache服务
[root@hxdserver ~]# apachectl start
[root@hxdserver ~]# ss -antl
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN     0      128              *:80                           *:*                  
LISTEN     0      128              *:22                           *:*                  
LISTEN     0      100      127.0.0.1:25                           *:*                  
LISTEN     0      128             :::22                          :::*                  
LISTEN     0      100            ::1:25                          :::*   

2.安装mysql
//安装依赖包
[root@hxdserver ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
//创建mysql用户和组
[root@hxdserver ~]# groupadd -r -g 306 mysql
[root@hxdserver ~]# useradd -M -s /sbin/nologin -g 306 -u 306 mysql

//下载二进制格式的mysql软件包
[root@hxdserver local]# ls
apache    bin    include  libexec                                     share
apr       etc    lib      mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz  src
apr-util  games  lib64    sbin

[root@hxdserver local]# tar xf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
[root@hxdserver local]# ln -sv mysql-5.7.23-linux-glibc2.12-x86_64/ mysql
"mysql" -> "mysql-5.7.23-linux-glibc2.12-x86_64/"

//修改目录/usr/local/mysql的属主属组
[root@hxdserver local]# chown -R mysql.mysql /usr/local/mysql
[root@hxdserver local]# ll /usr/local/mysql -d
lrwxrwxrwx. 1 mysql mysql 36 9月  27 10:28 /usr/local/mysql -> mysql-5.7.23-linux-glibc2.12-x86_64/

//添加环境变量
[root@hxdserver local]# cd
[root@hxdserver ~]# ls /usr/local/mysql
bin  COPYING  docs  include  lib  man  README  share  support-files
[root@hxdserver ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@hxdserver ~]# . /etc/profile.d/mysql.sh 
[root@hxdserver ~]# echo $PATH
/usr/local/mysql/bin:/usr/local/apache/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

//建立数据存放目录
[root@hxdserver ~]# mkdir /opt/data
[root@hxdserver ~]# chown -R mysql.mysql /opt/data/
[root@hxdserver ~]# ll /opt/
总用量 0
drwxr-xr-x. 2 mysql mysql 6 9月  27 10:36 data

//初始化数据库
[root@hxdserver ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/
2018-09-27T02:39:26.867282Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-09-27T02:39:27.223297Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-09-27T02:39:27.263353Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-09-27T02:39:27.364033Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 8d70e488-c1fe-11e8-af69-000c294b7cb8.
2018-09-27T02:39:27.365106Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-09-27T02:39:27.370370Z 1 [Note] A temporary password is generated for root@localhost: f8kjCCJnuJ;<   //这里冒号后面的为初始密码妥善保存

//配置mysql
[root@hxdserver ~]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
"/usr/local/include/mysql" -> "/usr/local/mysql/include/"
[root@hxdserver ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@hxdserver ~]# ldconfig -v
[root@hxdserver ~]# ldconfig -p |grep mysql
	libmysqlclient.so.20 (libc6,x86-64) => /usr/local/mysql/lib/libmysqlclient.so.20
	libmysqlclient.so.18 (libc6,x86-64) => /usr/lib64/mysql/libmysqlclient.so.18
	libmysqlclient.so (libc6,x86-64) => /usr/lib64/mysql/libmysqlclient.so
	libmysqlclient.so (libc6,x86-64) => /usr/local/mysql/lib/libmysqlclient.so

//生成配置文件
[root@hxdserver ~]# vim /etc/my.cnf
[root@hxdserver ~]# cat /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/opt/data
socket=/tmp/mysql.sock
port=3306
pid-file=/opt/data/mysql.pid
user=mysql
skip-name-resolve

//配置服务启动脚本
[root@hxdserver ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@hxdserver ~]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /etc/init.d/mysqld 
[root@hxdserver ~]# sed -ri 's#^(datadir=).*#\1/opt/data/#g' /etc/init.d/mysqld 

//启动mysql
[root@hxdserver ~]# service mysqld start 
Starting MySQL.Logging to '/opt/data/hxdserver.err'.
 SUCCESS! 
[root@hxdserver ~]# ps -ef |grep mysql
root      57089      1  0 11:09 pts/1    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/data --pid-file=/opt/data/mysql.pid
mysql     57267  57089  3 11:09 pts/1    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/opt/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=hxdserver.err --pid-file=/opt/data/mysql.pid --socket=/tmp/mysql.sock --port=3306
root      57297  12647  0 11:10 pts/1    00:00:00 grep --color=auto mysql
[root@hxdserver ~]# ss -antl
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN     0      128              *:80                           *:*                  
LISTEN     0      128              *:22                           *:*                  
LISTEN     0      100      127.0.0.1:25                           *:*                  
LISTEN     0      128             :::22                          :::*                  
LISTEN     0      100            ::1:25                          :::*                  
LISTEN     0      80              :::3306                        :::* 
//修改密码
//使用初始密码登录
[root@hxdserver ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.23

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> set password = password('hxd123456.');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> exit
Bye

3.安装php
//配置yum源
[root@hxdserver ~]# cd /etc/yum.repos.d/
[root@hxdserver yum.repos.d]#  wget http://mirrors.163.com/.help/CentOS7-Base-163.repo

[root@hxdserver yum.repos.d]#  sed -i 's/\$releasever/7/g' /etc/yum.repos.d/CentOS7-Base-163.repo 
[root@hxdserver yum.repos.d]#  sed -i 's/^enabled=.*/enabled=1/g' /etc/yum.repos.d/CentOS7-Base-163.repo 
[root@hxdserver yum.repos.d]# yum clean all 

[root@hxdserver yum.repos.d]# vim xx.repo 
//这里将本地源关闭了
[root@hxdserver yum.repos.d]# yum install -y  libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel 

//下载php
[root@hxdserver src]# wget  http://cn.php.net/distributions/php-7.2.8.tar.xz
[root@hxdserver src]# tar xf php-7.2.8.tar.xz
[root@hxdserver src]# cd php-7.2.8/
[root@hxdserver php-7.2.8]# ./configure --prefix=/usr/local/php7 --with-curl  --with-freetype-dir  --with-gd  --with-gettext  --with-iconv-dir  --with-kerberos  --with-libdir=lib64  --with-libxml-dir=/usr  --with-mysqli=/usr/local/mysql/bin/mysql_config  --with-openssl  --with-pcre-regex  --with-pdo-mysql  --with-pdo-sqlite  --with-pear  --with-jpeg-dir  --with-png-dir  --with-xmlrpc  --with-xsl  --with-zlib  --with-config-file-path=/etc  --with-config-file-scan-dir=/etc/php.d  --with-bz2  --enable-fpm  --enable-bcmath  --enable-libxml  --enable-inline-optimization  --enable-mbregex  --enable-mbstring  --enable-opcache  --enable-pcntl  --enable-shmop  --enable-soap  --enable-sockets  --enable-sysvsem --enable-xml  --enable-zip

[root@hxdserver php-7.2.8]#  make 
当配置PHP时出现  make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1 时,是因为服务器内存不足1G。
只需要在配置命令中添加 --disable-fileinfo即可 。
[root@hxdserver php-7.2.8]# make install
//安装后配置
[root@hxdserver ~]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
[root@hxdserver ~]# source /etc/profile.d/php7.sh 
[root@hxdserver ~]# which php 
/usr/local/php7/bin/php
[root@hxdserver ~]# php -v 
PHP 7.2.8 (cli) (built: Sep 27 2018 12:01:24) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

//配置php-fpm
[root@localhost ~]# cp /usr/src/php-7.2.8/php.ini-production /etc/php.ini
[root@hxdserver php-7.2.8]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm 
[root@hxdserver php-7.2.8]# chmod +x /etc/rc.d/init.d/php-fpm 
[root@hxdserver php-7.2.8]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[root@hxdserver php-7.2.8]#  cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf

//编辑php-fpm的配置文件/usr/local/php7/etc/php-fpm.conf 
//配置fpm的相关选项改为所需要的值
[root@hxdserver php-7.2.8]# vim /usr/local/php7/etc/php-fpm.conf
[root@hxdserver php-7.2.8]#  tail /usr/local/php7/etc/php-fpm.conf 
; files from a glob(3) pattern. This directive can be used everywhere in the
; file.
; Relative path can also be used. They will be prefixed by:
;  - the global prefix if it's been set (-p argument)
;  - /usr/local/php7 otherwise
include=/usr/local/php7/etc/php-fpm.d/*.conf
pm.max_children = 50
pm.start_servers = 5 
pm.min_spare_servers = 2 
pm.max_spare_servers = 8

//启动php-fpm
[root@hxdserver php-7.2.8]# service php-fpm start 
Starting php-fpm  done
[root@hxdserver php-7.2.8]#  ss -antl 
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN     0      128              *:80                           *:*                  
LISTEN     0      128              *:22                           *:*                  
LISTEN     0      100      127.0.0.1:25                           *:*                  
LISTEN     0      128      127.0.0.1:9000                         *:*                  
LISTEN     0      128             :::22                          :::*                  
LISTEN     0      100            ::1:25                          :::*                  
LISTEN     0      80              :::3306                        :::*

//fpm默认监听在127.0.0.1的9000端口

4.配置apache,启用代理模块
//启用httpd的相关模块

[root@hxdserver ~]# vim /etc/httpd24/httpd.conf
#LoadModule proxy_module modules/mod_proxy.so
#LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
//编辑httpd.conf文件,找到以上两行内容,将其取消注释

//创建虚拟机目录并生成php测试页面
[root@hxdserver ~]# mkdir /usr/local/apache/htdocs/dubai.com
[root@hxdserver ~]# vim /usr/local/apache/htdocs/dubai.com/index.php 
[root@hxdserver ~]# cat /usr/local/apache/htdocs/dubai.com/index.php 
<?php
phpinfo();
?>
[root@hxdserver ~]# chown -R apache.apache /usr/local/apache/htdocs/
[root@hxdserver ~]# ll /usr/local/apache/htdocs/ -d
drwxr-xr-x. 3 apache apache 41 9月  27 13:29 /usr/local/apache/htdocs/


//修改配置文件httpd.conf
[root@hxdserver ~]# vim /etc/httpd24/httpd.conf
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/dubai.com"
    ServerName www.dubai6666.com
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/dubai.com/$1
    <Directory "/usr/local/apache/htdocs/dubai.com">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost>
//在末尾添加以上内容

[root@hxdserver ~]# vim /etc/httpd24/httpd.conf
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php  //后加
    AddType application/x-httpd-php-source .phps  //后加
//搜索AddType添加如上内容
[root@hxdserver ~]# sed -i '/    DirectoryIndex/s/index.html/index.php index.html/g' /etc/httpd24/httpd.conf
[root@hxdserver ~]# apachectl stop
[root@hxdserver ~]# apachectl start
[root@hxdserver ~]# ss -antl
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN     0      128              *:80                           *:*                  
LISTEN     0      128              *:22                           *:*                  
LISTEN     0      100      127.0.0.1:25                           *:*                  
LISTEN     0      128      127.0.0.1:9000                         *:*                  
LISTEN     0      128             :::22                          :::*                  
LISTEN     0      100            ::1:25                          :::*                  
LISTEN     0      80              :::3306                        :::* 


5.验证

在这里插入图片描述
添加域名与ip的映射

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值