Home  >  Article  >  Backend Development  >  Analysis of the tutorial on configuring Apache+PHP+PHPmyadmin+MYsql_PHP in Alibaba Cloud ubuntu12.04 environment

Analysis of the tutorial on configuring Apache+PHP+PHPmyadmin+MYsql_PHP in Alibaba Cloud ubuntu12.04 environment

WBOY
WBOYOriginal
2016-07-21 15:02:47753browse

此教程中使用的相关IP等设置,在你的环境中要做相应修改。
使用之前更新apt-get,因为服务器基本上是一个裸系统
apt-get update;
apt-get upgrade;
1 我们使用root账户进行安装,首先切换到root账户,输入命令:
sudo su

2 安装 MySQL 5
输入命令:
apt-get install mysql-server mysql-client
安装过程中需要设置root账户密码,系统会作以下提示:
New password for the MySQL ”root” user:Repeat password for theMySQL ”root” user:

3 安装 Apache2
输入命令:
apt-get install apache2
在浏览器输入你服务器地址列入 http://192.168.0.100查看Apache2是否工作,如果显示(Itworks!),说明已经工作。
Apache 在 Ubuntu 中默认文档根目录为 /var/www,配置文件/etc/apache2/apache2.conf,额外配置存储子目录 /etc/apache2 例如/etc/apache2/mods-enabled (为 Apache 模块), /etc/apache2/sites-enabled(为虚拟主机 virtual hosts), 和 /etc/apache2/conf.d.

4 安装 PHP5
安装 PHP5 和 Apache PHP5 模块:
apt-get install php5 libapache2-mod-php5
(如果有安装的内容找不到,需要更新apt-get,执行apt-get update)
然后重启apache:
/etc/init.d/apache2 restart

5 测试 PHP5 / 可以建立一个探针页面
vi /var/www/info.php
输入下面的内容:
phpinfo();
?>
然后打开浏览器访问 (http://127.0.0.1/info.php):
你可以看到一些已经支持的模块。

6 为PHP5取得 MySQL 支持
我们需要安装 php5-mysql,先查看一下php5的模块
apt-cache search php5-mysql
php5-mysql - MySQL module for php5
php5-mysqlnd - MySQL module for php5 (Native Driver)
然后安装所需模块,例如下面的命令:
apt-get install php5-mysql
apt-get install php5-mysqlnd
sudo apt-get install php5 libapache2-mod-php5 php5-cgi php5-cli php5-common php5-curl php5-gd php5-mysql php5-pgsql
sudo a2enmod php5

差什么php5的模块,就安装php5的模块,ubuntu的php5安装module还是很方便的
以下模块自己选择安装,有些模块不一定正确
apt-get install php5-mysql php5-curl php5-gd php5-intlphp-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mingphp5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidyphp5-xmlrpc php5-xsl
重启 Apache2:
/etc/init.d/apache2 restart
然后刷次你 http://127.0.0.1/info.php 查看模块支持是不是已经增加了。

7 phpMyAdmin
安装phpmyadmin来管理mysql:
apt-get install phpmyadmin
phpmyadmin设置:
在安装过程中会要求选择Web server:apache2或lighttpd,选择apache2,按tab键然后确定。然后会要求输入设置的Mysql数据库密码连接密码Password of the database's administrative user。
然后将phpmyadmin与apache2建立连接,以我的为例:www目录在/var/www,phpmyadmin在/usr/share /phpmyadmin目录,所以就用命令:sudo ln -s /usr/share/phpmyadmin /var/www建立连接。
phpmyadmin测试:在浏览器地址栏中打开http://localhost/phpmyadmin。
Phpmyadmin访问地址:http://127.0.0.1/phpmyadmin/

以上LAMP的基本组件就安装完毕了,下面我们再来看一些其他的设置:
设置Ubuntu文件执行读写权限
LAMP组建安装好之后,PHP网络服务器根目录默认设置是在:/var/www。由于Linux系统的安全性原则,改目录下的文件读写权限是只允许root用户操作的,所以我们不能在www文件夹中新建php文件,也不能修改和删除,必须要先修改/var/www目录的读写权限。在界面管理器中通过右键属性不能修改文件权限,得执行root终端命令:sudo chmod 777 /var/www。然后就可以写入html或php文件了。如果对777表示的文件权限不是很清楚可参考chmod命令。

配置Apache
1启用mod_rewrite模块
终端命令:sudo a2enmod rewrite
重启Apache服务器:sudo /etc/init.d/apache2 restart
Apache重启后我们可以测试一下,在/var/www目录下新建文件test.php,写入代码:保存,在地址栏输入http://127.0.0.1/test.php或http://localhost/test.php,如果正确出现了php配置信息则表明LAMP Apache已经正常工作了(记得重启Apache服务器后再测试)。

2 Set Apache support .htm .html .php
sudo gedit /etc/apache2/apache2.conf
Add AddType application/x-httpd-php .php .htm .html.

Configuring Mysql test
The above PHP and Apache have been tested. Let's test whether the Mysql database has been correctly enabled.
Create a new mysql_test.php in the /var/www directory:

Copy the code The code is as follows:
$link = mysql_connect("localhost","root","020511");
if (!$link)
{
die('Could not connect: ' . mysql_error() );
}
else echo "Mysql has been configured correctly";
mysql_close($link);
?>

Save and exit, enter http in the address bar ://127.0.0.1/mysql_test.php, if "Mysql has been configured correctly" is displayed, it means OK. If not, restart the Apache server and try again.

Configure php5
sudo gedit /etc/php5/apache2/php.ini to modify the maximum allowed memory, find
memory_limit = 8M and modify it to
memory_limit = 32M
Modify the maximum allowed upload size, find
upload_max_filesize = 2M and change it to
upload_max_filesize = 8M
Allow mysql and gd modules, check whether the file contains the following code at the end, if not add it. (By default, it is added at the end of the configuration file, check it just in case)
extension=mysql.soextension=gd.so Save and close the file.

If garbled characters appear, the solution is as follows: Configure apache character encoding:

sudo gedit /etc/apache2/conf.d/charset
Change the content inside to AddDefaultCharset UTF-8

Configure php character encoding:
sudo gedit /etc/php5/apache2/php.ini
Find
code:
default_charset = "iso-8859 -1″
changed to
Code:
default_charset = “UTF-8″
Then restart apache:
Code:
sudo /etc/init.d/apache2 restart t

http://www.bkjia.com/PHPjc/327889.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327889.htmlTechArticleThe relevant IP and other settings used in this tutorial must be modified accordingly in your environment. Update apt-get before use, because the server is basically a bare system apt-get update; apt-get upgrad...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn