Table of Contents
Ubuntu环境下如何安装LAMP组件?
设置Ubuntu文件执行读写权限
如何安装phpmyadmin-Mysql 数据库管理
Ubuntu LAMP 如何配置Apache
LAMP配置之Mysql测试
解决Firefox浏览器显示中文乱码等问题
LAMP组件经常使用的几个终端命令
Ubuntu PHP 编辑器
还有一种更为简单的一键安装方式:
Home Backend Development PHP Tutorial UBUNTU 轻便一键安装LAMP和配置phpmyadmin

UBUNTU 轻便一键安装LAMP和配置phpmyadmin

Jun 13, 2016 pm 01:10 PM
apache lamp mysql php phpmyadmin

UBUNTU 轻松一键安装LAMP和配置phpmyadmin

wangking 写道
本文转自远方博客:http://farlee.info/archives/linux-ubuntu-lamp-apache-mysql-php-phpmyadmin-install-configuration.html

?

PHP开发和服务器运行环境首选LAMP组合,即Linux+Apache+Mysql+Php/Perl/Python,能最优化服务器性能。如何在本地电脑Ubuntu 中安装和配置LAMP环境搭建?Ubuntu9.10本身就是基于Linux内核,所以Linux是现成的了。使用Ubuntu LAMP Server软件包可以很简单地实现Linux下Apache,Mysql和Php的统一安装和配置,也不再需要一个一个来安装配置了。

Ubuntu环境下如何安装LAMP组件?

使用Ubuntu界面管理器
系统->系统管理->新立得软件包管理器->编辑->使用任务标记分组软件包->LAMP Server(勾选)->确定->返回到上一个窗口点击应用(或System->Administration->Synaptic Package Manager->Edit->Mark packages by Task->LAMP Server->OK)。然后系统会自动下载安装lamp环境软件包,几分钟就下载搞定。安装过程中会要求设置Mysql root帐号的密码,设置好了记住。另外当Ubuntu系统升级时lamp环境组件也会同时更新到最新版本。

安装完毕测试:打开Firefox浏览器在地址栏输入127.0.0.1,显示It works!表明Apache服务器已经开始工作了,LAMP安装也就这样完成了。



?

Linux ubuntu LAMP 安装配置环境-It Works

当然不使用Gnome,使用终端命令也很简单:
直接一条命令:apt-get install apache2 mysql-server mysql-client php5 php5-gd php5-mysql

设置Ubuntu文件执行读写权限

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

如何安装phpmyadmin-Mysql 数据库管理

使用界面管理器
系统->系统管理->新立得软件包管理器->搜索 phpmyadmin->右键标记安装。
或直接使用一条命令:sudo 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。

Ubuntu LAMP 如何配置Apache

1. 启用 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服务器后再测试)。

2.设置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 即可。

LAMP配置之Mysql测试

上面php,Apache 都已经测试过了,下面我们再测试一下Mysql 数据库是否已经正确启用。

在/var/www目录下新建 mysql_test.php:

<?php $link = mysql_connect("localhost","root","020511");
if (!$link)
{
die('Could not connect: ' . mysql_error());
}
else echo "Mysql已经正确配置";
mysql_close($link);
?>
Copy after login

保存退出,在地址栏输入http://127.0.0.1/mysql_test.php,显示”Mysql 已经正确配置”则表示OK了,如果不行,重启Apache服务器后再试一下。

解决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/

Ubuntu PHP 编辑器

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

PS:如果是Windows XP 下要搭建LAMP 环境,建议大家试试xampp快速安装配置法,使用也很方便快捷,点击前面的超级链接或Google一下就知道怎么用了。

?

还有一种更为简单的一键安装方式:

?

?wangking写道

一键安装LAMP服务:
sudo tasksel install lamp-server

一键卸载LAMP:

sudo tasksel remove lamp-server

注意:

通过上面的命令卸载Lamp时不免把Linux系统本身的东西卸载掉了,因此,

在卸载LAMP后一定记着更新一下系统

sudo apt-get update

sudo apt-get upgrade

上面两条都要执行

?

?

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1266
29
C# Tutorial
1239
24
Explain the purpose of foreign keys in MySQL. Explain the purpose of foreign keys in MySQL. Apr 25, 2025 am 12:17 AM

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.

Compare and contrast MySQL and MariaDB. Compare and contrast MySQL and MariaDB. Apr 26, 2025 am 12:08 AM

The main difference between MySQL and MariaDB is performance, functionality and license: 1. MySQL is developed by Oracle, and MariaDB is its fork. 2. MariaDB may perform better in high load environments. 3.MariaDB provides more storage engines and functions. 4.MySQL adopts a dual license, and MariaDB is completely open source. The existing infrastructure, performance requirements, functional requirements and license costs should be taken into account when choosing.

NGINX and Apache: Understanding the Key Differences NGINX and Apache: Understanding the Key Differences Apr 26, 2025 am 12:01 AM

NGINX and Apache each have their own advantages and disadvantages, and the choice should be based on specific needs. 1.NGINX is suitable for high concurrency scenarios because of its asynchronous non-blocking architecture. 2. Apache is suitable for low-concurrency scenarios that require complex configurations, because of its modular design.

MySQL: The Database, phpMyAdmin: The Management Interface MySQL: The Database, phpMyAdmin: The Management Interface Apr 29, 2025 am 12:44 AM

MySQL and phpMyAdmin can be effectively managed through the following steps: 1. Create and delete database: Just click in phpMyAdmin to complete. 2. Manage tables: You can create tables, modify structures, and add indexes. 3. Data operation: Supports inserting, updating, deleting data and executing SQL queries. 4. Import and export data: Supports SQL, CSV, XML and other formats. 5. Optimization and monitoring: Use the OPTIMIZETABLE command to optimize tables and use query analyzers and monitoring tools to solve performance problems.

Using Apache: Building and Hosting Websites Using Apache: Building and Hosting Websites Apr 25, 2025 am 12:07 AM

Apache is an open source web server software that is widely used in website hosting. Installation steps: 1. Install using the command line on Ubuntu; 2. The configuration file is located in /etc/apache2/apache2.conf or /etc/httpd/conf/httpd.conf. Through module extensions, Apache supports static and dynamic content hosting, optimizes performance and security.

Composer: Aiding PHP Development Through AI Composer: Aiding PHP Development Through AI Apr 29, 2025 am 12:27 AM

AI can help optimize the use of Composer. Specific methods include: 1. Dependency management optimization: AI analyzes dependencies, recommends the best version combination, and reduces conflicts. 2. Automated code generation: AI generates composer.json files that conform to best practices. 3. Improve code quality: AI detects potential problems, provides optimization suggestions, and improves code quality. These methods are implemented through machine learning and natural language processing technologies to help developers improve efficiency and code quality.

How to uninstall MySQL and clean residual files How to uninstall MySQL and clean residual files Apr 29, 2025 pm 04:03 PM

To safely and thoroughly uninstall MySQL and clean all residual files, follow the following steps: 1. Stop MySQL service; 2. Uninstall MySQL packages; 3. Clean configuration files and data directories; 4. Verify that the uninstallation is thorough.

An efficient way to batch insert data in MySQL An efficient way to batch insert data in MySQL Apr 29, 2025 pm 04:18 PM

Efficient methods for batch inserting data in MySQL include: 1. Using INSERTINTO...VALUES syntax, 2. Using LOADDATAINFILE command, 3. Using transaction processing, 4. Adjust batch size, 5. Disable indexing, 6. Using INSERTIGNORE or INSERT...ONDUPLICATEKEYUPDATE, these methods can significantly improve database operation efficiency.

See all articles