在Linux环境中搭建web服务器(linux服务器部署web项目)

如何在Linux 中搭建一个web服务器

web服务器的简单搭建

1、安装一个可以提供web服务的软件

yum -y install httpd

2、 启动httpd服务

systemctl start httpd

3、进入主配置文件

vim /etc/httpd/conf/httpd.conf

在此范围内添加或删除设置,为了方便编写,编辑了一个子配置文件/etc/httpd/conf.d/httpd-vhosts.conf

4、 编辑子配置文件

vim /etc/httpd/conf.d/httpd-vhosts.conf 此路径必为conf.d/*.conf (意:为.conf 后缀命名)

systemctl restart httpd 重启服务

5、 编辑页面测试文件

在web服务中默认存放网页文件的路径:/var/ chaodiquan.com /html

默认网页文件名字:index.html

6、 浏览器测试

ifconfig ens33 查看ens33网卡的地址

在浏览器里面 输入你的IP就可以看到测试文件里 希望可以帮助到的哈!

Linux怎么配置Web服务器

工具/原料

Linux操作系统

Web服务器配置详解

方法/步骤

1.Apache是Linux下的Web服务器,Apache用的是静态页面,需要加载模块来支持动态页面,会动态实时的调整进程来处理,最合理的使用多核CPU资源,支持虚拟主机应用,多个Web站点共享一个IP地址。

安装Web服务

先安装Web服务,通过命令yum groupinstall命令进行安装,建议用groupinstall而不用Install是因为groupinstall,会把该服务所有相关的服务包一起安装,这样不会有丢失。

2.通过service httpd restart来开启服务,这里用restart而不用start的原因是restart更安全,因为不知道该服务是否已经开启,如果已经start了再次用start可能会有意外的问题产生,故这里用restart.

3.通过命令chkconfig httpd on来开启httpd服务在下次开机后,仍然是开启有效的,这样的好处在于通过设置自动开启服务,避免人为失误操作,也会保证计算机重启或者断电后服务还是开启的。

4.验证httpd服务是否正常开启,是否能够对外提供服务,进入/var/www/html/,这里是主站点,写一个简单的页面,然后重定向到index.html,这是默认的首页。通过http访问该服务,发现已经成功服务该站点。

5.通过命令vim /etc/httpd/conf/httpd.conf可以对httpd配置文件进行修改,也可以用配置文件里面的功能,有些功能用#号注释掉了,如果想使用该功能的话,直接删除#号,可以让内置的配置文件该功能生效。

6.通过命令ll /etc/httpd可以查看到该目录下有conf和conf.d目录文件,再进一步查看/etc/httpd/conf.d下面可以看到的文件都是httpd的模块文件,用来支持动态页面的模块文件。

7.Apache和Selinux之间的关系,进入/var/www/html/目录下,通过ll –Z查看目录下index.html Selinux属性,通过命令ps –auxZ|grep http查看httpd的进程,这些http进程都有httpd_t的Selinux上下文属性,Selinux就规定了http_t这类的进程上下文属性可以访问httpd_sys_content_t这类文件的上下文属性,从而保证了网站的内容可以被访问。

8.查看Apache日志信息,日志信息存储在/var/log/httpd/目录下,可以查看http访问的日志及https的访问日志,可以查看错误的http日志及https的错误日志等信息,

怎么在linux搭建web服务器

1.开始说明

本教程中使用的IP地址是192.168.0.100,主机名称为Server1.example.com 这些设置可能会有所不同,你需要根据不同情况进行修改。

CentOS 6.2下安装MySQL

2.开始安装MySQL5

首先我们应该先用下面的命令安装MySQL:

yum install mysql mysql-server

然后我们需要创建MySQL系统的启动键链接启动MySQL服务器,这样以便于MySQL在系统启动时自动启动

chkconfig --levels 235 mysqld on

/etc/init.d/mysqld start

为MySQL root帐户设置密码:

mysql_secure_installation

会出现下面的一系列提示:

root@server1 ~]# 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] -- ENTER

New password: -- yourrootsqlpassword

Re-enter new password: -- yourrootsqlpassword

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] -- ENTER

... 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] -- ENTER

... 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] -- ENTER

- 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] -- ENTER

... 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!

[root@server1 ~]#

CentOS 6.2下安装Apache

3.安装阿帕奇2

Apache2的是作为一个CentOS的软件包,因此我们可以直接用下面命令安装它:

yum install httpd

现在配置系统在引导时启动Apache

chkconfig --levels 235 httpd on

并启动Apache

/etc/init.d/httpd start

现在,您的浏览器到http://192.168.0.100,你应该看到Apache2的测试页:

Apache 2测试网页

Apache的默认文档根目录是在CentOS上的/var/www/html 目录 ,配置文件是/etc/httpd/conf/httpd.conf。配置存储在的/etc/httpd/conf.d/目录。

4.安装PHP5

我们可以用下面的命令来安装PHP5

yum install php

安装完需要重启

/etc/init.d/httpd restart

CentOS 6.2下安装PHP5

5.我们可以安装PHP5和Apache的PHP5的模块如下:

默认网站的文件根目录是在/srv/www/html中。现在我们将在该目录中创建一个小型PHP文件(info.php的)在浏览器中调用它。该文件将显示很多关于我们的PHP安装,如安装的PHP版本和有用的一些细节。

vi /var/www/html/info.php

修改细节

现在,我们可以用浏览器访问例如http://192.168.0.100/info.php文件

PHP页面

正如你所看到的,PHP5的工作,它通过Apache 2.0的处理程序,在服务器API线。如果你继续向下滚动,你会看到所有在PHP5中已经启用的模块。MySQL是没有列出,这意味着我们没有在PHP5支持MySQL。

6.PHP5获得MySOL的支持

让PHP在MySQL中获得支持,我们可以安装的php-mysql软件包。安装一些其他的PHP5模块,以及您可能需要的应用程序,这是一个好主意:

yum search php

还安装需要安装的

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

现在重新启动Apache2的:

/etc/init.d/httpd restart

现在,重载http://192.168.0.100/info.php在您的浏览器,并再次向下滚动到模块部分。现在,你应该找到许多新的模块,包括MySQL模块:

MySQL页面

CentOS 6.2下安装phpMyAdmin

7.安装phpMyAdmin

phpMyAdmin是一个网络接口,通过它可以管理你的MySQL数据库。

首先,我们使CentOS系统RPMForge软件库的phpMyAdmin,而不是官方的CentOS 6.2库:

所以需要导入RPMForge的GPG密钥:

rpm --import

x86_64系统:

yum install

在i386系统:

yum install

安装phpmyadmin

yum install phpmyadmin

现在我们可以设置phpMyAdmin,了我们可以改变Apache的配置来让phpMyAdmin不仅仅只能从localhost登录。

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

配置

下一步,我们从HTTP改变的phpMyAdmin的cookie来身份验证:

vi /usr/share/phpmyadmin/config.inc.php

修改身份验证

重启阿帕奇

/etc/init.d/httpd restart

在地址栏输入http://192.168.0.100/phpMyAdmin/:你就可以访问phpMyAdmin了。

phpmyadmin页面

CentOS可以得到RHEL的所有功能,甚至是更好的软件。但CentOS并不向用户提供商业支持,当然也不负上任何商业责任。

如果你要将你的RHEL转到CentOS上,因为不希望为RHEL升级而付费。当然,你必须有丰富linux使用经验,因此RHEL的商业技术支持对你来说并不重要。但如果你是单纯的业务型企业,那么还是建议你选购RHEL软件并购买相应服务。这样可以节省你的IT管理费用,并可得到专业服务。

linux怎么搭建web服务器

第一步,我们在Ubuntu下搭建LAMP环境,首先,安装apache:

sudo apt-get install apache2 apache2-doc

测试apache2正常工作:

接下来是安装mysql:

sudo apt-get install mysql-server

sudo apt-get install mysql-client

安装mysql的时候会提醒设置root账户的密码

,需要注意他和你的登录账户密码是没有什么联系的。

接下来是php的安装:

sudo apt-get install php5

sudo apt-get install libapache2-mod-php5  //安装apache服务支持php模块

安装配置完一些东西我们都是需要重启apache生效。

未经允许不得转载:便宜VPS网 » 在Linux环境中搭建web服务器(linux服务器部署web项目)