Linux/ubuntu下安装LAMP (开启重写模块apache rewrite) How-to Install LAMP Server
  4yu2JdefgeRW 2023年11月02日 35 0


Linux LAMP servers are also popular, flexible and reliable as WAMP server. The installation of both servers are very easy and differ from each other. LAMP means L inux A pache M ysql P hp, and WAMP is for Windows. WAMP server installs automatically(installer),you are able to use server without touching setting files. While LAMP server installs with commands. Here, I am going to show how to install LAMP server through Terminal on Ubuntu.

 

LAMP Installation:

To install LAMP server, open up a Terminal window(Ctrl+Alt+t ), and type the following commands.

All commands have written in italic words and remember Terminal commands are case sensitive!!

 

To install Apache:



sudo apt-get install apache2



 

Now to confirm the installation of Apache2 open http://127.0.0.1 in your web browser, you will see It Works! default page of Apache.

 

To install Mysql:



sudo apt-get install mysql-server



 

At the installation you be will asked to provide a root password for Mysql.

To install php:



sudo apt-get install php5 libapache2-mod-php5



 

After this installation restart Apache [sudo /etc/init.d/apache2 restart don’t write brackets.

Now make a phpinfo.php file and save that in /var/www to do this use [sudo gedit /var/www/phpinfo.php ] write a code in this file

 

<?php
phpinfo();
?>

 

Now open http://127.0.0.1/phpinfo.php

 

To install phpmyadmin:



sudo apt-get install phpmyadmin



 

 

Two option window will open in installation one for web server reconfigure automatically[ select apache2] and second for configure database for phpmyadmin with dbconfig-common [ select No] .

 

 

You will need to copy the apache.conf to /etc/apache2/conf.d/ from /etc/phpmyadmin/ or the page will return a 404 error. To copy Run-



sudo cp /etc/phpmyadmin/apache.conf /etc/apache2/conf.d



 

13.10之后可以尝试



sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-enabled/phpmyadmin.conf



 

Now you have to restart your apache server



sudo /etc/init.d/apache2 restart



 

此时如果出现“apache2: Could not reliably determine the server's fully qualified domain name” 这样的错误,你可以打开文件/etc/apache2/apache2.conf 末尾添加代码 ServerName localhost 即可,详情看本文下方。

 

Now open http://127.0.0.1/phpmyadmin

 

 

Read : Lamp Installation through Tasksel

 

If you want to start blogging and interested in the field of earning money online. Then you should install WordPress CMS to make blog or site. For WordPress installation you should see my tutorial of WordPress installation .

 

Hope this will helpful for you, for any query or help post comments. Your feedback helps us.

 

来源:http://tech.mobiletod.com/how-to-install-lamp-serverapache-mysql-php-on-ubuntu-10-10/

 

Ubuntu LAMP 如何配置Apache

1. 修改文件夹读写权限

PHP网络服务器根目录默认位置:/var/www,默认属性只允许root用户执行操作,但是在Ubuntu中因为安全性的考虑默认关闭了 root账户。为了可以在这个文件夹新建修改php、html文件等等,可以通过终端命令行修改文件夹的这个属性:



sudo chmod 777 /var/www



 

2. 启用 mod_rewrite 模块



#终端命令: sudo a2enmod rewrite #重启Apache服务器: sudo /etc/init.d/apache2 restart



 

Apache重启后我们可以测试一下,在/var/www目录下新建文件test.php,写入代码:  <?php phpinfo(); ?> 保存,在地址栏输入http://127.0.0.1/test.php 或 http://localhost/test.php ,如果正确出现了php 配置信息则表明LAMP Apache已经正常工作了(记得重启Apache服务器后再测试)。

 

如何测试是否已经开启地址重写?查看这里

 

如果还是不行的话,可以考虑编辑  /etc/apache2/apache2.conf



<Directory /your/path> AllowOverride All </Directory>



 

同时还需要考虑的文件是:your site virtual host file or edit the 000-default in the /etc/apache2/sites-enabled/

 

Add this lines:



<Directory /var/www/mysite/> AllowOverride all </Directory>


 


<Directory /> Options FollowSymLinks AllowOverride None </Directory>


 

If you get a 500 type of error

This happens because the rewrite module doesn’t come enabled by default for security reasons.

Create a new file called rewrite.conf in _/etc/apache2/mods-enabled_
in the file put this line “LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so”

Reload one more time the server.

 

3. 设置Apache支持.htm .html .php



sudo gedit /etc/apache2/apache2.conf #或 sudo gedit /etc/apache2/mods-enabled/php5.conf

在打开的文件中加上


AddType application/x-httpd-php .php .htm .html 即可。


 

解决Firefox浏览器显示中文乱码等问题

上面在FireFox浏览器中打开mysql_test.php或phpmyadmin测试时,如果出现了中文乱码,则是默认语言设置问题,解决方法如下:

打开apache配置文件: udo gedit /etc/apache2/apache2.conf,在最后面加上:AddDefaultCharset UTF-8 ,如果还是乱码的,再将UTF-8改用gb2312。
重启Apache:sudo /etc/init.d/apache2 restart  再刷新mysql_test.php 中文乱码没有了。

如果要人工启动mysql:mysql -u root -p,根据提示输入密码。
如果重启Apache时出现:
* Restarting web server apache2
apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName
apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName

则还是修改apache配置文件:sudo gedit /etc/apache2/apache2.conf,在文件最后设置:ServerName 127.0.0.1

LAMP组件经常使用的几个终端命令



#重启 apache: sudo /etc/init.d/apache2 restart #重启mysql: sudo /etc/init.d/mysql restart #配置 php.ini: sudo gedit /etc/php5/apache2/php.ini #配置 apache2.conf: sudo gedit /etc/apache2/apache2.conf #配置 my.cnf: sudo gedit /etc/mysql/my.cnf #PHP CGI : sudo /var/www/cgi-bin/



修改phpmyadmin/phpmygoodadmin导入文件大小限制

找到php.ini文件


#sudo gedit /etc/php5/apache2/php.ini upload_max_filesize = 50M post_max_size = 50M memory_limit = 128M #sudo /etc/init.d/apache2 restart


Ubuntu PHP 编辑器

最后LAMP配置就完成了,在Ubuntu下进行简单的php代码编辑,用Gedit就可以了。Gedit支持HTML,PHP,Javascsript等近几十种语言的代码高亮功能。如果是PHP项目开发,建议使用PHP IDE编辑器,比如Zend Studio,Eclipse。据说文本编辑VIM也很不错。

 

Could not reliably determine the server's fully qualified domain name?

Restarting web server apache2
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
... waiting apache2:
Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName

 

This is just a friendly warning and not really a problem (as in that something does not work).

If you insert a



ServerName localhost

 


 

in either httpd.conf or apache2.conf in /etc/apache2

If you have a name inside /etc/hostname you can also use that name instead of localhost.


And it uses 127.0.1.1 if it is inside your /etc/hosts:

127.0.0.1 localhost
127.0.1.1 myhostname

Preferred method

Troubleshooting Apache

If you get this error:

apache2: Could not determine the server's fully qualified domain name, 
using 127.0.0.1 for ServerName

then use a text editor such as "sudo nano" at the command line or "gksudo gedit" on the desktop to create a new file,

sudo nano /etc/apache2/conf.d/fqdn

or

gksu "gedit /etc/apache2/conf.d/fqdn"

then add

ServerName localhost

to the file and save. This can all be done in a single command with the following:

echo "ServerName localhost" | sudo tee /etc/apache2/conf.d/fqdn

But on Ubuntu 14.04:

echo "ServerName localhost" | sudo tee /etc/apache2/conf-available/fqdn.conf
sudo ln -s /etc/apache2/conf-available/fqdn.conf /etc/apache2/conf-enabled/fqdn.conf

Don't forget the ".conf" (without will not work).

 


 

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
4yu2JdefgeRW