简体中文简体中文
EnglishEnglish
简体中文简体中文

CentOS源码编译LAMP环境详解

2025-01-20 08:40:46

随着互联网技术的不断发展,Linux操作系统因其稳定、安全、开源等特性,成为了服务器端部署的首选。CentOS作为一款基于Red Hat Enterprise Linux的免费、开源操作系统,因其良好的兼容性和稳定性,受到了广大用户的喜爱。本文将详细介绍如何在CentOS系统中编译源码安装LAMP(Linux、Apache、MySQL、PHP)环境。

一、LAMP环境简介

LAMP环境是指Linux操作系统下安装Apache、MySQL、PHP这三个软件的组合。它是一种流行的Web服务器解决方案,广泛应用于个人网站、企业网站和大型网站中。

1.Apache:一款开源的HTTP服务器软件,具有良好的性能和稳定性,支持多种服务器端编程语言,如PHP、Python、Perl等。

2.MySQL:一款开源的关系型数据库管理系统,具有高性能、易用性等特点,被广泛应用于各种Web应用中。

3.PHP:一种流行的服务器端脚本语言,具有简单易学、功能强大等特点,是开发动态网站的重要工具。

二、编译源码安装LAMP环境

1.准备工作

在编译源码安装LAMP环境之前,请确保您的CentOS系统已更新到最新版本,以避免兼容性问题。可以使用以下命令更新系统:

bash sudo yum update

2.安装依赖包

在编译源码之前,需要安装一些依赖包,以确保编译过程顺利进行。可以使用以下命令安装:

bash sudo yum install -y gcc gcc-c++ autoconf automake make libtool bison nasm patch gzip tar bzip2 openssl openssl-devel readline readline-devel zlib zlib-devel gmp gmp-devel libxml2 libxml2-devel libxslt libxslt-devel freetype freetype-devel fontconfig fontconfig-devel libpng libpng-devel libjpeg libjpeg-devel libjpeg-turbo libjpeg-turbo-devel libpng libpng-devel libxml2 libxml2-devel libxslt libxslt-devel openssl openssl-devel readline readline-devel zlib zlib-devel gmp gmp-devel

3.编译安装Apache

首先,下载Apache源码包:

bash wget http://www.apache.org/dyn/closer.cgi?path=binaries/apache_org/httpd/httpd-2.4.39.tar.bz2

然后,解压源码包:

bash tar -xjf httpd-2.4.39.tar.bz2

进入源码目录,运行以下命令配置、编译和安装:

bash cd httpd-2.4.39 ./configure --prefix=/usr/local/apache2 --enable-mods-shared=all make sudo make install

4.编译安装MySQL

同样,下载MySQL源码包:

bash wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.29.tar.gz

解压源码包:

bash tar -zxvf mysql-5.7.29.tar.gz

进入源码目录,运行以下命令配置、编译和安装:

bash cd mysql-5.7.29 ./configure --prefix=/usr/local/mysql --with-unix-socket-path=/var/lib/mysql/mysql.sock --with-socket-path=/var/lib/mysql/mysql.sock --enable-thread-safe-client --enable-assembler --without-ucs2 --without-ssl --without-debug --without-query-cache --without-server --without-myisam make sudo make install

配置MySQL:

bash sudo cp /usr/local/mysql/support-files/my-large.cnf /etc/my.cnf sudo cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld sudo chkconfig --add mysqld sudo chkconfig mysqld on sudo service mysqld start

初始化MySQL数据库:

bash sudo mysql_secure_installation

5.编译安装PHP

下载PHP源码包:

bash wget http://php.net/distributions/php-7.4.2.tar.gz

解压源码包:

bash tar -zxvf php-7.4.2.tar.gz

进入源码目录,运行以下命令配置、编译和安装:

