Install Apache, PHP, and MySQL in Ubuntu

Source: Internet
Author: User
Tags php template

1. sudo apt-Get install apache2 libapache2-mod-php5 PhP5 php5-gd mysql-server php5-mysql phpMyAdmin
When downloading and automatically installing the configuration, a box will pop up asking you to enter the password !! Remember the password

2. Enable mod_rewrite module

Sudo a2enmod rewrite
3. Configure the website directory

Sudo gedit/etc/apache2/sites-available/Default

------------------ By default, you will see
Namevirtualhost *
<Virtualhost *>
Serveradmin webmaster @ localhost

DocumentRoot/var/www/
<Directory/>
Options followsymlinks
AllowOverride none
</Directory>
<Directory/var/www/>

------------------ Let's change it to another place ~~ That is, the custom location.
Namevirtualhost *
<Virtualhost *>
Serveradmin webmaster @ localhost

DocumentRoot/home/Felix/www/
<Directory/>
Options followsymlinks
AllowOverride none
</Directory>
<Directory/home/Felix/www/>
------------------ Have you seen it? This is stored in the WWW folder of your username under home.

4. Restart the server

Sudo/etc/init. d/apache2 restart

========================================================== ====================================

BelowArticleFor reprinting:

Install MySQL

Sudo apt-Get install mysql-Server

This should be very simple, and I don't think there is much problem with the installation, so I will not talk about it much. Let's talk about the configuration below.

Configure MySQL

Note thatUbuntuMySQL is only accessible locally by default. If you want access from other machines, you need to change the/etc/MySQL/My. CNF configuration file! Next we will step by step:

After the default MySQL installation, the root user does not have a password. Therefore, use the root user to enter:

$ Mysql-u Root

-U root is used here because I am a general user (firehare). If-u root is not added, MySQL will assume that it is a firehare logon. Note: I have not entered the root user mode here because it is unnecessary. In general, it is not necessary to enter the root user mode to operate the database in MySQL. This is only possible when the database is set.

After entering MySQL, the most important thing is to set the root user password in MySQL. Otherwise, the MySQL service is no longer secure.

MySQL & gt; grant all privileges on *. * to root @ localhost identified by "123456 ";

Note: I use 123456 as the root user password, but this password is not safe. Please use a password with a mix of uppercase and lowercase letters and numbers, and at least 8 characters.

In this case, the root user password in MySQL is set up, and then the database you need is created with the root user. Here we take xoops as an example:

MySQL & gt; Create Database xoops;

MySQL & gt; grant all privileges on xoops. * To xoops_root @ localhost identified by "654321 ";

In this way, a xoops_roots user is created, which has all permissions on the database xoops. In the future, we will use xoops_root to manage the xoops database, instead of using the root user. This user's permissions will only be limited to the xoops database.

If you want to implement remote access or control, you have to do two things:

1:

MySQL & gt; grant all privileges on xoops. * To xoops_root @ "%" identified by "654321 ";

Allows the xoops_root user to log on to MySQL from any machine.

Second:

$ Sudo gedit/etc/MySQL/My. CNF

Earlier versions

& Gt; Skip-networking = & gt; # Skip-networking

New Version

& Gt; bind-address = 127.0.0.1 = & gt; bind-address = IP address of your machine

This allows other machines to access MySQL.

1. Install apache2

Command:

Sudo apt-Get install apache2

2. Edit the/etc/apache2/apache2.conf file. Back up the configuration file before modification. In this way, you can recover an error.
& Gt; adddefacharcharset ISO-8859-1 = & gt; adddefacharcharset gb2312
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.
A. First install the libapache2-mod-security package

Command:

Sudo apt-Get install libapache2-mod-security

B) 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 ln-S/etc/apache2/mod-available/mod-security.load/etc/apache2/mod-enabled/mod-security.load
$ Sudo CP/usr/share/doc/libapache2-mod-security/examples/httpd2.conf. Example-full/etc/apache2/mod-available/mod-security.conf
$ Sudo CP/etc/apache2/mod-available/mod-security.conf/etc/apache2/mod-available/mod-security.conf.orig
$ Sudo VI/etc/apache2/mod-available/mod-security.conf
& Gt; # detect the content length to avoid Heap Overflow attacks
& Gt; secfilterforcebyterange 32 254 = & gt; secfilterforcebyterange 32 126

& Gt; # debug settings
& Gt; secfilterdebuglevel 9 = & gt; secfilterdebuglevel 0

