lamp centos(centos8安装)

大家好,关于lamp centos很多朋友都还不太明白,不过没关系,因为今天小编就来为大家分享关于centos8安装的知识点,相信应该可以解决大家的一些困惑和问题,如果碰巧可以解决您的问题,还望关注下本站哦,希望对各位有所帮助!

如何搭建lamp(CentOS7+Apache+MySQL+PHP)环境

在网上搜资料,自己在本地虚拟机上尝试搭建,弄了整整一天一夜,终于弄好了.网上的资料,虽然很多,但大多都是重复的,拿去试了之后,又很多都不能得到正确的结果.最终找到了适合我的linux环境的搭建方式;在这里贴出来:度娘真不给力啊,没搜出来靠谱的方法。最后用喜乐搜找到的靠谱的教程。

这里还是要总结一下我的LAMP环境的搭建步骤。我先在电脑里装了虚拟机,在虚拟机中测试了数次之后,再在服务器上搭建的。说说我的环境:虚拟机是:VMware® Workstation 12.1.1 Pro;Linux系统用的是:CentOS-7-x86_64-DVD-1511.iso;(阿里云上也是用的CentOS7-64bit)准备好这两个之后,就开始一步一步搭建我们的LAMP环境了。

一、安装虚拟机

二、安装CentOS7

注意:以下安装,我都是用的root权限。

三、安装Apache1.安装yum-y install httpd2.开启apache服务systemctl start httpd.service3.设置apache服务开机启动systemctl enable httpd.service4.验证apache服务是否安装成功在本机浏览器中输入虚拟机的ip地址,CentOS7查看ip地址的方式为:ip addr(阿里云不需要用这种方式查看,外网ip已经在你主机列表那里给你写出来了的;)这里是访问不成功的(阿里云用外网访问,能成功,不需要做以下步骤)查了资料,说法是,CentOS7用的是Firewall-cmd,CentOS7之前用的是iptables防火墙;要想让外网能访问到apache主目录,就需要做以下的操作:firewall-cmd--permanent--zone=public--add-service=httpfirewall-cmd--permanent--zone=public--add-service=httpsfirewall-cmd--reload然后再访问外网ip,如果看到apache默认的页面--有Testing 123...字样,便是成功安装了apache服务了;

四、安装PHP1.安装yum-y install php2.重启apache服务systemctl restart httpd或者systemctl restart httpd.service然后,你可以写一个php文件在浏览器中运行一下了;eg:vi/var/www/html/info.phpi<?php phpinfo();?>Esc:wq然后,在自己电脑浏览器输入 192.168.1.1/info.php运行,会出现php的一些信息

五、安装MySQL我这里根据所学的那个教程,也安装了MariaDB1.安装

yum-y install mariadb*

2.开启MySQL服务systemctl start mariadb.service3.设置开机启动MySQL服务systemctl enable mariadb.service4.设置root帐户的密码mysql_secure_installation然后会出现一串东西,可以仔细读一下,如果你懒得读,就在提示出来的时候,按Enter就好了,让你设置密码的时候,你就输入你想要的密码就行,然后继续在让你选择y/n是,Enter就好了;当一切结束的时候,你可以输入mysql-uroot-p的方式,验证一下;

六、将PHP和MySQL关联起来yum search php,选择你需要的安装:yum-y install php-mysql

七、安装常用的PHP模块例如,GD库,curl,mbstring,...1.安装:yum-y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel2.重启apache服务systemctl restart httpd.service然后,再次在浏览器中运行info.php,你会看到安装的模块的信息;

至此,LAMP环境就搭建好了。

如何搭建lamp(CentOS7+Apache+MySQL+PHP)环境

标签:

LAMP平台安装Xcache和Memcached加速网站运行