`bash cd php-7.4.2 ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --enable-mysqlnd --with-mysqli=/usr/local/mysql/bin/mysqlconfig --with-pdo-mysql=/usr/local/mysql/bin/mysqlconfig --with-openssl=/usr/local/ssl --with-zlib --with-bz2 --with-gd --with-curl --with-xmlrpc --with-xsl --enable-zip --enable-bcmath --enable-soap --enable-ftp --enable-gd-native-ttf --enable-exif --enable-intl --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/png --with-gettext --with-mhash --with-curl --with-mysqli=/usr/local/mysql/bin/mysqlconfig --with-pdo-mysql=/usr/local/mysql/bin/mysqlconfig --with-openssl=/usr/local/ssl --with-zlib --with-bz2 --with-gd --with-xmlrpc --with-xsl --enable-zip --enable-bcmath --enable-soap --enable-ftp --enable-gd-native-ttf --enable-exif --enable-intl --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/png --with-gettext --with-mhash --with-curl --with-mysqli=/usr/local/mysql/bin/mysqlconfig --with-pdo-mysql=/usr/local/mysql/bin/mysqlconfig --with-openssl=/usr/local/ssl --with-zlib --with-bz2 --with-gd --with-xmlrpc --with-xsl --enable-zip --enable-bcmath --enable-soap --enable-ftp --enable-gd-native-ttf --enable-exif --enable-intl --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/png --with-gettext --with-mhash --with-curl --with-mysqli=/usr/local/mysql/bin/mysqlconfig --with-pdo-mysql=/usr/local/mysql/bin/mysqlconfig --with-openssl=/usr/local/ssl --with-zlib --with-bz2 --with-gd --with-xmlrpc --with-xsl --enable-zip --enable-bcmath --enable-soap --enable-ftp --enable-gd-native-ttf --enable-exif --enable-intl --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/png --with-gettext --with-mhash --with-curl --with-mysqli=/usr/local/mysql/bin/mysqlconfig --with-pdo-mysql=/usr/local/mysql/bin/mysqlconfig --with-openssl=/usr/local/ssl --with-zlib --with-bz2 --with-gd --with-xmlrpc --with-xsl --enable-zip --enable-bcmath --enable-soap --enable-ftp --enable-gd-native-ttf --enable-exif --enable-intl --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/png --with-gettext --with-mhash --with-curl --with-mysqli=/usr/local/mysql/bin/mysqlconfig --with-pdo-mysql=/usr/local/mysql/bin/mysqlconfig --with-openssl=/usr/local/ssl --with-zlib --with-bz2 --with-gd --with-xmlrpc --with-xsl --enable-zip --enable-bcmath --enable-soap --enable-ftp --enable-gd-native-ttf --enable-exif --enable-intl --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/png --with-gettext --with-mhash --with-curl --with-mysqli=/usr/local/mysql/bin/mysqlconfig --with-pdo-mysql=/usr/local/mysql/bin/mysqlconfig --with-openssl=/usr/local/ssl --with-zlib --with-bz2 --with-gd --with-xmlrpc --with-xsl --enable-zip --enable-bcmath --enable-soap --enable-ftp --enable-gd-native-ttf --enable-exif --enable-intl --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/png --with-gettext --with-mhash --with-curl --with-mysqli=/usr/local/mysql/bin/mysqlconfig --with-pdo-mysql=/usr/local/mysql/bin/mysqlconfig --with-openssl=/usr/local/ssl --with-zlib --with-bz2 --with-gd --with-xmlrpc --with-xsl --enable-zip --enable-bcmath --enable-soap --enable-ftp --enable-gd-native-ttf --enable-exif --enable-intl --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/png --with-gettext --with-mhash --with-curl --with-mysqli=/usr/local/mysql/bin/mysqlconfig --with-pdo-mysql=/usr/local/mysql/bin/mysqlconfig --with-openssl=/usr/local/ssl --with-zlib --with-bz2 --with-gd --with-xmlrpc --with-xsl --enable-zip --enable-bcmath --enable-soap --enable-ftp --enable-gd-native-ttf --enable-exif --enable-intl --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/png --with-gettext --with-mhash --with-curl --with-mysqli=/usr/local/mysql/bin/mysqlconfig --with-pdo-mysql=/usr/local/mysql/bin/mysqlconfig --with-openssl=/usr/local/ssl --with-zlib --with-bz2 --with-gd --with-xmlrpc --with-xsl --enable-zip --enable-bcmath --enable-soap --enable-ftp --enable-gd-native-ttf --enable-exif --enable-intl --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/png --with-gettext --with-mhash --with-curl --with-mysqli=/usr/local/mysql/bin/mysqlconfig --with-pdo-mysql=/usr/local/mysql/bin/mysqlconfig --with-openssl=/usr/local/ssl --with-zlib --with-bz2 --with-gd --with-xmlrpc --with-xsl --enable-zip --enable-bcmath --enable-soap --enable-ftp --enable-gd-native-ttf --enable-exif --enable-intl --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/png --with-gettext --with-mhash --with-curl --with-mysqli=/usr/local/mysql/bin/mysqlconfig --with-pdo-mysql=/usr/local/mysql/bin/mysqlconfig --with-openssl=/usr/local/ssl --with-zlib --with-bz2 --with-gd --with-xmlrpc --with-xsl --enable-zip --enable-bcmath --enable-soap --enable-ftp --enable-gd-native-ttf --enable-exif --enable-intl --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/png --with-gettext --with-mhash --with-curl --with-mysqli=/usr/local/mysql/bin/mysqlconfig --with-pdo-mysql=/usr/local/mysql/bin/mysqlconfig --with-openssl=/usr/local/ssl --with-zlib --with-bz2 --with-gd --with-xmlrpc --with-xsl --enable-zip --enable-bcmath --enable-soap --enable-ftp --enable-gd-native-ttf --enable-exif --enable-intl --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/png --with-gettext --with-mhash --with-curl --with-mysqli=/usr/local/mysql/bin/mysqlconfig --with-pdo-mysql=/usr/local/mysql/bin/mysqlconfig --with-openssl=/usr/local/ssl --with-zlib --with-bz2 --with-gd --with-xmlrpc --with-xsl --enable-zip --enable-bcmath --enable-soap --enable-ftp --enable-gd-native-ttf --enable-exif --enable-intl --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/png --with-gettext --with-mhash --with-curl --with-mysqli=/usr/local/mysql/bin/mysqlconfig --with-pdo-mysql=/usr/local/mysql/bin/mysqlconfig --with-openssl=/usr/local/ssl --with-zlib --with-bz2 --with-gd --with-xmlrpc --with-xsl --enable-zip --enable-bcmath --enable-soap --enable-ftp --enable-gd-native-ttf --enable-exif --enable-intl --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/png --with-gettext --with-mhash --with-curl --with-mysqli=/usr/local/mysql/bin/mysqlconfig --with-pdo-mysql=/usr/local/mysql/bin/mysqlconfig --with-openssl=/usr/local/ssl --with-zlib --with-bz2 --with-gd --with-xmlrpc --with-xsl --enable-zip --enable-bcmath --enable-soap --enable-ftp --enable-gd-native-ttf --enable-exif --enable-intl --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/png --with-gettext --with-mhash --with-curl --with-mysqli=/usr/local/mysql/bin/mysqlconfig --with-pdo-mysql=/usr/local/mysql/bin/mysqlconfig --with-openssl=/usr/local/ssl --with-zlib --with-bz2 --with-gd --with-xmlrpc --with-xsl --enable-zip --enable-bcmath --enable-soap --enable-ftp --enable-gd-native-ttf --enable-exif --enable-intl --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/png --with-gettext --with-mhash --with-curl --with-mysqli=/usr/local/mysql/bin/mysqlconfig --with-pdo-mysql=/usr/local/mysql/bin/mysqlconfig --with-openssl=/usr/local/ssl --with-zlib --with-bz2 --with-gd --with-xmlrpc --with-xsl --enable-zip --enable-bcmath --enable-soap --enable-ftp --enable-gd-native-ttf --enable-exif --enable-intl --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/png --with-gettext --with-mhash --with-curl --with-mysqli=/usr/local/mysql/bin/mysqlconfig --with-pdo-mysql=/usr/local/mysql/bin/mysqlconfig --with-openssl=/usr/local/ssl --with-zlib --with-bz2 --with-gd --with-xmlrpc --with-xsl --enable-zip --enable-bcmath --enable-soap --enable-ftp --enable-gd-native-ttf --enable-exif --enable-intl --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/png --with-gettext --with-mhash --with-curl --with-mysqli=/usr/local/mysql/bin/mysqlconfig --with-pdo-mysql=/usr/local/mysql/bin/mysqlconfig --with-openssl=/usr/local/ssl --with-zlib --with-bz2 --with-gd --with-xmlrpc --with-xsl --enable-zip --enable-bcmath --enable-soap --enable-ftp --enable-gd-native-ttf --enable-exif --enable-intl --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/png --with-gettext --with-mhash --with-curl --with-mysqli=/usr/local/mysql/bin/mysqlconfig --with-pdo-mysql=/usr/local/mysql/bin/mysqlconfig --with-openssl=/usr/local/ssl --with-zlib --with-bz2 --with-gd --with-xmlrpc --with-xsl --enable-zip --enable-bcmath --enable-soap --enable-ftp --enable-gd-native-ttf --enable-exif --enable-intl --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/png --with-gettext --with-mhash --with-curl --with-mysqli=/usr/local/mysql/bin/mysqlconfig --with-pdo-mysql=/usr/local/mysql/bin/mysqlconfig --with-openssl=/usr/local/ssl --with-zlib --with-bz2 --with-gd --with-xmlrpc --with-xsl --enable-zip --enable-bcmath --enable-soap --enable-ftp --enable-gd-native-ttf --enable-exif --enable-intl --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/png --with-gettext --with-mhash --with-curl --with-mysqli=/usr/local/mysql/bin/mysqlconfig --with-pdo-mysql=/usr/local/mysql/bin/mysqlconfig --with-openssl=/usr/local/ssl --with-zlib --with-bz2 --with-gd --with-xmlrpc --with-xsl --enable-zip --enable-bcmath --enable-soap --enable-ftp --enable-gd-native-ttf --enable-exif --enable-intl --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/png --with-gettext --with-mhash --with-curl --with-mysqli=/usr/local/mysql/bin/mysqlconfig --with-pdo-mysql=/usr/local/mysql/bin/mysqlconfig --with-openssl=/usr/local/ssl --with-zlib --with-bz2 --with-gd --with-xmlrpc --with-xsl --enable-zip --enable-bcmath --enable-soap --enable-ftp --enable-gd-native-ttf --enable-exif --enable-intl --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/png --with-gettext --with-mhash --with-curl --with-mysqli=/usr/local/mysql/bin/mysqlconfig --with-pdo-mysql=/usr/local/mysql/bin/mysqlconfig --with-openssl=/usr/local/ssl --with-zlib --with-bz2 --with-gd --with-xmlrpc --with-xsl --enable-zip --enable-bcmath --enable-soap --enable-ftp --enable-gd-native-ttf --enable-exif --enable-intl --with-freetype