Ubuntu VPS中安装配置Apache+PHP+Mysql

来源:互联网 发布:哪个linux最适合嵌入式 编辑:程序博客网 时间:2024/06/01 23:22

一、Ubuntu VPS安装后初始设置

1、登录到服务器
使用终端工具登录到服务器,Linux、Mac系统可以使用终端工具进行SSH连接登录,Windows平台可以使用Putty进行登录。
以Putty为例,只需输入IP地址,选择SSH连接,点击OPEN即可,第一次登录可能会弹出安全警告,确认即可,在终端界面输入管理员账户名和密码即可。

2、安装安全更新
博客正在使用的系统是Ubuntu(下面指令均为Ubuntu环境,其它系统指令请参考文末链接),操作指令如下:

sudo apt-get updatesudo apt-get upgrade --show-upgraded

3、修改主机名
默认的主机名是localhost,建议修改掉,不只是为了安全,也方便记忆和识别:

echo "mynewname" > /etc/hostnamehostname -F /etc/hostname

4、设置host映射

vi /etc/hosts127.0.0.1       example.com        localhost12.34.56.78    example.com        mynewname

其中的IP地址12.34.56.78请换成自己的IP地址,下同。

5、设置时区(可选)

dpkg-reconfigure tzdata

二、为Ubuntu VPS安装Apache

1、安装APACHE

apt-get install apache2

2、修改NameVirtualHost入口
输入:

vi /etc/apache2/ports.conf

修改文件:

/etc/apache2/ports.conf

中的NameVirtualHost入口地址。指示监听IP地址:

NameVirtualHost    12.34.56.78

(VI用法,按下i插入操作,ESC进入编译模式,输入冒号:即可运行命令,x保存退出),更多VI命令用法介绍参考Ubuntu网站。

3、修改

/etc/apache2/sites-available/default

文件
设置缺省网站主机为

<VirtualHost 12.34.56.78:80>

这里默认端口为80,一般不用修改。

4、创建各网站配置文件

flush privileges;

6、退出

quit

备注:默认数据库在

/var/lib/mysql

目录下,注意需要把数据库文件夹及文件改为660权限,具体看mysql的运行用户。

四、为VPS安装PHP

1、安装PHP

apt-get install php5 php-pear

2、调整PHP配置

vi /etc/php5/apache2/php.inimax_execution_time = 30memory_limit = 64Merror_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERRORdisplay_errors = Offlog_errors = Onerror_log = /var/log/php-error.logregister_globals = Off

3、重启APACHE

/etc/init.d/apache2 restart

4、让PHP支持MYSQL

apt-get install php5-mysql

5、更新软件包

apt-get update

6、安装php5-suhosin包,增加安全性
安装php5-suhosin之前需注释掉

vi /etc/apt/sources.list

的以下部分:

deb http://us.archive.ubuntu.com/ubuntu/ lucid universedeb-src http://us.archive.ubuntu.com/ubuntu/ lucid universedeb http://us.archive.ubuntu.com/ubuntu/ lucid-updates universedeb-src http://us.archive.ubuntu.com/ubuntu/ lucid-updates universedeb http://security.ubuntu.com/ubuntu lucid-security universedeb-src http://security.ubuntu.com/ubuntu lucid-security universe

然后再进行安装:

apt-get install php5-suhosin

7、安装GD库

apt-get install php5-gd

8、重启APACHE

/etc/init.d/apache2 restart

到这里已经完成安装,接下来就可以上传自己的网站程序,设置域名解析即可。
注意:本文只是自己在Ubuntu下的操作实例,个别操作可能根据实际情况有所不同,如有错误,欢迎指出,不足之处指出完善。

0 0
原创粉丝点击