#1045 unable to log on to phpMyAdmin and cannot connect to the MySQL server. Install the lamp tutorial on Ubuntu first.

Source: Internet
Author: User

In Linux, configure and install Apache, PHP, and MySQL. Follow the online tutorial step by step, but it gets stuck at the first step. I think I have never set any user names. I searched today, it turns out that the default user name in his system is root, and he is a zombie...

Install

Of course, if you do not use gnome, it is easy to use terminal commands:

Run the following command:

apt-get install apache2 mysql-server mysql-client php5 php5-gd php5-mysql

Set the Ubuntu File Read and Write Permissions

After lamp is installed, the default root directory of the PHP network server is/var/www. Due to the security principle of Linux, only root users are allowed to change the file read and write permissions under the directory. Therefore, you cannot create or delete PHP files in the WWW folder, you must first modify the read and write permissions of the/var/WWW directory. You cannot modify the File Permission by right-clicking the attribute in the interface manager. You must run the root terminal command:

sudo chmod 777 /var/www

. Then you can write HTML or PHP files. If you are not clear about the file permissions indicated by 777, refer to the CHMOD command.

How to install phpMyAdmin-MySQL Database Management

Use the interface Manager:

System-> System Management-> New Software Package Manager-> Search phpMyAdmin-> right-click to mark installation.

Or directly use a command:

sudo apt-get install phpmyadmin 

Installation starts.

PhpMyAdmin settings:

During the installation process, You must select Web server: apache2 or Lighttpd, select apache2, press the tab key, and click OK. Then, you are required to enter the MySQL Database Password of the database's administrative user.

Then, establish a connection between phpMyAdmin and apache2. Take my example: the WWW directory is in the/var/WWW directory, and the phpMyAdmin directory is in the/usr/share/phpMyAdmin directory. Therefore, run the following command:

sudo ln -s /usr/share/phpmyadmin /var/www 

Establish a connection.

PhpMyAdmin test: Open http: // localhost/phpMyAdmin in the address bar of the browser.

How to configure Apache in Ubuntu Lamp

1. Enable mod_rewrite module

Terminal command:

sudo a2enmod rewrite

Restart the Apache server:

sudo /etc/init.d/apache2 restart

After Apache is restarted, we can test it. Create the file test. php in the/var/WWW directory and write the code:

  <?php phpinfo(); ?> 

Save and enter http: // 127.0.0.1/test in the address bar. PHP or http: // localhost/test. PHP. If the correct PHP configuration information appears, it indicates that lamp Apache is working properly (remember to restart the Apache server before testing ).

2.set apacheto support .htm. html. php

sudo gedit /etc/apache2/apache2.conf

Or

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

Add

AddType application/x-httpd-php .php .htm .html

You can.

MySQL test of lamp Configuration

The above PHP and Apache have been tested. Next we will test whether the MySQL database has been correctly enabled.

Create mysql_test.php in the/var/WWW directory:

<? PHP $ link = mysql_connect ("localhost", "root", "020511"); If (! $ Link) {die ('could not connect: '. mysql_error ();} else echo "MySQL has been correctly configured"; mysql_close ($ link);?>

Save and exit. Enter http: // 127.0.0.1/mysql_test.php in the address bar. If "MySQL has been correctly configured", it indicates OK. If not, restart the Apache server and try again.

Run the following command to install lamp:

$sudo  tasksel

Enter the administrator password and select lamp server.

Enter the MySQL password

The program starts to be downloaded and the installation is complete.

After installation, enter the server address in the browser. Generally, 127.0.0.1 is entered by default.

 

Appears

It works!

This is the default web page for this server.

The web server software is running but no content has been added, yet.

Indicates that Apache is running.

 

Next, check the MySQL operation:

Command Line input:

mysql -u root -p

If the operation is normal as follows, and50 @ ander50-desktop :~ $ Mysql-u root-penter password: Welcome to the MySQL monitor. commands end with; or/g. your MySQL connection ID is 40 server version: 5.1.41-3ubuntu12. 3 (UBUNTU) type 'help; 'or'/H' for help. type '/C' to clear the current input statement.

Mysql>

Enter Password

Configuration Overview

1. Configure PhP5

Command:

sudo gedit /etc/php5/apache2/php.ini

Modify the maximum memory usage allowed.

memory_limit = 8M

Change

memory_limit = 32M

Modify the maximum size allowed for upload and search

upload_max_filesize = 2M

Change

upload_max_filesize = 8M

Allow the MySQL and Gd modules to check whether the file finally contains the following code, if not added. (It is added at the end of the configuration file by default. Check it just in case)

extension=mysql.soextension=gd.so

Save and close the file.
Ii. Configure Apache
1. The configuration file in Ubuntu is in/etc/apache2, and apache2.conf is a global configuration or master configuration file, httpd. conf is a user configuration file. It is often used in PHP programming. PHP overwrites config. default. the settings in the PHP file are the same. The user settings are independent to facilitate management and backup. After all, the main configuration file is rarely modified. You can occasionally write one or two modifications to httpd. conf, convenient backup
Add a line to/etc/apache2/httpd. conf:

ServerName 127.0.0.1

Command:

sudo gedit /etc/apache2/httpd.conf

2. The following section is found on the official website.
Edit/etc/apache2/apache2.conf (the newly installed system may be in/etc/apache2/CONF. d/charset) file. Before modification, back up the configuration file. In this way, you can recover an error. Set

AddDefaultCharset ISO-8859-1

Change

AddDefaultCharset GB2312

Of course, if your website code uses a UTF-8, you can also change

AddDefaultCharset UTF-8 

In this way, we won't go through the garbled code every time we open the web page!
3. Add a security module to ensure the normal operation of the Apache service. Now we have installed mod-security. (Optional)
A. Install the libapache2-mod-security package first (this package is no longer available for the system after 7.10, skip this step)

sudo apt-get install libapache2-mod-security

A. this module is not activated by default, we can see a mod-security.load file in the/etc/apache2/mod-available Directory, but there is no soft link in the/etc/apache2/mod-enabled directory. Now we activate it:

$sudo a2enmod mod-security$sudo cp /usr/share/doc/libapache2-mod-security/examples/httpd2.conf.example-full /etc/apache2/mods-available/mod-security.conf$sudo cp /etc/apache2/mods-available/mod-security.conf /etc/apache2/mods-available/mod-security.conf.orig$sudo vi /etc/apache2/mods-available/mod-security.conf 

==== Mod-security.conf file content start ====

# Check content length to avoid Heap Overflow attacks listen 32 254 => secfilterforcebyterange 32 126 # debug setting secfilterdebuglevel 9 => secfilterdebuglevel 0 # Set the default action secfilterdefaultaction "Deny, log, status: 499 "=> secfilterdefadefaaction" Deny, log, status: 404 "# pass the settings to the subdirectory secfilterinheritance off # redirect user on filter # When matching SH, redirect to a special warning page. This page is self-written. If you write some warnings, attackers may be unable to leave the page. This section will not take effect first. It is not too late to expire after the relevant configuration is configured. Remember to make it take effect after configuration. # Secfilter sh redirect: http: // localhost/hack/warning.htm # prevent OS specific keywords # filter sensitive things. We use * for attackers to use/etc /. /passwd to bypass detection secfilter/etc/passwd => secfilter/etc/* passwdsecfilter/bin/* Sh # Very crude filters to prevent SQL injection attacks # prevent SQL insert (SQL injection) attack secfilter "Delete [[[space |] + from" secfilter "insert [[space |] + into" secfilter "select. + from "secfilter" select [[[space |] + from "secfilter" Union [[[space |] + from"

==== Mod-security.conf file content ended ====

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

A. Restart The apache2 service.

sudo /etc/init.d/apache2 restart
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.