linux yum安装apache php mysql,CentOS 5.x yum安装LAMP(Apache+MySQL+PHP)

17270ce95af85a4a2d33846cd5831d99.png

LAMP是Linux,Apache,MySQL,PHP的缩写。这个教程主要是讲在centos安装有php和mysql支持的apache web服务器。在这个教程我使用主机名server1.example.com对应IP地址192.168.0.100。这些设置可能不同于你,你必须替换成你正确的。

添加外部源,保证MySQL和PHP最新

因为系统基本的源的MySQL和PHP程序比较旧,所以我们添加比较新的外部源。

# rpm --import http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka

# vi /etc/yum.repos.d/CentOS-Base.repo

在底部增加下面信息

[utterramblings]

name=Jason's Utter Ramblings Repo

baseurl=http://www.jasonlitka.com/media/EL$releasever/$basearch/

enabled=1

gpgcheck=1

gpgkey=http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka

安装MySQL

执行yum程序安装MySQL

yum install mysql mysql-server

添加MySQL进启动项(这样系统启动时会自动启动MySQL),并立即启动MySQL服务器:

chkconfig --levels 235 mysqld on

/etc/init.d/mysqld start

设置MySQL root帐号密码:

mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL

SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current

password for the root user.  If you've just installed MySQL, and

you 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):

OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL

root user without the proper authorisation.

Set root password? [Y/n]

New password:

Re-enter new password:

Password updated successfully!

Reloading privilege tables..

... Success!

By default, a MySQL installation has an anonymous user, allowing anyone

to log into MySQL without having to have a user account created for

them.  This is intended only for testing, and to make the installation

go a bit smoother.  You should remove them before moving into a

production environment.

Remove anonymous users? [Y/n]

... Success!

Normally, root should only be allowed to connect from 'localhost'.  This

ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n]

... Success!

By default, MySQL comes with a database named 'test' that anyone can

access.  This is also intended only for testing, and should be removed

before moving into a production environment.

Remove test database and access to it? [Y/n]

- Dropping test database...

... Success!

- Removing privileges on test database...

... Success!

Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

Reload privilege tables now? [Y/n]

... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MySQL

installation should now be secure.

Thanks for using MySQL!

安装Apache

Apache在CentOS软件包可用,因此我们可以使用yum安装:

yum install httpd

设置系统启动时自启动Apache

chkconfig --levels 235 httpd on

并启动Apache

/etc/init.d/httpd start

现在你直接在你的浏览器键入http://192.168.0.100,你就应该会看到Apache的测试页面。

安装PHP

我们可以按照下面的命令安装PHP和Apache PHP模块:

yum install php

然后重启Apache服务器:

/etc/init.d/httpd restart

安装相关模块使用PHP支持MySQL

为了让PHP支持MySQL,我们可以安装php-mysql软件包。你也可以安装其它的php模块。可以使用以下命令搜索可用的php模块:

yum search php

选择一些你需要的模块进行安装:

yum install php-mysql php-common php-mbstring php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc

添加apache支持php:

编辑/etc/httpd/conf/httpd.conf,添加:

Addtype application/x-httpd-php .php

现在重启Apache:

/etc/init.d/httpd restart

安装phpMyAdmin

phpMyAdmin是一个可视化管理你的MySQL数据库的软件。

安装很简单,下载解压到根目录即可.

下载地址:http://www.phpmyadmin.net/home_page/downloads.php

接着我们配置phpMyAdmin,为了使用phpMyAdmin不仅仅只允许localhost连接,我们修改一下apache的配置。

vi /etc/httpd/conf.d/phpmyadmin.conf

填入如下内容:

#

#  Web application to manage MySQL

#

#

#  Order Deny,Allow

#  Deny from all

#  Allow from 127.0.0.1

#

Alias /phpmyadmin /usr/share/phpmyadmin

重启apache:

/etc/init.d/httpd restart

然后你就可以通过http://192.168.0.100/phpmyadmin/进入phpMyAdmin了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
CentOS 7.9是一种常用的Linux系统,而LAMP是一种常见的Web服务器环境,用于搭建个人博客等网站。下面是使用本地yum安装LAMP的步骤: 1. 首先,确保你已经安装CentOS 7.9操作系统,并且已经配置好网络连接。 2. 安装Apache HTTP服务器: - 打开终端,使用root权限登录。 - 运行以下命令安装Apache: ``` yum install httpd ``` - 安装完成后,启动Apache服务并设置开机自启动: ``` systemctl start httpd systemctl enable httpd ``` 3. 安装MySQL数据库: - 运行以下命令安装MySQL: ``` yum install mariadb-server ``` - 安装完成后,启动MySQL服务并设置开机自启动: ``` systemctl start mariadb systemctl enable mariadb ``` - 运行MySQL安全脚本以提高安全性并设置root密码: ``` mysql_secure_installation ``` 4. 安装PHP: - 运行以下命令安装PHP及相关扩展: ``` yum install php php-mysql ``` - 安装完成后,重新启动Apache服务: ``` systemctl restart httpd ``` 5. 配置虚拟主机: - 打开Apache的默认配置文件: ``` vi /etc/httpd/conf/httpd.conf ``` - 在文件末尾添加以下内容,用于配置虚拟主机: ``` <VirtualHost *:80> ServerName your_domain DocumentRoot /var/www/html/your_domain <Directory /var/www/html/your_domain> AllowOverride All </Directory> </VirtualHost> ``` - 将`your_domain`替换为你的域名或IP地址,并保存文件。 - 创建网站根目录: ``` mkdir /var/www/html/your_domain ``` - 设置正确的文件权限: ``` chown -R apache:apache /var/www/html/your_domain chmod -R 755 /var/www/html/your_domain ``` 6. 完成以上步骤后,你就可以通过浏览器访问你的个人博客了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值