在CentOS 7系统里搭建好LAMP环境后,就可以安装网站程序了,以最流行了Wordpess为例。为了加快网站的访问速度,除了花钱买更好的硬件设施外。我们可以通过优化网站的程序、主题。为服务器开启缓存功能,为网站提速。我们知道,互联网上缓存为王。

1.安装php加速器Xcache

XCache是一个国人开发的又快又稳定的 PHP opcode缓存器,通过共享编译内存从而降低服务器负载。

由于yum源仓库里面没有,先下载源文件,最新版3.2.0

在tmp目录下:cd/tmp下载:wget

解压缩:tar xvfz xcache-3.2.0.tar.gz

准备安装:cd xcache-3.2.0

安装前,先要准备编译环境:yum-y install php-devel gcc

运行phpize,非常重要:phpize

配置:./configure--enable-xcache

安装:make make install

复制配置文件 cp xcache.ini/etc/php.d(xcache.ini在源程序安装目录)

重新启动http服务:systemctl restart httpd

2.安装memcached

Memcached是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载。它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提供动态、数据库驱动网站的速度。

a.安装

yum-y install memcached

安装memcache关联php

yum-y install php-pecl-memcache

编译安装PHP的memcache扩展

下载 wget

tar xf memcache-3.0.8.tgz

cd memcache-3.0.8

依次执行

phpize

./configure

make make install

b.配置

在php.ini文件中添加memcache扩展

extension=/usr/lib64/php/modules/memcache.so(版本不同目录可能不同)

c.运行

memcached-d-m 128-c 1024-P/tmp/memcached.pid

d.测试

测试memcached是否工作正常,在网站目录下编辑一个文件如memtest.php,放入如下代码:

$memcache= new Memcache;

$memcache-connect('localhost', 11211) or die("Could not connect");

$version=$memcache-getVersion();

echo"Server's version:".$version."

/n";

$tmp_object= new stdClass;

$tmp_object-str_attr='test';

$tmp_object-int_attr= 123;

$memcache-set('key',$tmp_object, false, 10) or die("Failed to save data at the server");

echo"Store data in the cache(data will expire in 10 seconds)

/n";

$get_result=$memcache-get('key');

echo"Data from the cache:

/n";

var_dump($get_result);

?

访问后如果能现实版本号server's version: 1.4…… store date in the cache等信息说明memcached运行正常。

5.整合

Wordpress支持memcached

下载:wget

unzip memcached.2.0.2.zip

cd memcached.2.0.2

复制 object-cache.php到网站根目录 wp-content文件夹内,wordpress会自动调用缓存。

重启服务器:

sytemctl restart memcached

sytemctl restart httpd

3.开启Gzip压缩。

apache2.4版本默认添加了gzip模块,我们要同时开启deflate模块,压缩网页文件,提高服务器浏览速度。

vim/etc/httpd/conf/httpd.conf在最后加入如下几行:

DeflateCompressionLevel 9

AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-httpd-php

AddOutputFilter DEFLATE css js

重新启动http服务:systemctl restart httpd

如何在CentOS上安装phpMyAdmin

在CentOS上安装phpMyAdmin,你第一步需要架设一台Web服务器(如Apache或nginx),安装好MySQL/MariaDB数据库和PHP。根据你的偏好和需求,你可以从LAMP和LEMP中选择一种安装。

另一个要求是允许在你的CentOS上安装EPEL库。

在CentOS6或7上安装phpMyAdmin

一旦你设置了EPEL库,你就能轻松地用以下命令安装phpMyAdmin了。

在CentOS 7上:

$ sudo yum install phpmyadmin

在CentOS 7上:

$ sudo yum install phpmyadmin php-mcrypt

在CentOS 7上配置phpMyAdmin

默认情况下,CentOS 7上的phpMyAdmin只允许从回环地址(127.0.0.1)访问。为了能远程连接,你需要改动它的配置。

