LAMP编译安装

编译安装LAMP

1.环境准备

##系统版本
[root@lamp ~]# cat /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core)
##软件版本
httpd-2.4.43.tar.gz
apr-1.7.0.tar.bz2
apr-util-1.6.1.tar.bz2
mariadb-10.2.23.tar.gz
php-7.3.10.tar.xz

2.安装httpd依赖包与环境准备

[root@lamp ~]# yum install gcc pcre-devel openssl-devel expat-devel bzip2 -y
[root@lamp ~]# useradd -r -s /sbin/nologin apache
[root@lamp ~]# tar xvf apr-1.7.0.tar.bz2 
[root@lamp ~]# tar xvf apr-util-1.6.1.tar.bz2 
[root@lamp ~]# tar xf httpd-2.4.43.tar.gz
[root@lamp ~]# mv apr-1.7.0 httpd-2.4.43/srclib/apr
[root@lamp ~]# mv apr-util-1.6.1 httpd-2.4.43/srclib/apr-util

3.编译安装httpd

[root@lamp ~]# cd httpd-2.4.43
[root@lamp httpd-2.4.43]# ./configure --prefix=/app/httpd24 \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork \
--with-included-apr
[root@lamp httpd-2.4.43]# make -j 4 && make install

4.配置PATH环境变量和httpd.conf

[root@lamp httpd-2.4.43]# echo "PATH=$PATH:/app/httpd24/bin/" > /etc/profile.d/lamp.sh
[root@lamp httpd-2.4.43]# . /etc/profile.d/lamp.sh 
[root@lamp httpd-2.4.43]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/app/httpd24/bin
[root@lamp httpd-2.4.43]# vim /app/httpd24/conf/httpd.conf 
##修改下面三行
user apache
group apache
ServerName localhost:80
[root@lamp ~]# apachectl -t
Syntax OK

5.启动apache并验证测试

[root@lamp httpd-2.4.43]# apachectl start
[root@lamp httpd-2.4.43]# ps -ef |grep apache
apache    34440  34439  0 14:47 ?        00:00:00 /apps/httpd24/bin/httpd -k start
apache    34441  34439  0 14:47 ?        00:00:00 /apps/httpd24/bin/httpd -k start
apache    34442  34439  0 14:47 ?        00:00:00 /apps/httpd24/bin/httpd -k start
apache    34443  34439  0 14:47 ?        00:00:00 /apps/httpd24/bin/httpd -k start
apache    34444  34439  0 14:47 ?        00:00:00 /apps/httpd24/bin/httpd -k start
root      34446   1175  0 14:48 pts/0    00:00:00 grep --color=auto apache
[root@lamp httpd-2.4.43]# curl 10.0.0.7
<html><body><h1>It works!</h1></body></html>

6.安装mariadb依赖包

[root@lamp ~]# yum -y install bison bison-devel libcurl-devel libarch ive-devel boost-devel gcc-c++ cmake ncurses-devel gnutls-devel libxml2-devel libevent-devel libaio-devel

7.准备mysql用户和数据存放目录

[root@lamp ~]# useradd -r -s /sbin/nologin -d /data/mysql mysql
[root@lamp ~]# mkdir /data/mysql
[root@lamp ~]# chown mysql.mysql /data/mysql/

8.编译安装mariadb

[root@lamp ~]# tar xvf mariadb-10.2.23.tar.gz 
[root@lamp ~]# cd mariadb-10.2.23
[root@lamp mariadb-10.2.23]# cmake . \
-DCMAKE_INSTALL_PREFIX=/app/mysql \
-DMYSQL_DATADIR=/data/mysql/ \
-DSYSCONFDIR=/etc/mysql \
-DMYSQL_USER=mysql \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITHOUT_MROONGA_STORAGE_ENGINE=1 \
-DWITH_DEBUG=0 \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
[root@lamp mariadb-10.2.23]# make -j 4 && make install

9.设置mariadb环境变量

[root@lamp mariadb-10.2.23]# . /etc/profile.d/lamp.sh 
PATH=$PATH:/app/mysql/bin
[root@lamp mariadb-10.2.23]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/app/httpd24/bin:/app/mysql/bin

10.准备配置文件和生成数据库初始化文件

[root@lamp mariadb-10.2.23]# cd /app/mysql/
[root@lamp mysql]# ./scripts/mysql_install_db --datadir=/data/mysql --user=mysql
[root@lamp mysql]# cp /app/mysql/support-files/my-huge.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? y

11.准备启动脚本并启动验证

[root@lamp mysql]# cp /app/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@lamp mysql]# service mysqld start
Starting mysqld (via systemctl):                           [  OK  ]
[root@lamp mysql]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.2.23-MariaDB-log Source distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> 

12.安装php的依赖包

[root@lamp ~]# yum install libxml2-devel bzip2-devel libmcrypt-devel -y

13.解压php源码包,并进行编译安装

[root@lamp ~]# tar xf php-7.3.10.tar.xz 
[root@lamp php-7.3.10]# ./configure --prefix=/app/php \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-openssl \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--enable-mbstring \
--enable-xml \
--enable-sockets \
--enable-fpm \
--enable-maintainer-zts \
--disable-fileinfo
[root@lamp php-7.3.10]# make -j 4 && make install

14.准备php的配置文件

[root@lamp php-7.3.10]#  cd /app/php/etc/php-fpm.d/
[root@lamp php-fpm.d]# mv www.conf.default www.conf
[root@lamp php-fpm.d]# cp /root/php-7.3.10/php.ini-production /etc/php.ini
[root@lamp php-fpm.d]# cd ..
[root@lamp etc]# cp php-fpm.conf.default php-fpm.conf

15.创建php的运行账号并启动php-fpm

[root@lamp etc]# useradd -r -s /sbin/nologin www
[root@lamp etc]# echo "PATH=$PATH:/app/php/sbin/" > /etc/profile.d/lamp.sh 
[root@lamp etc]# . /etc/profile.d/lamp.sh 
[root@lamp etc]# php-fpm -t
[18-Aug-2021 16:52:02] NOTICE: configuration file /apps/php/etc/php-fpm.conf test is successful

[root@lamp etc]# php-fpm -c php.ini 
[root@lamp etc]# ps -ef |grep php-fpm
root      66298      1  0 16:52 ?        00:00:00 php-fpm: master process (/apps/php/etc/php-fpm.conf)
www       66299  66298  0 16:52 ?        00:00:00 php-fpm: pool www
www       66300  66298  0 16:52 ?        00:00:00 php-fpm: pool www
root      66302   1175  0 16:53 pts/0    00:00:00 grep --color=auto php-fpm

16.编辑apache配置文件支持php和php测试页面

[root@lamp ~]# vim /apps/httpd24/htdocs/index.php
<?php
phpinfo();
?>

[root@lamp ~]# vim /apps/httpd24/conf/httpd.conf
##取消下面两行的注释
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
##下面加二行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/app/httpd24/htdocs/$1
##定位至DirectoryIndex index.html, 修改为
DirectoryIndex index.php index.html

posted @ 2021-08-20 10:12  人生值得  阅读(35)  评论(0编辑  收藏  举报