LAMP源码部署

安装Apache

#安装开发工具包
[root@localhost ~]# yum groups mark install 'Development Tools'
#创建apache服务的用户和组
[root@localhost ~]# useradd -r -M -s /sbin/nologin -g apache apache 
#安装依赖包
[root@localhost ~]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++
下载和安装apr以及apr-util
[root@localhost src]# tar -xf apr-1.7.0.tar.bz2 /usr/local/
[root@localhost src]# tar -xf apr-util-1.6.1.tar.bz2 /usr/local/
[root@localhost src]# tar -xf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz /usr/local/
# 开始编译apr
[root@localhost local]# cd apr-1.7.0/
[root@localhost apr-1.7.0]# vim configure
......
cfgfile=${ofile}T
    trap "$RM \"$cfgfile\"; exit 1" 1 2 15
    #$RM "$cfgfile"    # 此行注释掉
......
[root@localhost apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.7.0]# make && make install

# 开始编译apr-util
[root@localhost apr-1.7.0]# cd ../apr-util-1.6.1/
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-arp=/usr/local/apr
[root@localhost apr-util-1.6.1]# make && make install

# 编译httpd
[root@localhost apr-util-1.6.1]# cd ../httpd-2.4.46/
[root@localhost httpd-2.4.46]# ./configure --prefix=/usr/local/httpd \
> --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@localhost httpd-2.4.46]# make && make install

#安装后配置
# 配置httpd服务环境变量
[root@localhost]# echo 'export PATH=/usr/local/httpd/bin:$PATH' > /etc/profile.d/httpd.sh
[root@localhost]# source /etc/profile.d/httpd.sh 
[root@localhost]# ln -s /usr/local/httpd/include/ /usr/include/httpd
# 修改服务器主机名
[root@localhost]# vim /etc/httpd24/httpd.conf
......
# If your host doesn't have a registered DNS name, enter its IP address here.
ServerName localhost:80    # 修改服务名
#启动apache
[root@localhost]# apachectl start
[root@localhost]# ss -antl
State        Recv-Q        Send-Q                  Local Address:Port                 Peer Address:Port        
LISTEN       0             128                           0.0.0.0:22                        0.0.0.0:*           
LISTEN       0             128                                 *:80                              *:*           
LISTEN       0             128                              [::]:22    

安装MySQL

