当前位置:首页 > 行业动态 > 正文

如何从源码在CentOS上安装LAMP堆栈?

CentOS源码LAMP是指在CentOS操作系统上安装和配置LAMP(Linux、Apache、MySQL、PHP)的过程。

要在 CentOS 上安装 LAMP(Linux, Apache, MySQL, PHP)源码,你需要按照以下步骤操作:

如何从源码在CentOS上安装LAMP堆栈?  第1张

1、更新系统并安装必要的依赖包:

sudo yum update y
sudo yum install y gcc make autoconf libtool pkgconfig gccc++ openssldevel pcredevel zlibdevel

2、安装 Apache:

下载 Apache 源码
wget https://archive.apache.org/dist/httpd/httpd2.4.53.tar.gz
tar zxvf httpd2.4.53.tar.gz
cd httpd2.4.53
配置并编译安装
./configure prefix=/usr/local/apache2 enableso enablerewrite withmpm=prefork withincludedapr withincludedaprutil
make && sudo make install

3、安装 MySQL:

下载 MySQL 源码
wget https://dev.mysql.com/get/Downloads/MySQL8.0/mysql8.0.26.tar.gz
tar zxvf mysql8.0.26.tar.gz
cd mysql8.0.26
配置并编译安装
cmake . DCMAKE_INSTALL_PREFIX=/usr/local/mysql n    DMYSQL_DATADIR=/usr/local/mysql/data n    DSYSCONFDIR=/etc n    DWITH_INNOBASE_STORAGE_ENGINE=1 n    DWITH_ARCHIVE_STORAGE_ENGINE=1 n    DWITH_BLACKHOLE_STORAGE_ENGINE=1 n    DWITH_READLINE=1 n    DWITH_SSL=system n    DWITH_ZLIB=system n    DWITH_LIBWRAP=0 n    DMYSQL_UNIX_ADDR=/tmp/mysql.sock n    DDEFAULT_CHARSET=utf8mb4 n    DDEFAULT_COLLATION=utf8mb4_general_ci n    DWITH_EXTRA_CHARSETS=all n    DWITH_DEBUG=0
make && sudo make install

4、安装 PHP:

下载 PHP 源码
wget https://www.php.net/distributions/php7.4.19.tar.gz
tar zxvf php7.4.19.tar.gz
cd php7.4.19
配置并编译安装
./configure prefix=/usr/local/php withapxs2=/usr/local/apache2/bin/apxs withconfigfilepath=/usr/local/php withmysqli=mysqlnd withpdomysql=mysqlnd withopenssl withzlib enablezip enableinlineoptimization disablefileinfo enablembstring enablecalendar withcurl withgd enablegd withjpeg withpng enablesockets enablesysvsem enablesysvshm enablemaintainerzts withxmlrpc enablesoap withoutpear withgettext enablebcmath enableintl withmcrypt withmhash enableopcache enablepcntl enableftp enableexif enablewddx withtidy withxsl enablezip enablembstring withbz2 withreadline enablecli enablefpm withfpmuser=apache withfpmgroup=apache withlibdir=lib64 withcurl withlibedit enabledom enablexml enablesimplexml enabletokenizer enablexmlwriter enableshmop enablejson enablesession enablefilter enableobjectallocations enablesharedmemory enablepcntl enableposix enabledebug
make && sudo make install

5、配置环境变量:

echo 'export PATH=$PATH:/usr/local/php/bin' >> ~/.bashrc
source ~/.bashrc

6、启动 Apache 和 PHPFPM:

sudo /usr/local/apache2/bin/apachectl start
sudo /usr/local/php/sbin/phpfpm

至此,你已经在 CentOS 上安装了 LAMP 源码,你可以创建一个简单的 PHP 文件来测试是否安装成功:

echo "<?php phpinfo(); ?>" > /usr/local/apache2/htdocs/info.php

然后在浏览器中访问http://localhost/info.php,如果看到 PHP 信息页面,说明 LAMP 安装成功。

各位小伙伴们,我刚刚为大家分享了有关“centos 源码 lamp”的知识,希望对你们有所帮助。如果您还有其他相关问题需要解决,欢迎随时提出哦!

0