用文本编辑器打开phpMyAdmin的配置文件(路径:/etc/httpd/conf.d/phpMyAdmin.conf),找出并注释掉带有"Require ip XXXX"字样的代码行。会有四处这样的代码行,用"Require all granted"取而代之。重新改动过的配置文件如下所示。

$ sudo vi/etc/httpd/conf.d/phpMyAdmin.conf

.....<Directory/usr/share/phpMyAdmin/> AddDefaultCharset UTF-8<IfModule mod_authz_core.c># Apache 2.4<RequireAny>#Require ip 127.0.0.1#Require ip::1 Require all granted</RequireAny></IfModule><IfModule!mod_authz_core.c># Apache 2.2 Order Deny,Allow Deny from All Allow from 127.0.0.1 Allow from::1</IfModule></Directory><Directory/usr/share/phpMyAdmin/setup/><IfModule mod_authz_core.c># Apache 2.4<RequireAny>#Require ip 127.0.0.1#Require ip::1 Require all granted</RequireAny></IfModule><IfModule!mod_authz_core.c># Apache 2.2 Order Deny,Allow Deny from All Allow from 127.0.0.1 Allow from::1</IfModule></Directory>.....

最后,重启httpd使改动生效。

$ sudo systemctl restart httpd

在CentOS 6上配置phpMyAdmin

默认情况下,CentOS 6上的phpMyAdmin是禁止从每个IP地址访问的。为了能远程连接,你需要改动它的配置。

用文本编辑器打开phpMyAdmin的配置文件(路径:/etc/httpd/conf.d/phpMyAdmin.conf),找出并注释掉"Deny from all"字样的代码行。然后把"Allow from 127.0.0.1"字样的代码行改成"Allow from 0.0.0.0"。重新改动过的配置文件如下所示。

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

<Directory"/usr/share/phpmyadmin"> Order Deny,Allow# Deny from all Allow from 0.0.0.0</Directory>

下一步是将phpMyAdmin的配置文件用blowfish加密工具加密。这一步需要加密cookie里的密码来作为基于cookie的部分认证。

用文本编辑器打开如下路径所示的文件并且用blowfish设置一个随机密码,如下所示。

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

$cfg['blowfish_secret']='kd5G}d33aXDc50!';/* YOU MUST FILL IN THIS FOR COOKIE AUTH!*/

最后,重启httpd使改动生效。

$ sudo service httpd restart

测试phpMyAdmin

测试phpMyAdmin是否设置成功,访问这个页面:

你应该能通过Web界面来记录下任何MySQL用户(比如root)和管理MySQL/MariaDB的数据库/表。

疑难解答

这里有一些在CentOS上安装phpMyAdmin的过程中遇到的一些问题解决方法。

当你在浏览器里尝试连接phpMyAdmin页面的时候,你看到"403 Forbidding"错误:

You don't have permission to access/phpMyAdmin on this server.

发生这种错误是因为phpMyAdmin默认阻止了IP地址远程连接。要修复这种错误,你需要编辑它的配置文件来允许远程连接。具体操作见上。

当你连接phpMyAdmin页面时,你看见"The configuration file now needs a secret passphrase(blowfish_secret)."信息,并且你无法登录。

要修复这种错误,你需要编辑/usr/share/phpmyadmin/config.inc.php这个文件来添加一个随机的blowfish密码,然后重启httpd,如下所示。

$ sudo service httpd restart(CentOS 6)

$ sudo systemctl restart httpd(CentOS 7)

$cfg['blowfish_secret']='kd5G}d33aXDc50!';/* YOU MUST FILL IN THIS FOR COOKIE AUTH!*/

当你连接phpMyAdmin页面时,你看见"Cannot load mcrypt extension. Please check your PHP configuration"错误信息。

要修复这种错误,要安装下面这个包:

然后重启httpd:

$ sudo service httpd restart(CentOS 6)

$ sudo systemctl restart httpd(CentOS 7)

$ sudo yum install php-mcrypt

阅读剩余
THE END