#安装依赖包
[root@server ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel ncurses-compat-libs
#创建用户
[root@server ~]# useradd -r -M -s /sbin/nologin mysql
#解压软件至/usr/local/
[root@localhost soft]# tar xf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@server ~]# cd /usr/local
[root@server local]# ls
apache    games    mysql
apr       include  mysql-5.7.22-linux-glibc2.12-x86_64
apr-util  lib      sbin
bin       lib64    share
etc       libexec  src
[root@localhost local]# ln -sv mysql-5.7.22-linux-glibc2.12-x86_64/ mysql
‘mysql’ -> ‘mysql-5.7.22-linux-glibc2.12-x86_64/’
[root@server local]# ll
total 0
drwxr-xr-x  13 root  root  152 Nov  3 02:07 apache
drwxr-xr-x   6 root  root   58 Nov  3 01:58 apr
drwxr-xr-x   5 root  root   43 Nov  3 02:00 apr-util
drwxr-xr-x.  2 root  root    6 Aug 12  2018 bin
drwxr-xr-x.  2 root  root    6 Aug 12  2018 etc
drwxr-xr-x.  2 root  root    6 Aug 12  2018 games
drwxr-xr-x.  2 root  root    6 Aug 12  2018 include
drwxr-xr-x.  2 root  root    6 Aug 12  2018 lib
drwxr-xr-x.  2 root  root    6 Aug 12  2018 lib64
drwxr-xr-x.  2 root  root    6 Aug 12  2018 libexec
lrwxrwxrwx   1 root  root   36 Nov  3 03:17 mysql -> mysql-5.7.22-linux-glibc2.12-x86_64/
drwxr-xr-x   9 mysql mysql 129 Nov  3 02:36 mysql-5.7.22-linux-glibc2.12-x86_64
drwxr-xr-x.  2 root  root    6 Aug 12  2018 sbin
drwxr-xr-x.  5 root  root   49 Aug 26 19:58 share
drwxr-xr-x.  2 root  root    6 Aug 12  2018 src

[root@server ~]# which mysql
/usr/local/mysql/bin/mysql

#修改目录/usr/local/mysql的属主属组
[root@server ~]# chown -R mysql.mysql /usr/local/mysql
[root@server ~]# ll /usr/local/mysql -d
lrwxrwxrwx 1 mysql mysql 36 Aug 14 16:00 /usr/local/mysql -> mysql-5.7.22-linux-glibc2.12-x86_64/
添加环境变量
[root@server ~]# ls /usr/local/mysql
bin  COPYING  docs  include  lib  man  README  share  support-files
[root@server ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@server ~]# . /etc/profile.d/mysql.sh
[root@server ~]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin


#建立数据存放目录
[root@server ~]# mkdir /opt/data
[root@server ~]# chown -R mysql.mysql /opt/data
#初始化数据库
[root@server ~]# mysqld --initialize-insecure --datadir=/opt/data/ --user=mysql
#配置mysql
[root@server ~]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
'/usr/local/include/mysql' -> '/usr/local/mysql/include/'
[root@server ~]# vim /etc/ld.so.conf.d/mysql.conf 
[root@server ~]# ldconfig
配置服务启动脚本
[root@server ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@server ~]# vim /etc/init.d/mysqld 
basedir=/usr/local/mysql    #此行原为空
datadir=/opt/data  			#此行原为空


#生成配置文件
[root@server ~]# vim /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
EOF
#启动mysql并修改密码后登录
[root@server ~]# service mysqld start
Starting MySQL.Logging to '/opt/data/server.err'.
.... SUCCESS! 
[root@server ~]# ss -antl
State  Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0      5            0.0.0.0:873       0.0.0.0:*   
LISTEN 0      128          0.0.0.0:22        0.0.0.0:*   
LISTEN 0      5               [::]:873          [::]:*   
LISTEN 0      80                 *:3306            *:*   
LISTEN 0      128             [::]:22           [::]:*   

[root@server ~]# mysql -uroot -p123456;
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.22 MySQL Community Server (GPL)

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> quit
Bye




配置PHP

#安装关联依赖包
[root@localhost]yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel  pcre-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel php-mysqlnd.x86_64
.....
#编译安装php
[root@localhost src]# tar -xf php-7.2.8.tar.xz -C /usr/local/
[root@localhost src]# cd /usr/local
[root@localhost local]# ls
bin  etc  games  include  lib  lib64  libexec  php-7.2.8  sbin  share  src
[root@localhost local]# cd php-7.2.8/
[root@localhost php-7.2.8]#
./configure --prefix=/usr/local/php \
--with-config-file-path=/etc --enable-fpm --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-soap --with-openssl --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --enable-exif  --enable-ftp --with-gd --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --with-gettext --enable-json --enable-mbstring --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-readline --enable-shmop --enable-simplexml --enable-sockets --enable-zip --enable-mysqlnd-compression-support --with-pear --enable-pcntl --enable-posix
......
[root@localhost]# make && make install
#安装后的配置
[root@localhost]# echo 'export PATH=$PATH:/usr/local/php/bin' > /etc/profile.d/php.sh[root@192 php-7.2.8]# source /etc/profile.d/php.sh 
[root@localhost]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/php/bin
#配置php-fpm
[root@localhost php-7.2.8]# cp php.ini-production /etc/php.ini 
cp: overwrite '/etc/php.ini'? yes
[root@localhost php-7.2.8]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-7.2.8]# chmod +x /etc/rc.d/init.d/php-fpm 
[root@localhost php-7.2.8]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@localhost ~]vim /usr/local/php/etc/php-fpm.conf
......
pm.max_children = 50   # 最多同时提供50个进程提供50个并发服务
pm.start_servers = 5 # 启动时启动5个进程
pm.min_spare_servers = 2  # 最小空闲进程数
pm.max_spare_servers = 8  # 最大空闲进程数
#启动
[root@localhost ~]# service php-fpm start
Starting php-fpm  done
[root@localhost ~]# ss -antl
State     Recv-Q     Send-Q           Local Address:Port           Peer Address:Port     
LISTEN    0          128                    0.0.0.0:22                  0.0.0.0:*        
LISTEN    0          128                  127.0.0.1:9000                0.0.0.0:*        
LISTEN    0          128                       [::]:22                     [::]:*

配置apache

#装特殊依赖包
[root@localhost ~]# yum list all|grep mysql|grep php
php-mysqlnd.x86_64                                   7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream    
[root@localhost ~]# yum -y install php-mysqldnd

#编辑httpd.conf文件,取消以下两行内容的注释:
[root@localhost ~]# vim /etc/httpd24/httpd.conf 
LoadModule proxy_module modules/mod_proxy.so   
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
# php服务器上将欲执行的Php文件编辑好保存
[root@localhost ~]# mkdir -p /www/html/
[root@localhost ~]# touch test.php
[root@localhost ~]# vim test.php
<?php
   phpinfo();
?>

# http服务器上编辑虚拟主机文件
[root@localhost ~]# vim /etc/httpd24/extra/httpd-vhosts.conf 
<VirtualHost *:80>
    DocumentRoot "/www/html"
    ServerName test.example.com
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.152.134:9000/www/html/$1
</VirtualHost>


# 搜索AddType,添加以下内容
[root@localhost ~]# 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        #添加此行
修改php服务的监听ip
[root@localhost ~]# vim www.conf
......
;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = 0.0.0.0:9000    # 将默认的主机ip改成0.0.0.0
......
# 重启服务
[root@localhost ~]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm  done
[root@localhost ~]# ss -antl
State     Recv-Q     Send-Q           Local Address:Port           Peer Address:Port     
LISTEN    0          128                    0.0.0.0:22                  0.0.0.0:*        
LISTEN    0          128                    0.0.0.0:9000                0.0.0.0:*        
LISTEN    0          128                       [::]:22                     [::]

验证:
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值