lamp平台构建

安装httpd

  1. yum配置
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
  1. 下载epel源
[root@localhost ~]#yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
[root@localhost ~]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@localhost ~]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
  1. 开始配置
1.下载apr   apr-util   httpd
wget https://downloads.apache.org/httpd/httpd- 2.4.54.tar.bz2
wget https://downloads.apache.org/apr/apr-util-1.6.1.tar.bz2
wget https://downloads.apache.org/apr/apr-1.6.5.tar.bz2

4. 安装开发工具包
dnf groups mark install -y "Development Tools"

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

6. 安装依赖包
yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++

7. 解压并配置
[root@localhost src]# tar xf apr-1.6.5.tar.gz
[root@localhost src]# cd apr-1.6.5
[root@localhost apr-1.6.5]# vim configure
    # $RM "$cfgfile"        //将此行加上注释,或者删除此行
[root@localhost apr-1.6.5]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.6.5]# make && make install

[root@localhost apr-1.6.5]# cd /usr/src/apr-util-1.6.1
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@localhost apr-util-1.6.1]# make && make install

//编译安装httpd
[root@localhost src]# tar xf httpd-2.4.54.tar.bz2 
[root@localhost src]# cd httpd-2.4.54
[root@localhost httpd-2.4.54]# ./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@localhost httpd-2.4.54]#make && make install

//安装后配置
[root@localhost local]# cd apache
[root@localhost apache]# ls
bin  build  cgi-bin  error  htdocs  icons  include  logs  man  manual  modules
[root@localhost apache]#  echo 'export PATH=$PATH:/usr/local/apache/bin' > /etc/pro
profile    profile.d/ protocols  
[root@localhost apache]#  echo 'export PATH=$PATH:/usr/local/apache/bin' > /etc/profile.d/httpd.sh 
[root@localhost apache]# source /etc/profile.d/httpd.sh 
[root@localhost apache]#  ln -s /usr/local/apache/include/ /usr/include/httpd
[root@localhost apache]# vim /etc/man_db.conf
MANDATORY_MANPATH			/usr/local/apache/man          //添加这一行
[root@localhost ~]# httpd -t
Syntax OK

//更换启动方式
[root@localhost ~]# cd /usr/lib/systemd/system/
[root@localhost system]# cp sshd.service httpd.service 
[root@localhost system]# vim httpd.service  
[Unit]
Description=httpd server daemon
After=network.target sshd-keygen.target

[Service]
Type=forking
ExecStart=/usr/local/apache/bin/apachectl start
ExecStop=/usr/local/apache/bin/apachectl stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
//启动httpd
[root@localhost system]# systemctl daemon-reload
[root@localhost system]# systemctl status httpd
● httpd.service - httpd server daemon
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
[root@localhost system]# systemctl start httpd
[root@localhost system]# ss -antl
State      Recv-Q     Send-Q         Local Address:Port         Peer Address:Port    Process    
LISTEN     0          128                  0.0.0.0:22                0.0.0.0:*                  
LISTEN     0          128                        *:80                      *:*                  
LISTEN     0          128                     [::]:22                   [::]:*     

//加入开机自启
[root@localhost system]# systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

mysql

//安装依赖包
[root@localhost ~]# yum -y install ncurses-devel openssl-devel openssl cmake

//创建用户和组
[root@localhost src]# groupadd -r -g 306 mysql
[root@localhost src]# useradd -r -M -s /sbin/nologin -g 306 -u 306 mysql

//下载二进制格式的mysql软件包
这里用的是压缩包
[root@localhost src]# tar xf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz  -C /usr/local/

//修改目录/usr/local/mysql的属主属组
[root@localhost local]# ll
lrwxrwxrwx.  1 mysql mysql  35 8月   2 14:21 mysql -> mysql-5.7.37-linux-glibc2.12-x86_64
drwxr-xr-x.  9 mysql mysql 129 8月   2 14:12 mysql-5.7.37-linux-glibc2.12-x86_64


//添加环境变量
[root@localhost mysql]# cd bin
[root@localhost bin]# echo 'export PATH=$PATH:/usr/local/mysql/bin' > /etc/profile.d/mysql.sh
[root@localhost bin]# source /etc/profile.d/mysql.sh 
[root@localhost bin]# which mysql
/usr/local/mysql/bin/mysql
[root@localhost bin]# cd ..
[root@localhost mysql]# ln -s /usr/local/mysql/include/   /usr/include/mysql
[root@localhost mysql]# echo '/usr/local/mysql/lib/' > /etc/ld.so.conf.d/mysql.conf
[root@localhost mysql]# ldconfig
[root@localhost mysql]# vim /etc/man_db.conf 
MANDATORY_MANPATH			/usr/local/mysql/man    //在配置文件里添加这一行

//建立数据存放目录
[root@localhost ~]# mkdir /opt/data
[root@localhost ~]# chown -R mysql.mysql /opt/data/

//初始化数据库
[root@localhost ~]# mysqld --initialize --user mysql --datadir /opt/data/
2022-08-02T11:38:00.714173Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-08-02T11:38:01.284508Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-08-02T11:38:01.382400Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-08-02T11:38:01.450268Z 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: 9085e5d9-1257-11ed-90ba-000c296824b7.
2022-08-02T11:38:01.452665Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-08-02T11:38:02.686390Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-08-02T11:38:02.686478Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-08-02T11:38:02.688381Z 0 [Warning] CA certificate ca.pem is self signed.
2022-08-02T11:38:03.481315Z 1 [Note] A temporary password is generated for root@localhost: Ng&yidLBD4s.

