阿里云服务器搭建LAMP环境

2025-04-22 05:18:17

1、使用的例子:服务器版本内核。

阿里云服务器搭建LAMP环境

2、Xshell连接到您的服务器上,使系统处于最新状态执行以下命令,yum update -y

阿里云服务器搭建LAMP环境

3、利用yum命令安装Apache执行命令,yum -y install httpd

阿里云服务器搭建LAMP环境
阿里云服务器搭建LAMP环境

4、启动httpd并且设置为它开机启动,systemctl start httpd 【启动httpd命令】systemctl enable httpd 【设置httpd开机启动】

阿里云服务器搭建LAMP环境

5、我们这里可通过俩个命令查看是否启动和开机启动;systemctl status httpd 【查看是否启动命令】systemctl is-enabled httpd 【查看是否开机启动(输出enabled已经成功)】下图为例;

阿里云服务器搭建LAMP环境

6、注意:后续检查数据库的方法也是大同小异作不在详细解释。

7、安装成功后,在浏览器地址栏输入你的服务器IP地址出现下图说明你的httpd已经成功安装,例如我这里:39.104.82.85

阿里云服务器搭建LAMP环境

8、安装数据库Mariadb它是MySQL的一个分支几乎兼容mysql所有功能,执行下面命令;yum -y install mariadb-server mariadb

阿里云服务器搭建LAMP环境
阿里云服务器搭建LAMP环境

9、启动mariadb并且设置为它开机启动;检查是否启动和开机启动systemctl start mariadbsystemctl enable mariadbsystemctl status mariadbsystemctl is-enabled mariadb

阿里云服务器搭建LAMP环境
阿里云服务器搭建LAMP环境

10、下面配置root密码和数据库的一些安全;执行命令,mysql_secure_installation

11、#将会输出让输入原始密码(这里默认为空密码请直接回车Enter),In order to log into MariaDB to secure it, we'll need the currentpassword for the root user. If you've just installed MariaDB, andyou haven't set the root password yet, the password will be blank,so you should just press enter here.Enter current password for root (enter for none):#这里询问我们是否设置root密码,输入y设置密码,y(设置); n(不设置)Setting the root password ensures that nobody can log into the MariaDBroot user without the proper authorisation.Set root password? [Y/n]#输入密码再次确认密码回车Set root password? [Y/n] yNew password:Re-enter new password:Password updated successfully!Reloading privilege tables..... Success!By default, a MariaDB installation has an anonymous user, allowing anyoneto log into MariaDB without having to have a user account created forthem. This is intended only for testing, and to make the installationgo a bit smoother. You should remove them before moving into aproduction environment.Remove anonymous users? [Y/n] y (询问是否移除匿名用户输入y回车)... Success!Normally, root should only be allowed to connect from 'localhost'. Thisensures that someone cannot guess at the root password from the network.Disallow root login remotely? [Y/n] n(询问是否禁止远程root登陆我这里选择y禁止远程登录【如果您需要远程登录连接数据库可选择n】)... skipping.By default, MariaDB comes with a database named 'test' that anyone canaccess. This is also intended only for testing, and should be removedbefore moving into a production environment.Remove test database and access to it? [Y/n] y(询问是否删除测试数据库【可选项随意y或n】这里我选择y)Reloading the privilege tables will ensure that all changes made so farwill take effect immediately.Reload privilege tables now? [Y/n] y (询问是否现在重新加载权限表选择y回车)... Success!Cleaning up...All done! If you've completed all of the above steps, your MariaDBinstallation should now be secure.Thanks for using MariaDB!#会自动跳到命令页面,到此我们的数据库设置了密码和一些安全。

12、我们可以简单登录下数据库;mysql -uroot -pEnter password: 【输入密码回车即可登录进去】Welcome to the MariaDB monitor. Commands end with ; or \g.Your MariaDB connection id is 13Server version: 5.5.56-MariaDB MariaDB ServerCopyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]> show databases; 【命令显示数据库列表】+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema |+--------------------+4 rows in set (0.01 sec)MariaDB [(none)]> quit 【退出数据库】Bye

阿里云服务器搭建LAMP环境

13、安装PHP,执行命令;yum -y install php

阿里云服务器搭建LAMP环境
阿里云服务器搭建LAMP环境

14、查看所有组件,执行命令;yum search php选择所需组件进行安装,执行命令;yum -y install php-罪焐芡拂mysql php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel

阿里云服务器搭建LAMP环境
阿里云服务器搭建LAMP环境

15、完成后我们可以新建一个PHP页面来查看我们安装的组件,执行命令;vim /var/www/html/info.php#打开后按键盘字母 i #编辑为以下内容;<?phpphpinfo();?>#编辑完后按键盘 Esc 在输入 : 最后 wq! 回车。#vim使用方法可自行百度,不作详细解释

阿里云服务器搭建LAMP环境

16、最后重启的httpd服务,执行命令诋危族枧;systemctl restart httpd打开浏览器输入:39.104.82.85/info.php(即IP地址 / 和文件名)#看到这个页面证明您的LAMP环境搭建httpd发布目录默认在/var/www/html/#您可以使用winscp上传您的页面到发布目录

阿里云服务器搭建LAMP环境

17、###最后执行命令 rm -rf /var/www/html/info.php 删除你的这种测试文件###【我是:等待>行动=等死】

阿里云服务器搭建LAMP环境
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
相关推荐
  • 阅读量:85
  • 阅读量:39
  • 阅读量:52
  • 阅读量:55
  • 阅读量:40
  • 猜你喜欢