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 am 10:52 AM
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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

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)

PHP: Handling Databases and Server-Side Logic PHP: Handling Databases and Server-Side Logic Apr 15, 2025 am 12:15 AM

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

PHP's Purpose: Building Dynamic Websites PHP's Purpose: Building Dynamic Websites Apr 15, 2025 am 12:18 AM

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP: An Introduction to the Server-Side Scripting Language PHP: An Introduction to the Server-Side Scripting Language Apr 16, 2025 am 12:18 AM

PHP is a server-side scripting language used for dynamic web development and server-side applications. 1.PHP is an interpreted language that does not require compilation and is suitable for rapid development. 2. PHP code is embedded in HTML, making it easy to develop web pages. 3. PHP processes server-side logic, generates HTML output, and supports user interaction and data processing. 4. PHP can interact with the database, process form submission, and execute server-side tasks.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

How to build a Zookeeper cluster in CentOS How to build a Zookeeper cluster in CentOS Apr 14, 2025 pm 02:09 PM

Deploying a ZooKeeper cluster on a CentOS system requires the following steps: The environment is ready to install the Java runtime environment: Use the following command to install the Java 8 development kit: sudoyumininstalljava-1.8.0-openjdk-devel Download ZooKeeper: Download the version for CentOS (such as ZooKeeper3.8.x) from the official ApacheZooKeeper website. Use the wget command to download and replace zookeeper-3.8.x with the actual version number: wgethttps://downloads.apache.or

Centos install mysql Centos install mysql Apr 14, 2025 pm 08:09 PM

Installing MySQL on CentOS involves the following steps: Adding the appropriate MySQL yum source. Execute the yum install mysql-server command to install the MySQL server. Use the mysql_secure_installation command to make security settings, such as setting the root user password. Customize the MySQL configuration file as needed. Tune MySQL parameters and optimize databases for performance.

How to solve CentOS system failure How to solve CentOS system failure Apr 14, 2025 pm 01:57 PM

There are many ways to solve CentOS system failures. Here are some common steps and techniques: 1. Check the log file /var/log/messages: system log, which contains various system events. /var/log/secure: Security-related logs, such as SSH login attempts. /var/log/httpd/error_log: If you use the Apache server, there will be an error message here. 2. Use the diagnostic tool dmesg: display the contents of the kernel ring buffer, which helps understand hardware and driver questions

See all articles