阿里云ECS服务器Linux环境下配置php运行环境(安装配置篇)

来源:互联网 发布:利希滕贝格图样 淘宝 编辑:程序博客网 时间:2024/05/16 08:37

阿里云ECS服务器Linux环境安装配置php的运行环境,不同于window操作系统下配置,因为是linux操作系统主要是在命令窗体里输入命令来操作,对于初次接触过linux系统的可能会有点怕怕的,下不去手。。。。。。


需要安装的软件有Apache+PHP+MySQL。


安装Apache


yum install httpd #根据提示,输入Y安装即可成功安装

安装成功后开启Apache,

/etc/init.d/httpd start #启动Apache

Apache启动之后可能会提示错误:

httpd:httpd: Could not reliably determine the server's fully qualif domain name, using ::1 for ServerName

解决方法:

vi /etc/httpd/conf/httpd.conf  #编辑http.conf文件

查找到 #ServerName www.example.com:80

按“i”键代表修改文档

修改为 ServerName localhost:80 #这里设置为你自己的域名,如果没有域名,可以设置为localhost



按“Esc”键退出,然后再按“:wq”#保存退出

chkconfig httpd on #设为开机启动

/etc/init.d/httpd restart #重启Apache服务器


(如果不是很确定在命令窗体能够修改,可以下载一个WinSCP连接服务器后按 /etc/httpd/conf/httpd.conf这个路径查找修改,代码大概在278行,在修改之前把文件格式先转换为utf-8编码,或者先将httpd.conf 文件备份,防止改错了可以替换回去!!


第一步已经完成了,哈哈哈哈!


安装MySQL


yum install mysql mysql-server #根据提示,输入Y安装即可成功安装

/etc/init.d/mysqld start #启动MySQL服务

chkconfig mysqld on #设置为开机启动

cp  /usr/share/mysql/my-medium.cnf  /etc/my.cnf  #拷贝配置文件


接下来就是为mysql的root账号设置密码(默认的密码是空)

mysql_secure_installation 按回车键

如果你是新安装mysql,会弹出提示:

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

因为你是新安装,默认密码为空,直接按enter键就可以。

然后设置新的密码,输入Y即可

输入两次密码确认(一定要记住密码哦!后面设置其他用户还需要用的密码进入MySQL,创建用户等操作)


再接着就是会有若干个提示:

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 aproduction environment.

Remove anonymous users? [Y/n] y

MySQL会默认创建一个匿名用户,问你是否删除,一般输入Y删除掉。


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

root用户默认只能访问localhost,以防有人猜密码,是否禁止root登陆,一般选择yes。


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]

mysql默认创建一个名为test的数据库,这个库任何人都可以访问,是否删除掉,一般不删除。


Reloading the privilege tables will ensure that all changes made so far will take effect immediately.

Reload privilege tables now? [Y/n]

意思是上面的修改是否马上生效:输入Y


最后会出现:Thanks for using MySQL!

MySQL密码设置完成,重新启动MySQL:

/etc/init.d/mysqld restart #重启MySQL服务

设置mysql远程连接

配置mysql允许远程连接的方法

默认情况下,mysql只允许本地登录,如果要开启远程连接,则需要修改/etc/mysql/my.conf文件。

一、修改/etc/mysql/my.conf
找到bind-address = 127.0.0.1这一行
改为bind-address = 0.0.0.0即可

二、为需要远程登录的用户赋予权限
1、新建用户远程连接mysql数据库
grant all on *.* to admin@'%' identified by '123456' with grant option; 
flush privileges;
允许任何ip地址(%表示允许任何ip地址)的电脑用admin帐户和密码(123456)来访问这个mysql server。
注意admin账户不一定要存在。

2、支持root用户允许远程连接mysql数据库
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
flush privileges;

三、查看系统用户



安装php

yum install php #根据提示,输入Y安装即可成功安装


安装其他版本源

CentOS yum 安装 PHP 5.6.24

配置yum源

追加CentOS 6.5的epel及remi源。

# rpm -Uvh http://ftp.iij.ad.jp/pub/linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

以下是CentOS 7.0的源。

# yum install epel-release
# rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

使用yum list命令查看可安装的包(Packege)。

# yum list --enablerepo=remi --enablerepo=remi-php56 | grep php

安装PHP5.6

yum源配置好了,下一步就安装PHP5.6。

# yum install --enablerepo=remi --enablerepo=remi-php56 php php-opcache php-devel php-mbstring php-fpm  php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof

用PHP命令查看版本。

# php --version
PHP 5.6.0 (cli) (built: Sep 3 2014 19:51:31)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies
with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies
with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans

yum install php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt  #根据提示,输入Y安装即可成功安装

/etc/init.d/mysqld restart #重启mysql

/etc/init.d/httpd restart #重启Apache



终于完成了所有软件的安装,现在进行测试一下

安装完成之后在/var/www/ 会有一个html文件夹,这个就是默认的访问路径。

编写一个index.php 文件进行测试

<?php

echo "hello world";

?>



!!!!!!!!!!!!!!!

如果前面的三个安装步骤都成功,而在测试的时候出现访问不了的问题,有可能是因为阿里云ECS服务器里面的安全组设置问题;

解决方法,在云ECS服务器里添加安全组规则;

这里要登录阿里云的控制台--https://www.aliyun.com/

选择云服务器ECS->安全组,找到你的服务器在哪个区,选择配置规则->添加安全组规则





阅读全文
0 0
原创粉丝点击