本教程将说明如何安装开发环境 LAMP。 但是,LAMP是什么? LAMP的缩写 Linux + Apache2 + PHP5 + MySQL,即编写脚本,维护或设置由其制作或编写的网站的环境 PHP 同 MySQL 在Apache服务器上。
开始解决此事...
我们安装Apache2
server@host:# apt-get install apache2 apache2-doc
Apache的基本用法:
server@host:# /etc/init.d/apache2 {start|stop|restart|reload|force-reload}
现在,我们如何告诉Apache2使用为其安装的模块?
编辑中 /etc/apache2/apache2.conf 并添加:
<IfModule dir_module>
DirectoryIndex index.html index.htm index.shtml index.cgi index.php index.php3 index.pl index.xhtml
</IfModule>
添加模块:
可以在找到 / usr / lib / apache2 /模块/
例如: mod_rewrite的 覆盖网址以使其更加用户友好。
加入 /etc/apache2/apache2.conf:
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
一种更优雅的方法是,从命令终端使用以下命令启用它:
server@host:# a2enmod rewrite
然后重启Apache:
server@host:# /etc/init.d/apache2 restart
PHP5安装/配置
server@host:# apt-get install libapache2-mod-php5 php5 php5-common php5-curl php5-dev php5-gd php5-idn php-pear php5-imagick php5-imap php5-json php5-mcrypt php5-memcache php5-mhash php5-ming php5-mysql php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl
对PHP 5的一些更改
En /etc/php5/apache2/php.ini:
将文件上传到服务器[大小]:
upload_max_filesize = 8M
内存使用情况:
memory_limit = 32M
上传文件,POST方法:
post_max_size = 8M
启动,重新启动PHP 5?
PHP 5作为Apache2模块在系统上运行,因此,如果仅通过重新启动Apache在PHP5中进行一些配置,则所做的更改将被应用。
MySQL安装/配置
server@host:# apt-get install mysql-server
在安装过程中,系统会要求您提供MySQL root用户的密码,出于安全原因,请尝试使其与系统的root用户密码不同。
MySQL的基本用法:
server@host:# /etc/init.d/mysql {start|stop|restart|reload|force-reload|status}
并在设置[/etc/mysql/my.cnf,大约第71行],我们将取消注释日志:
log /var/log/mysql/mysql.log
然后重新启动MySQL以使更改生效...
server@host:# /etc/init.d/mysql restart
PHPMyAdmin的安装/配置
server@host:# apt-get install phpmyadmin
配置位于config.inc.php文件中,该文件不存在,但是我们将使用以下内容创建它:
<?php
$cfg['blowfish_secret'] = 'phpmyadmin';
$i = 0;
$i++;
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['extension'] = 'mysql';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['auth_type'] = 'cookie';
?>
虚拟主机
这是一种允许在同一IP地址下发布多个[具有多个不同域名]网站的方法。 使您可以更有效地共享内存和处理器周期[Hz]。
用于VirtualHosting的Apache2命令:
- a2ensite:激活一个网站。 配置必须在 / etc / apache2 /网站可用/
- a2dissite:停用网站。
- a2enmod:激活可用于以下版本的apache模块 / etc / apache2 / mods-可用/
- a2dismod:停用模块。
创建一个虚拟主机
我们创建VirtualHost配置文件:
server@host:# cd /etc/apache2/sites-available/
server@host:/etc/apache2/sites-available# touch blog.example.com
我们创建网站所在的文件夹...
server@host:# mkdir -p /var/www/blog/
Blog.example.com配置:
<VirtualHost *:80>
ServerAdmin admin@blog.example.com
ServerName blog.example.com
DocumentRoot /var/www/blog/
# HTML documents, with indexing.
<Directory />
Options +Includes
</Directory>
</VirtualHost>
我们启用:
server@host:# a2ensite blog.example.com
接着? 当然,幸福的结局:
server@host:# /etc/init.d/apache2 restart
注意:如果情况更好,我们应该与网络管理员联系,在DNS中添加一条A记录,该记录指向我们的IP,名称为“博客”。 必须这样做才能将所有DNS轮询从blog.example.com重定向到我们的PC。
然后,我们只需在浏览器中编写:
http://blog.example.com
我们将可以访问有问题的网站。
如果我们要从头开始或从框架进行开发,仅需在此虚拟主机上安装WordPress或Drupal。
就是这样,下次再见,继续在GNU / Linux系统上安装/配置服务。