//配置服务器启动脚本
[root@localhost support-files]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost support-files]# vim /etc/init.d/mysqld          //在此配置文件更改以下内容
basedir=/usr/local/mysql/
datadir=/opt/data/
[root@localhost system]# cp sshd.service mysqld.service
[root@localhost system]# vim mysqld.service 
[Unit]
Description=OpenSSH server daemon
Documentation=man:sshd(8) man:sshd_config(5)
After=network.target sshd-keygen.target
Wants=sshd-keygen.target

[Service]
Type=forking
ExecStart=/etc/init.d/mysqld start
ExecStop=/etc/init.d/mysqld stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target

//启动mysql
[root@localhost system]# systemctl start mysqld
[root@localhost system]# systemctl enable  mysqld
[root@localhost system]# ss -antl
State      Recv-Q     Send-Q         Local Address:Port         Peer Address:Port    Process    
LISTEN     0          128                  0.0.0.0:22                0.0.0.0:*                  
LISTEN     0          80                         *:3306                    *:*                  
LISTEN     0          128                        *:80                      *:*                  
LISTEN     0          128                     [::]:22                   [::]:*       


//修改密码
[root@localhost ~]# mysql -uroot -p'Ng&yidLBD4s.'
mysql> set password = password('123');
Query OK, 0 rows affected, 1 warning (0.00 sec)

安装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  --skip-broken

//下载php
wget https://www.php.net/distributions/php-7.4.30.tar.xz

//解压编译php
tar xf php-7.4.30.tar.xz
[root@localhost php-7.4.30]# ./configure --prefix=/usr/local/php7  --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 --enable-gd --with-jpeg --with-zlib-dir --with-freetype --with-gettext --enable-json --enable-mbstring --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-readline --enable-shmop --enable-simplexml --enable-sockets --with-zip --enable-mysqlnd-compression-support --with-pear --enable-pcntl --enable-posix

//环境变量
[root@localhost php7]# echo 'export PATH=$PATH:/usr/local/php7/bin' > /etc/profile.d/php7.sh 
[root@localhost php7]# source /etc/profile.d/php7.sh 
[root@localhost php7]# ln -s /usr/local/php7/include/ /usr/include/php7
[root@localhost php7]# echo '/usr/local/php7/lib/' > /etc/ld.so.conf.d/php7.conf
[root@localhost php7]# ldconfig

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

//配置启动
[root@localhost php-7.4.30]# cd /usr/lib/systemd/system
[root@localhost system]# cp sshd.service php-fpm.service
[root@localhost system]# vim php-fpm.service 
[root@localhost system]# cat php-fpm.service 
[Unit]
Description=php-fpm server daemon
After=network.target sshd-keygen.target

[Service]
Type=forking
ExecStart=/etc/init.d/php-fpm start
ExecStop=/etc/init.d/php-fpm stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
[root@localhost system]# systemctl start php-fpm
[root@localhost system]# systemctl enable  php-fpm
[root@localhost system]# ss -antl
State      Recv-Q     Send-Q         Local Address:Port         Peer Address:Port    Process    
LISTEN     0          128                127.0.0.1:9000              0.0.0.0:*                  
LISTEN     0          128                  0.0.0.0:22                0.0.0.0:*                  
LISTEN     0          80                         *:3306                    *:*                  
LISTEN     0          128                        *:80                      *:*                  
LISTEN     0          128                     [::]:22                   [::]:*    

配置apache

//进入vim /etc/httpd24/httpd.conf 找到这两行去掉他们前面的#号
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

配置虚拟主机

//创建虚拟主机目录并生成php测试页面
[root@localhost ~]# cd /usr/local/apache/
[root@localhost apache]# ls
bin  build  cgi-bin  error  htdocs  icons  include  logs  man  manual  modules
[root@localhost apache]# cd htdocs/
[root@localhost htdocs]# vim index.php
<?php
   phpinfo();
?>
[root@localhost htdocs]# chown -R apache.apache /usr/local/apache/
[root@localhost htdocs]# vim /etc/httpd24/httpd.conf                      
# Virtual hosts                                               
Include /etc/httpd24/extra/httpd-vhosts.conf                        //找到这个位置去掉前面的#号

//在配置文件的最后加入以下内容
[root@localhost ~]# vim /etc/httpd24/httpd.conf
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/runtime"
    ServerName runtime.example.com
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/runtime/$1
    <Directory "/usr/local/apache/htdocs/runtime">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost>
[root@localhost htdocs]# mkdir runtime
[root@localhost htdocs]# mv index.php runtime/
[root@localhost htdocs]# chown -R apache.apache runtime

//搜索AddType,添加以下内容
[root@localhost ~]# vim /etc/httpd24/httpd.conf
# If the AddEncoding directives above are commented-out, then you
    # probably should define those extensions to indicate media types:
    #
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php        #添加此行
    AddType application/x-httpd-php-source .phps           #添加此行

<IfModule dir_module>
    DirectoryIndex    index.php   index.html             //在此处添加一个index.dex
</IfModule>
[root@localhost ~]# systemctl restart httpd
[root@localhost system]# ss -antl
State      Recv-Q     Send-Q         Local Address:Port         Peer Address:Port    Process    
LISTEN     0          128                127.0.0.1:9000              0.0.0.0:*                  
LISTEN     0          128                  0.0.0.0:22                0.0.0.0:*                  
LISTEN     0          80                         *:3306                    *:*                  
LISTEN     0          128                        *:80                      *:*                  
LISTEN     0          128                     [::]:22                   [::]:*    

//关闭防火墙
[root@localhost system]# systemctl stop firewalld
[root@localhost system]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost system]# vim /etc/selinux/config 
[root@localhost system]# setenforce 0
更改域名

在这里插入图片描述

在hosts最后一行写入
192.168.253.140 runtime.example.com

验证

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值