Configure the LAMP environment on Ubuntu
The configuration of the LAMP environment is divided into three parts: installation, configuration and testing.
1. Install
Install Apachesudo apt-get install apache2
After Apache2 is installed, a new www directory/var/www/will be created/
Install MySQL
Sudo apt-get install mysql-server mysql-client
During installation, the system prompts you to enter the root user password.
Install PHP
Sudo apt-get install php5 libapache2-mod-php5
After installation, restart Apache to load the php module.
Sudo/etc/ini. d/apache2 restart
2. Configuration
(The following configuration file is opened by using vim or another text editor)
Configure Apachesudo vim/etc/apache2/apache2.conf
Open the configuration file and add the content at the end of the document.
First, add type support
AddType application/x-httpd-php. php. html. htm
Then, add the default character set as needed.
Adddefacharcharset UTF-8
Then, add the access sequence of the home page files as needed. The previous access sequence takes precedence.
<IfModule dir_module>
DirectoryIndex index.htm index.html index. php
</IfModule>
Finally, modify the default path of Apache (that is, the www directory)
Open related configuration files
Sudo vim/etc/apache2/sites-enabled/000-default.conf
Find DocumentRoot/var/www/html
Change to DocumentRoot/var/www
Restart apache to make the configuration take effect.
Sudo/etc/init. d/apache2 restart
3. Test
Test Apache
Always open ingress in the browser
Test MySQL
Total input at the terminal
Sudo netstat-tap | grep mysql
If you can see the words tcp 0 0 localhost: mysql 1060/mysqld, the configuration is successful.
If not, restart mysqlsudo/etc/init. d/mysql restart.
Test PHP
First, modify the permissions of the www directory.
Sudo chmod-R 777/var/www
Create a test. php test file in the www directory.
Cd/var/www
Sudo touch test. php
Sudo vim test. php
Then write the following code in the test file to call a phpinfo () function.
<? Php
Phpinfo ();
?>
After saving it, browse localhost/test. php In the browser. If you can see a page showing the php parameter amount, it indicates that the php configuration is successful.