我们更多的网站服务器是选择了Linux系统,这里建议你选择centos,这也是阿里云ecs推荐的系统,在服务器上比较推荐centos,特别对于新手,首选CentOS,并不是centos比Debian和ubuntu好,而是centos是初学者安装vps的首选,它既稳定,占用资源又少此版本生命周期较长,而且网上有关centos的教程很多,方便学习,我们这里选择了Centos7.2,采用yum在线安装。
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
rpm -qa | grep httpd
或者:
apachectl -v
或者:
httpd -v
service mysqld start
如果未被识别则没有安装
如果系统安装过,或者安装失败,清理一下系统
yum remove mysql
rm -f /etc/my.cnf
rpm -qa|grep httpd
注意:如果是新的系统或者你从来没有尝试安装过,则以上步骤省略。
[root@localhost ~]# yum -y install httpd
直到返回
......
Installed:
httpd.x86_64 0:2.4.6-40.el7.centos.4
Dependency Installed:
apr.x86_64 0:1.4.8-3.el7 apr-util.x86_64 0:1.5.2-6.el7
httpd-tools.x86_64 0:2.4.6-40.el7.centos.4 mailcap.noarch 0:2.1.41-2.el7
Complete!
表示安装成功!
[root@localhost ~]# yum -y install php
直到返回:
......
Installed:
php.x86_64 0:5.4.16-36.3.el7_2
Dependency Installed:
libzip.x86_64 0:0.10.1-8.el7 php-cli.x86_64 0:5.4.16-36.3.el7_2
php-common.x86_64 0:5.4.16-36.3.el7_2
Complete!
[root@localhost ~]# yum -y install php-fpm
直到返回:
Installed:
php-fpm.x86_64 0:5.4.16-36.3.el7_2
Complete!
[root@localhost ~]# yum -y install mysql
直到返回:
Installed:
mariadb.x86_64 1:5.5.50-1.el7_2
Dependency Updated:
mariadb-libs.x86_64 1:5.5.50-1.el7_2
Complete!
7.2版本的Centos已经把mysql更名为mariadb,表示安装成功!
[root@localhost ~]# yum -y install mysql-server
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirror.lzu.edu.cn
* extras: mirrors.nwsuaf.edu.cn
* updates: mirrors.tuna.tsinghua.edu.cn
No package mysql-server available.
Error: Nothing to do
CentOS 7+ 版本将MySQL数据库软件从默认的程序列表中移除,用mariadb代替了,entos7配置教程上,大多都是安装mariadb,因为centos7默认将mariadb视作mysql。
因为mysql被oracle收购后,原作者担心mysql闭源,所以又写了一个mariadb,这个数据库可以理解为mysql的分支。如果需要安装mariadb,只需通过yum就可。
yum install -y mariadb
yum install -y mariadb-server
wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum install mysql-community-server
然后需要确定,输入y回车即可
Install 3 Packages (+8 Dependent packages)
Total download size: 82 M
Is this ok [y/d/N]:
一直选择输入 y ,有两次选择,直到返回:
Replaced:
mariadb.x86_64 1:5.5.50-1.el7_2 mariadb-libs.x86_64 1:5.5.50-1.el7_2
Complete!
安装成功!!!
yum -y install php-mysql
直到返回:
Installed:
php-mysql.x86_64 0:5.4.16-36.3.el7_2
Dependency Installed:
php-pdo.x86_64 0:5.4.16-36.3.el7_2
Complete!
安装成功!!!
yum -y install httpd-manual mod_ssl mod_perl mod_auth_mysql
返回
......
Installed:
httpd-manual.noarch 0:2.4.6-40.el7.centos.4
mod_ssl.x86_64 1:2.4.6-40.el7.centos.4
Complete!
安装成功!!!
yum -y install php-gd php-xml php-mbstring php-ldap php-pear php-xmlrpc php-devel
返回:
......
Dependency Updated:
pcre.x86_64 0:8.32-15.el7_2.1
Complete!
安装成功!!!
yum -y install mysql-connector-odbc mysql-devel libdbi-dbd-mysql
返回:
......
Dependency Installed:
libdbi.x86_64 0:0.8.4-6.el7 libdbi-drivers.x86_64 0:0.8.3-16.el7
unixODBC.x86_64 0:2.3.1-11.el7
Complete!
安装成功!!!
systemctl start httpd.service #启动apache
systemctl stop httpd.service #停止apache
systemctl restart httpd.service #重启apache
systemctl enable httpd.service #设置apache开机启动
#启动MariaDB
systemctl start mariadb.service
#停止MariaDB
systemctl stop mariadb.service
#重启MariaDB
systemctl restart mariadb.service
#设置开机启动
systemctl enable mariadb.service
service mysqld restart #centOs7以前用处(与下行二选一)
service mariadb restart #centOs7以后用此
service php-fpm start
service httpd restart
初次安装mysql是没有密码的,我们要设置密码,mysql的默认账户为root
设置 MySQL 数据 root 账户的密码:
[root@localhost ~]# mysql_secure_installation
1.当出现如下提示时候直接按回车(不要输入任何东西直接回车):
Enter current password for root
2.出现如下再次回车:
Set root password? [Y/n]
3.出现如下提示输入你需要设置的密码,这里输入了root,输入密码是不显示的,回车后再输入一次确认:
New password:
4.接下来还会有四个确认,分别是:
Remove anonymous users? [Y/n]
Disallow root login remotely? [Y/n]
Remove test database and access to it? [Y/n]
Reload privilege tables now? [Y/n]
5.直接回车即可。
进入apache的web根目录:/var/www/html 中写一个最简单的php测试页面
cd /var/www/html
touch phpinfo-test.php
vi phpinfo-test.php
Phpinfo Test.php";
phpinfo()
?>
按 esc 退出编辑模式,回到控制模式,输入 :wq 然后回车,在浏览器中输入服地址http://localhost/phpinfo-test.php
出现下图则成功
我们采用了yum在线安装,版本都是默认的Php是5.4,apache的版本是Server version: Apache/2.4.6 (CentOS)