Quickly build a LAMP environment under ubuntu and centos of linux

Install the lamp environment under linux, the following is a quick way to install the LAMP environment under ubuntu and centos.


First of all, let us understand what a LAMP environment is (taken from Baidu Encyclopedia) :

Linux+Apache+Mysql/MariaDB+Perl/PHP/Python is a group of open source software commonly used to build dynamic websites or servers. They are all independent programs, but because they are often used together, they have higher and higher Compatibility, together constitute a powerful Web application platform. With the vigorous development of the open source trend, the open source LAMP has formed a tripartite trend with J2EE and .Net commercial software , and the software development project has a lower investment cost in software, so it has attracted the attention of the entire IT community. In terms of website traffic, more than 70% of the visit traffic is provided by LAMP, which is the most powerful website solution.

Software components

Linux
Linux is free and open source software , which means an operating system where the source code is available .
Apache
Apache is the use of the most popular open source of WEB server software.
MySQL
MySQL is a multi-threaded , multi-user SQL database management system .
MySQL has been purchased by Oracle Corporation since January 27, 2010 through SUN . SUN initially acquired MySQL on February 26, 2008.
PHP, Perl or Python
PHP is a programming language originally designed to produce dynamic websites . PHP is an application software mainly used on the server side . Perl is similar to Python.




First introduce the first method, the quick installation method under centos:

Now configure the required components for the system and upgrade the system.

yum -y update
yum -y install gcc gcc-c++ autoconf automake libtool libevent libevent-devel gmp gmp-devel
yum -y install gd gd-devel freetype freetype-devel fontconfig fontconfig-devel libjpeg libjpeg-devel zlib zlib-devel pcre pcre-devel
yum -y install ncurses ncurses-devel libmcrypt mhash

Install mysql
yum -y install mysql mysql-server mysql-devel

Install apache
yum -y install httpd httpd-devel

Install php
yum -y install php53*

Start apache and MySQL
/etc/init.d/httpd restart
/etc/init.d/mysqld restart
So far, our LAMP environment has been set up. Now is to test whether the environment is set up successfully, and check the configuration information.
vi /var/www/html/info.php
 <?php
    phpinfo();
?>
Upload the /var/www/html/ directory and visit http://yourip/info.php to view php information.
The short tag mode is not turned on, so it cannot be displayed normally. You can find short_open_tag in php, ini, and then change its value to on .

Set httpd and MySQL to boot up.
chkconfig httpd on
chkconfig mysqld on

Supplement: each configuration file location
/etc/my.cnf MySQL configuration file
/etc/httpd/ apache configuration file
/etc/php.ini php configuration file
/var/www/html/ Website storage directory

Then, the following is a quick installation method under ubuntu:

Install Apache2:

sudo apt-get install apache2

Install the PHP module:

sudo apt-get install php5

Install Mysql

sudo apt-get install mysql-server

Install phpmyadmin 

Installation of other modules:

sudo apt-get install libapache2-mod-php5

sudo apt-get install libapache2-mod-auth-mysql

sudo apt-get install php5-mysql

sudo apt-get install php5-gd

The first two are easy to understand. If you want apache to be able to parse PHP, you need to use these two modules to find the php engine. The third one is used when php operates the mysql database. Most people have database programming experience, so there is no need to explain more. The fourth GD library.



Here are some notes

在刚刚装完LAMP环境后,我进行了测试,发现在浏览PHP网页时没有显示,而是将PHP网页文件下载了下来,原因是apache的配置里面有点问题,需要设置一下就行了。

以下是apache的简单配置:

1.apache根目录

安装完apache2,根目录在/var/www下,可以通过http://localhost/测试一下是否好用。当然也可以在该目录下新建一个文件test.html来试一试http://localhost/test.html。 

2.PHP解析问题

安装完貌似php的解析都有点问题,浏览php网页会保存,apache没有将其解析为网页。网上一般说的是需要在httpd.conf中添加XXXX,对其他的linux系统可能确实如此,但是ubuntu有点特殊。

ubuntu的apache2配置在/etc/apache2目录下。这个目录下有个apache2.conf文件,这个文件通过包含其他配置文件涵盖了所有的apache2系统配置信息。 php解析部分在的配置在/etc/apache2/mods-available下的php5.conf和php5.load中,apache2.conf文件中并没有将这两个文件包含进来,只要包含进去就OK了。

*************************************************

在apache2.conf中找到    

# Include module configuration:    

Include /etc/apache2/mods-enabled/*.load   

Include /etc/apache2/mods-enabled/*.conf

在其后面添加   

Include /etc/apache2/mods-available/php5.load    

Include /etc/apache2/mods-available/php5.conf*

************************************************

另外一种方法就是将这两个文件链接到mods-enabled目录下:    

sudo ln -s /etc/apache2/mods-available/php5.load /etc/apache2/mods-enabled/php5.load   

sudo ln -s /etc/apache2/mods-available/php5.conf /etc/apache2/mods-enabled/php5.conf

这一种方式更好一点,没有破坏apache2本身的配置结构。

************************************************* 

3.改变apache2的默认目录到当前的开发目录

apache2的默认目录配置在/etc/apache2/sites-enabled/00default文件中。

找到该文件中的DocumentRoot项, 将/var/www改为你的开发目录就OK了。

当然,还有一种方法就是不该边默认目录,只是在var/www下建立一个到你的目录的链接。

比如你的目录在/home/username/phptest,那么你只要

sudo ln -s /home/username/phptest /var/www/phptest

这样你就可以通过http://localhost/phptest访问你的工作目录了。[注意]链接文件名中不能含有“.”,否则apache2会将其当作为一个文件试图解析而无法达到链接目录的效果。

 个人推荐用后一种方式,这样可以多个工作目录并行开发。

配置中常用命令重启apachesudo /etc/init.d/apache2 restart

建立系统链接sudo ln -s a b


参考资料:百度文库



Guess you like

Origin blog.csdn.net/u012457196/article/details/38357211