如何在服务器上安装LAMP环境?

在服务器上安装LAMP(Linux、ApacheMySQLPHP)环境,可以按照以下步骤进行,以下是详细的安装过程和相关配置:

如何在服务器上安装LAMP环境?

安装前的准备

1、系统更新:确保系统软件包是最新的。

   sudo apt update && sudo apt upgrade -y

2、关闭防火墙并准备安装所需软件包

   systemctl stop firewalld
   systemctl disable firewalld
   setenforce 0

一、安装Apache HTTP服务器

1、安装环境依赖包

   yum -y install gcc gcc-c++ make pcre pcre-devel expat-devel perl

2、配置软件模块:将APR组件包移动到Apache源码的srclib目录下。

   cd /opt/
   tar zxvf apr-1.6.2.tar.gz
   tar zxvf apr-util-1.6.0.tar.gz
   tar jxvf httpd-2.4.29.tar.bz2
   mv apr-1.6.2 /opt/httpd-2.4.29/srclib/apr
   mv apr-util-1.6.0 /opt/httpd-2.4.29/srclib/apr-util

3、编译及安装Apache

   cd /opt/httpd-2.4.29/
   ./configure --prefix=/usr/local/httpd \
              --enable-so \
              --enable-rewrite \
              --enable-charset-lite \
              --enable-cgi
   make && make install

4、优化配置文件路径:将相关文件链接到常用路径。

   ln -s /usr/local/httpd/bin/httpd /usr/sbin/httpd

5、添加httpd服务到系统服务管理

   cp /usr/local/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf
   cp /usr/local/httpd/conf/mime.types /etc/httpd/conf/mime.types

6、修改httpd服务配置文件:编辑/etc/httpd/conf/httpd.conf文件,根据需要进行调整。

7、启动并设置Apache开机自启

如何在服务器上安装LAMP环境?

   systemctl start httpd
   systemctl enable httpd

8、浏览器访问验证:在浏览器中访问http://<您的服务器IP>/,应显示Apache默认的欢迎页面,如果无法访问,请检查防火墙设置。

二、安装MySQL数据库

1、准备安装包:下载MySQL安装包并将其传到服务器上。

2、安装环境依赖包

   yum -y install perl

3、配置软件模块:解压并配置MySQL。

   cd /opt/
   tar zxvf mysql-5.7.24.tar.gz
   cd mysql-5.7.24/
   cmake .
   make && make install

4、创建MySQL用户

   mysql_install_db --user=mysql --basedir=/usr/local/mysql-5.7.24/ --datadir=/usr/local/mysql/data

5、修改MySQL配置文件:编辑/etc/my.cnf文件,根据需要进行调整。

6、更改MySQL安装目录和配置文件的属主属组

   chown -R mysql:mysql /usr/local/mysql

7、设置路径环境变量:编辑/etc/profile文件,添加以下内容:

   export PATH=$PATH:/usr/local/mysql/bin

8、初始化数据库

如何在服务器上安装LAMP环境?

   mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

9、添加MySQL系统服务:复制MySQL启动脚本到/etc/init.d/目录,并设置为开机自启动。

   cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
   chmod +x /etc/init.d/mysqld
   systemctl enable mysqld

10、启动MySQL服务

    systemctl start mysqld

11、修改MySQL登录密码:登录MySQL并修改初始密码。

    mysql -u root -p
    ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';

12、授权远程登录

    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'your_password' WITH GRANT OPTION;
    FLUSH PRIVILEGES;

三、安装PHP解析环境

1、将安装PHP所需软件包传到/opt 目录:下载PHP安装包并将其传到服务器上。

2、安装GD库和相关程序

   yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel xz xz-devel gd gd-devel libmcrypt libmcrypt-devel

3、配置PHP软件模块:解压并配置PHP。

   cd /opt/
   tar zxvf php-7.4.0.tar.gz
   cd php-7.4.0/
   ./configure --prefix=/usr/local/php \
               --with-config-file-path=/usr/local/php \
               --with-config-file-scan-dir=/usr/local/php/etc \
               --disable-all \
               --enable-maintainer-zlib \
               --enable-maintainer-openssl \
               --with-zlib-dir \
               --with-zlib-lib \
               --enable-mbstring \
               --enable-ftp \
               --enable-mbregex \
               --enable-mysqlnd \
               --with-curl \
               --enable-embedded-zlib \
               --with-libdir=lib \
               --with-mysqli=mysqlnd \
               --with-pdo-mysql=mysqlnd \
               --with-openssl \
               --with-gd \
               --with-bz2 \
               --enable-gd-native-ttf \
               --with-freetype-dir=/usr/include/freetype2 \
               --with-jpeg-dir=/usr/include \
               --with-png-dir=/usr/include \
               --enable-gd-jit-ft-dir=enabled \
               --with-mhash \
               --enable-json \
               --with-apxs2=/usr/local/httpd/bin/apxs \
               --with-config-file-path=/usr/local/php/etc \
               --sysconfdir=/usr/local/php/etc \
               --with-pcre-regex=yes \
               --with-pcre-dir=/usr/local/php \
               --with-zlib=/usr \
               --with-libxml-dir=/usr \
               --enable-inline-optimization \
               --disable-debug \
               --disable-rpath \
               --enable-option-checking=fatal \
               --enable-sigchild \
               --enable-trans-sigs \
               --with-mime-magic \
               --without-pear \
               --with-gettext \
               --with-system-tzdata \
               --with-curl \
               --enable-ftp \
               --enable-mbstring \
               --enable-exif \
               --with-gd \
               --enable-intl \
               --enable-calendar \
               --with-ctype=yes \
               --enable-cli \
               --with-iconv=yes \
               --enable-session \
               --enable-tokenizer \
               --enable-wddx \
               --enable-xmlreader \
               --enable-xmlwriter \
               --with-xmlrpc \
               --enable-shmop \
               --enable-simplexml \
               --enable-soap \
               --enable-sockets \
               --enable-sysvsem \
               --enable-sysvshm \
               --enable-pcntl \
               --enable-sysvshmht \
               --enable-bpfilter \
               --enable-dbx \
               --enable-exif \
               --enable-ftp \
               --enable-fileinfo \
               --enable-filter \
               --enable-ipv6 \
               --enable-json \
               --enable-hash \
               --enable-libgen \
               --enable-dom \
               --with-readline \
               --with-libedit \
               --with-openssl \
               --with-zlib \
               --enable-zip \
               --with-bz2 \
               --with-curl \
               --enable-mysqlnd \
               --with-pdo_mysql=mysqlnd \
               --with-pdo_sqlite=enabled \
               --with-sqlite3=enabled \
               --with-gd \
               --enable-gd-native-ttf \
               --with-jpeg-dir=/usr \
               --with-png-dir=/usr \
               --with-freetype-dir=/usr/include/freetype2 \
               --with-xpm-dir=no \
               --with-xpm-include=no \
               --with-xpm-lib=no \
               --enable-static \
               --enable-shared \
               --enable-debug \
               --disable-rpath \
               --enable-inline-optimization \
               --disable-debug \
               --disable-rpath \
               --enable-option-checking=fattal

以上内容就是解答有关“服务器安装lamp”的详细内容了,我相信这篇文章可以为您解决一些疑惑,有任何问题欢迎留言反馈,谢谢阅读。

文章来源网络,作者:运维,如若转载,请注明出处:https://shuyeidc.com/wp/51602.html<

(0)
运维的头像运维
上一篇2025-01-11 21:25
下一篇 2025-01-11 21:30

相关推荐

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注