& Gt; # Set the default action
& Gt; secfilterdefadefaaction "Deny, log, status: 499" = & gt; secfilterdefaultaction "Deny, log, status: 404"

& Gt; # pass the settings to the subdirectory
& Gt; secfilterinheritance off

& Gt; # redirect user on filter match
& Gt; # When matching SH, redirect to a special warning page, which is self-written. If you write some warnings, attackers may leave it difficult. 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.
& Gt; # secfilter sh redirect: http: // localhost/hack/warning.htm

& Gt; # prevent OS specific keywords
& Gt; # filter sensitive things. We use * to prevent attackers from using/etc/./passwd.
& Gt; secfilter/etc/passwd = & gt; secfilter/etc/* passwd
& Gt; secfilter/bin/* Sh

& Gt; # Very crude filters to prevent SQL injection attacks
& Gt; # prevent SQL injection attacks
& Gt; secfilter "Delete [[: Space:] + from"
& Gt; secfilter "insert [[: Space:] +"
& Gt; secfilter "Select. + from"
& Gt; secfilter "select [[: Space:] + from"
& Gt; secfilter "Union [[: Space:] + from"

Command:

Sudo ln-S/etc/apache2/mod-available/mod-security.conf/etc/apache2/mod-enabled/mod-security.conf

C) Restart The apache2 service.

Command:

Sudo/etc/init. d/apache2 restart

Step 3 may cause some websites to fail to run normally. You can refer to removing some restrictions. Because it is a security module, refer to the firewall practice and disable all insecure services, then open the necessary information as needed.

Install PHP support

$ Sudo apt-Get install libapache2-mod-php5
$ Sudo apt-Get install PhP5
If you want to support graphics add php5-gd, If You Want To support MySQL add php5-mysql, here to list libapache2-mod-php5 separately, mainly because PhP5 dependency is not done well, it is possible to install the package on the libapache-mod-php5, so to avoid unnecessary trouble, it is better to simply specify it separately.

3. Modify the PHP configuration file to limit the maximum size of memory and files to be uploaded.

We will edit the/etc/PhP5/apache2/PHP. ini file and make the general configuration first. Before modifying the file, back up the configuration file. In this way, you can recover an error.
& Gt; memory_limit = 8 m = & gt; change it to the memory size you need.
& Gt; upload_max_filesize = 2 m = & gt; modify the maximum file upload size
==================
& Gt; Extension = mysql. So support MySQL Service
& Gt; Extension = Gd. So supports the GD Function
==================
In fact, in Ubuntu, if you install the php5-mysql and php5-gd, will automatically modify the above two lines, we just do is to confirm whether they are removed in front of the annotator.

BobyangWrote:

Supplement:
1. Currently, most open sources in PHP are written in PhP4. To be compatible with previous PHP versions, you sometimes need to open register_long_arrays. Otherwise, variables such as $ http_get_vars and $ http_post_vars cannot be used, some inexplicable problems may occur.
2. In addition, after installing PhP5, check whether there is a link under/etc/apache2/mod-enabled:
Php5.load-& gt;/etc/apache2/mod-available/php5.load

4. Reinforce PHP to enhance security. Note: The following security depends on the situation, so I have clearly written their functions. If there is a problem, check whether the following restrictions are caused, you can comment it out.

Next we will start to reinforce PHP. We will edit the/etc/PhP5/apache2/PHP. ini file again. The reason why we haven't completed the change is mainly to give you a clear idea.
& Gt; # enable security mode. The advantage of opening a PHP file is that the PHP file can only access all the same files as the PHP file, even in the chroot environment, you cannot access files with different masters in jail. Backdoors like PHP shell are useless. phpshell is a popular PHP backdoors, he can execute system commands, just like his name, very similar to shell.
& Gt; safe_mode = on

& Gt; # The following settings limit the directory range that can be operated by functions such as fopen () and file () to avoid illegal file reading by intruders, you must add "/" to/var/WWW; otherwise, files under/var/wwww can also be accessed. This option will disable any PHP files that are not in the/var/www/directory, including any files that are linked to the/var/www/directory through soft links.ProgramFor example, the phpMyAdmin package cannot run properly after this option is set.
& Gt; open_basedir =/var/www/

& Gt; # disable the phpinfo and get_cmd_var functions to avoid service information leakage. Disable them after confirming that PHP works properly.
& Gt; disable_functions = phpinfo, get_assist_var

& Gt; # Set the PHP program error log
& Gt; error_reporting = e_all
& Gt; log_errors = on
& Gt; error_log =/var/log/php_err.log

& Gt; # If the PHP program does not specify register_globals, it is best to set register_globals to off to avoid many security issues. NOTE: If your program requires register_globals, do not close it. Ubuntu is disabled by default.
& Gt; register_globals = off

& Gt; # Disable remote address access. Do you remember the latest PHP Include Vulnerability? If a variable is included in a PHP program, the attacker can use this control server to execute a remote php program, such as phpshell, locally, so we can close this.
& Gt; allow_url_fopen = off

5. OK. you have finished your work!

 

_______________________________________________________________________________________________________

1. Install apache2 + PhP5 + MySql
Sudo apt-Get install apache2 php5-mysql libapache2-mod-php5 mysql-Server

Ii. Set the MySQL password
Mysqladmin-u Root Password New Password

3. Install phpMyAdmin
Sudo apt-Get install phpMyAdmin

Test: http: // localhost/PHPmyAdmin/

4. Other operations:
Edit test page :()
Sudo gedit/var/www/testphp. php

Start Apache
$ Sudo/usr/sbin/apache2ctl start
Stop Apache
$ Sudo/usr/sbin/apache2ctl stop
Restart Apache
$ Sudo/etc/init. d/apache2 restart

To enhance security for local development only, set as follows:
$ Gksudo "gedit/etc/apache2/ports. conf"
$ Password:
Change ports. conf
Listen 127.0.0.1: 80
Save the file and restart Apache. In this case, Apache can be accessed only through 127.0.0.1.

What I want to say: I still like to download the package and configure the environment by myself. It is difficult and time-consuming, but there are a lot of online materials and there will be no problems that cannot be solved. I don't like ubuntu. Apache2 after a tar.gz package was downloaded, installed on its own, and the test was completed successfully. Today, the above items are installed in the New Software Package Manager (lazy, you have to change it. I have a cleanliness for my computer, and I want to delete anything I can't use. Hey, delete it.

 

 

 

 

 

 

Because of work needs, I want to see how the HTML editor is implemented in WordPress and how it performs security operations on the server side, such as filtering JavaScript keywords in HTML, so I installed it on ubuntu7.04 in my VM.
First of all, I use the new IDE software management tools, installed apache2.2.3, mysql5.0.38, libapache2-mod-php5 and php5-cgi (the two should be installed on the former is enough), put in the installation of these two don't need me to say it, haha, just follow the normal steps for the new IDE software management tool to install the software.

After installation, set the password for the root user of the MySQL database (empty by default)

Mysqladmin-u Root Password [newpassword]

Then use the root user to log in, create a new database, and add a new user with the ownership of the database operation. The command is as follows:

Mysql-u root-P [yourpassword]
> Create Database wordpressdb;
> Grant all privileges on wordpressdb. * to [newusername] identified by "321456" with Grant options;
> Exit;

Now that the database is ready, download wordpress2.2 (latest version) and decompress it to the Apache web directory (after Apache is installed by default, create a WWW/directory under the/var/directory, copy the entire WordPress directory to the WWW directory, and the Administrator permission is required here), and then type HTTP in the browser: // localhost/WordPress, page prompts did not find the wp-config.php file, followed to inside a look, the original he only has a wp-config-simple.php template, another, there is a readme.html file, you can first look at this file, then I know what's going on, so I will wp-config-simple.php corresponding place (in fact, as long as the general change three places, database name, access database user name and the password of the user name ), save as a wp-config.php file.

Refresh the previous page, and the following error occurs: Your PHP installation appears to be missing the MySQL which is required for Wordpress ., at first, I thought WordPress couldn't find the data. I tried to modify the database and access the database to see if it was my data back name or the username was wrong, but it didn't seem like me. Then I asked my colleague, it turns out that PHP has missing a template for communicating with MySQL. No way. It's too time in English!

So I had to Google again, and finally found the name of this template on a foreign site: libapache2-mod-auth-mysql php5-mysql

Open the terminal and enter the command line (phpMyAdmin is installed in the command line below to manage MySQL, and others I prefer MySQL query browser to operate MySQL databases ):

Sudo apt-Get install libapache2-mod-auth-mysql php5-mysql phpMyAdmin

After the installation is complete, continue with the following operations:
Sudo gedit/etc/PhP5/apache2/PHP. ini

Find the line "; Extension = mysql. So" and remove the semicolon, indicating that the module connected to MySQL is loaded and saved when Apache is started.

Restart the Apache server:
Sudo/etc/init. d/apache2 restart

Collect and organize the Linux learning network, and paste the original link.

 

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.