centos6 apache centos下载软件并安装
如何在CentOS6下实现Apache+PHP+MySQL的快速安装
LAMP是一个免费、开源的解决方案,代表了Linux、Apache、MySQL、PHP,主要用作建立可行的通用的web服务器。那么如何在CentOS6下实现安装Apache+php+Mysql的快速安装?其具体安装配置步骤可以如下进行:
1.准备工作
使用yum进行安装,为了提高速度,最好先是修改为中国CentOS镜像服务器。目前国内有三个镜像可以选择,分别是:中国科学技术大学、163和Sohu的镜像,建议教育网用户选择中科大,电信用户选择163,他们的repo文件本博客作了备份如下:
下面命令是备份CentOS-Base.repo文件,并修改使用163镜像作为yum源:
mv/etc/yum.repos.d/CentOS-Base.repo/etc/yum.repos.d/CentOS-Base.repo.save
wget
mv CentOS6-Base-163.repo/etc/yum.repos.d/CentOS-Base.repo
2.更新系统内核
yum-y update
3.安装Apahce、Mysql、PHP
yum-y install httpd php mysql mysql-server
默认情况下,mysql数据目录位于/var/lib/mysql
4.安装相关组件:
yum install php-mysql php-gd php-imap php-ldap php-odbc
php-pear php-xml php-xmlrpc
5.安装MySQL管理工具phpMyAdmin
yum-y install phpMyAdmin
6.配置Apache随系统启动
chkconfig--levels 235 httpd on
/etc/init.d/httpd start
7.配置MySQL随系统启动
chkconfig--levels 235 mysqld on
/etc/init.d/mysqld start
8.设置数据库root密码
/usr/bin/mysqladmin-u root password'New+Password#www.yupengyan.com'
9.测试PHP是否安装成功
在 CentOS中 Apache的默认根目录是/var/www/html,配置文件/etc/httpd/conf/httpd.conf。其他配置存储在/etc/httpd/conf.d/目录。
阿里云上的centos 7.2怎么yum安装php 5.6
因之前通过网易的 centos镜像,将阿里云的 centos升级到最新版了,乘自己的项目尚未开始正式开发,遂将所有的相应环境都升级到最高。
查看 centos版本:
[root@iZ23d~]# cat/etc/centos-release
CentOS Linux release 7.2.1511(Core)
1、删除之前的 php版本:
[root@iZ23d~]# yum remove php* php-common
Loaded plugins: langpacks
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
No Match for argument: php-5.4.16
No Match for argument: php-5.4.16.tar.gz
No Match for argument: php-7.0.1RC1
No Match for argument: php-7.0.1RC1.tar.gz
No Match for argument: phpMyAdmin-4.4.0.tar.gz
No Match for argument: php-common
No Packages marked for removal
2、rpm安装 Php7相应的 yum源:
[root@iZ23d~]# rpm-Uvh
Retrieving
warning:/var/tmp/rpm-tmp.LhJKKR: Header V4 RSA/SHA1 Signature, key ID 62e74ca5: NOKEY
Preparing...################################# [100%]
package webtatic-release-7-3.noarch is already installed
3、直接yum安装php7:
[root@iZ23d~]# yum install php70w
Loaded plugins: langpacks
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Resolving Dependencies
--> Running transaction check
。。。【省略】
Warning: RPMDB altered outside of yum.
Installing: php70w-common-7.0.0-1.w7.x86_64 1/3
Installing: php70w-cli-7.0.0-1.w7.x86_64 2/3
Installing: php70w-7.0.0-1.w7.x86_64 3/3
Verifying: php70w-7.0.0-1.w7.x86_64 1/3
Verifying: php70w-common-7.0.0-1.w7.x86_64 2/3
Verifying: php70w-cli-7.0.0-1.w7.x86_64 3/3
Installed:
php70w.x86_64 0:7.0.0-1.w7
Dependency Installed:
php70w-cli.x86_64 0:7.0.0-1.w7 php70w-common.x86_64 0:7.0.0-1.w7
Complete!
4、检查 php版本:
[root@iZ23d~]# php-v
PHP 7.0.0(cli)(built: Dec 2 2015 20:42:32)( NTS)
Copyright(c) 1997-2015 The PHP Group
Zend Engine v3.0.0, Copyright(c) 1998-2015 Zend Technologies
[root@iZ23d2e6hoqZ~]#
以上显示安装成功!
5、重启 Apache,查看 phpinfo:
[root@iZ23d~]# systemctl restart httpd.service
检查phpinfo:
PHP Version 7.0.0
SystemLinux iZ23d 3.10.0-229.11.1.el7.x86_64#1 SMP Thu Aug 6 01:06:18 UTC 2015 x86_64
Build DateDec 2 2015 20:43:38
Server APIApache 2.0 Handler
Virtual Directory Supportdisabled
Configuration File(php.ini) Path/etc
Loaded Configuration File/etc/php.ini
Scan this dir for additional.ini files/etc/php.d
Additional.ini files parsed/etc/php.d/bz2.ini,/etc/php.d/calendar.ini,/etc/php.d/ctype.ini,/etc/php.d/curl.ini,/etc/php.d/exif.ini,/etc/php.d/fileinfo.ini,/etc/php.d/ftp.ini,/etc/php.d/gettext.ini,/etc/php.d/gmp.ini,/etc/php.d/iconv.ini,/etc/php.d/json.ini,/etc/php.d/phar.ini,/etc/php.d/shmop.ini,/etc/php.d/simplexml.ini,/etc/php.d/sockets.ini,/etc/php.d/tokenizer.ini,/etc/php.d/xml.ini,/etc/php.d/zip.ini
PHP API20151012
PHP Extension20151012
Zend Extension320151012
Zend Extension BuildAPI320151012,NTS
PHP Extension BuildAPI20151012,NTS
Debug Buildno
Thread Safetydisabled
Zend Signal Handlingdisabled
Zend Memory Managerenabled
Zend Multibyte Supportdisabled
IPv6 Supportenabled
DTrace Supportenabled
Registered PHP Streamshttps, ftps, compress.zlib, php, file, glob, data, http, ftp, compress.bzip2, phar, zip
Registered Stream Socket Transportstcp, udp, unix, udg, ssl, sslv3, sslv2, tls, tlsv1.0, tlsv1.1, tlsv1.2
Registered Stream Filterszlib.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk, bzip2.*, convert.iconv.*
This program makes use of the Zend Scripting Language Engine:
Zend Engine v3.0.0, Copyright(c) 1998-2015 Zend Technologies
Configuration
apache2handler
Apache VersionApache/2.4.6(CentOS)
Apache API Version20120211
Server Administratorxxxxxx@xxxxxx.com
Hostname:Portxxxx.xxxxx.xxx:0
User/Groupapache(48)/48
Max RequestsPer Child: 0- Keep Alive: on- Max Per Connection: 100
TimeoutsConnection: 60- Keep-Alive: 15
Virtual ServerYes
Server Root/etc/httpd
Loaded Modulescore mod_so http_core mod_access_compat mod_actions mod_alias mod_allowmethods mod_auth_basic mod_auth_digest mod_authn_anon mod_authn_core mod_authn_dbd mod_authn_dbm mod_authn_file mod_authn_socache mod_authz_core mod_authz_dbd mod_authz_dbm mod_authz_groupfile mod_authz_host mod_authz_owner mod_authz_user mod_autoindex mod_cache mod_cache_disk mod_data mod_dbd mod_deflate mod_dir mod_dumpio mod_echo mod_env mod_expires mod_ext_filter mod_filter mod_headers mod_include mod_info mod_log_config mod_logio mod_mime_magic mod_mime mod_negotiation mod_remoteip mod_reqtimeout mod_rewrite mod_setenvif mod_slotmem_plain mod_slotmem_shm mod_socache_dbm mod_socache_memcache mod_socache_shmcb mod_status mod_substitute mod_suexec mod_unique_id mod_unixd mod_userdir mod_version mod_vhost_alias mod_dav mod_dav_fs mod_dav_lock mod_lua prefork mod_proxy mod_lbmethod_bybusyness mod_lbmethod_byrequests mod_lbmethod_bytraffic mod_lbmethod_heartbeat mod_proxy_ajp mod_proxy_balancer mod_proxy_connect mod_proxy_express mod_proxy_fcgi mod_proxy_fdpass mod_proxy_ftp mod_proxy_http mod_proxy_scgi mod_proxy_wstunnel mod_ssl mod_systemd mod_cgi mod_perl mod_php7
以上显示 php7安装成功!
如何在CentOS 7服务器上利用Apache安装并hpMyAdmin
在CentOS上安装phpMyAdmin,首先需要架设一台Web服务器(如Apache或nginx),安装好MySQL/MariaDB数据库和PHP。根据你的偏好和需求,你可以从LAMP和LEMP中选择一种安装。
另一个要求是允许在你的CentOS上安装EPEL库。在CentOS6或7上安装phpMyAdmin可以通过以下命令实现。在CentOS 7上:$ sudo yum install phpmyadmin。如果需要php-mcrypt扩展,可以使用:$ sudo yum install phpmyadmin php-mcrypt。
在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。
AddDefaultCharset UTF-8
# Apache 2.4
#Require ip 127.0.0.1
#Require ip::1
Require all granted
# Apache 2.2
Order Deny,Allow
Deny from All
Allow from 127.0.0.1
Allow from::1
# Apache 2.4
#Require ip 127.0.0.1
#Require ip::1
Require all granted
# Apache 2.2
Order Deny,Allow
Deny from All
Allow from 127.0.0.1
Allow from::1
最后,重启httpd使改动生效:$ sudo systemctl restart httpd。
在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。
Order Deny,Allow
# Deny from all
Allow from 0.0.0.0
下一步是将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(CentOS 6)或$ sudo systemctl restart httpd(CentOS 7)。
测试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 yum install php-mcrypt。