Home  >  Article  >  PHP Framework  >  Lamp environment configuration: LAMP environment configuration under Alibaba Cloud server under CentOS 6.3

Lamp environment configuration: LAMP environment configuration under Alibaba Cloud server under CentOS 6.3

不言
不言Original
2018-07-28 17:18:422508browse

Many students may not be familiar with the LAMP environment configuration, and some problems may arise when configuring the lamp environment. Today, I will share with my friends an article based on the LAMP environment configuration under Alibaba Cloud Server under CentOS 6.3. Let’s take a closer look at the details below.

1. Apache configuration

vi /etc/httpd/conf/httpd.conf edit file

Options Indexes FollowSymLinks

Changed in line 331 to: Options Includes ExecCGI FollowSymLinks (allows the server to execute CGI and SSI)

#AddHandler cgi-script .cgi

Changed in line 796 to: AddHandler cgi-script .cgi .pl (Allow CGI scripts with extension .pl to run)

AllowOverride None

Change on line 338 to: AllowOverride All (Allow .htaccess)

AddDefaultCharset UTF-8

is modified in line 759 to: AddDefaultCharset GB2312 (Add GB2312 as the default encoding)

Options Indexes MultiViews

Find this line, delete "Indexes" and change For this state Options MultiViews (do not display the tree directory structure on the browser)

DirectoryIndex index.html index.html.var

Change line 402 to: DirectoryIndex index.html index.htm Default.html Default.htm index.php Default.php index.html.var (Set the default homepage file, add index.php)

KeepAlive Off

is modified in line 76 to: KeepAlive On (allow the program sexual connection)

MaxKeepAliveRequests 100

Change line 83 to: MaxKeepAliveRequests 1000 (increase the number of simultaneous connections)

:wq! #Save and exit

/ etc/init.d/httpd restart

Change DocumentRoot "/var/www/html" to your directory "/data0/www/xxxxxxxxx" (this directory is the mounted data disk)

rm -f /etc/httpd/conf.d/welcome.conf /var/www/error/noindex.html #Delete the default test page

Apache’s log file
ErrorLog /etc/ httpd/logs/error_log (php error log is also output here)
CustomLog /etc/httpd/logs/access_log combined

2. PHP configuration

vi /etc/php.ini #Edit

date.timezone = PRC #Remove the previous semicolon in line 946 and change it to date.timezone = PRC

magic_quotes_gpc = On #In 745 Open magic_quotes_gpc to prevent SQL injection (php5.4 does not support magic_quotes_gpc (prevention of SQL inflow))

log_errors = On #Record error log

:wq! #Save and exit

/etc/init.d/httpd restart #Restart Apche, php

3. Mount the data disk

The hard disk of the Alibaba Cloud server is composed of two pieces. One is the system disk and the other is the data disk. The data disk is not mounted by default. If you want to use the data disk, you need to manually mount it yourself.

Through the command fdisk -l, you can see that the device name is /dev/xvdb.

In addition, the hard disk (/dev/xvdb) must be partitioned and formatted before mounting.

Use the fdisk command to partition, and the format command is mkfs.ext3.

How to operate can refer to the official document: Linux system mounting data disk.

A maximum of 4 data disks can be mounted, and they are mounted in /data0. In the future, other data disks can be mounted in /data1,/data2,/data3

The role of data disks is provided by the Alibaba Cloud server console. "Reset" function, you can choose to reset the system disk or data disk. If the operating system is broken, you can only reset the system disk and keep the website data in the data disk.

4. Configure the MySQL database

Set the initial password, build the database, create the table, and import the data

Please see here: MySQL backup and recovery, Remotely access the MySql server

Then move the mysql data file to the "data disk" to prevent the data from being lost when the system is broken and the system is redone.

After I moved the mysql data file, I encountered an error when logging in using mysql -u username -p: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

The main reason is that there are several steps when modifying the my.cnf file that are different from the above. Let's explain them here. The operation method is as follows:

  • Stop the mysql process

  • Move the entire /var/lib/mysql directory to /data0/db

mv /var/lib/mysql /home/data/

This will move the MySQL data file to /data0/db/mysql

  • Modify my.cnf configuration file

Do not use the /etc/my.cnf configuration file directly. Please find the *.cnf file under /usr/share/mysql/. Copy one of them (my-medium.cnf in my case) to /etc/ and rename it to my.cnf). The command is as follows:

[root@test1 mysql]# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf

  • Edit MySQL Configuration file/etc/my.cnf

To ensure that MySQL can work normally, you need to specify the location where the mysql.sock file is generated.

# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
#socket = /var/lib/mysql/mysql.sock # Commented
socket=/data0/db/mysql/mysql.sock #Newly added content
# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port = 3306
#socket = /var/lib/mysql/mysql.sock #Commented
datadir=/data0/db/mysql #Newly added content
socket=/data0/db/ mysql/mysql.sock #Newly added content

  • MySQL startup script/etc/rc.d/init.d/mysqld does not require any modification

  • Restart the MySQL service

/etc/rc.d/init.d/mysqld start

If the work is moved normally, the move will be successful, otherwise compare to the previous Check again in step 7.

After moving MySql, PHP cannot connect to the MySql database

After the above operation, after moving the MySql data files to other directories, PHP cannot connect to the MySql database. Yes Because the mysql.sock file cannot be found.

Solution one:

Create a soft connection

cd /var/lib
mkdir mysql
ln -s  /data0/db/mysql/mysql.sock  /var/lib/mysql/mysql.sock

Solution two:

Modify /etc/php.ini file

Find the line mysql.default_socket = . This value is empty at first. PHP will use the default value built in mysql.

Change to the following content:

mysql.default_socket = /data0/db/mysql/mysql.sock

Please fill in the file location of mysql.sock according to your actual situation.

There is also mysqli.default_socket =. It depends on the situation whether you want to modify it. It has not been modified here.

Recommended related articles:

Under Alibaba Cloud Server Quick installation and deployment of LAMP environment - Based on CentOS 6.3

LAMP (Apache PHP MySql) environment configuration under Linux

laravel environment construction :How to deploy laravel to Alibaba Cloud or Tencent Cloud Steps

Related course recommendations:

The latest five Laravel video tutorial recommendations in 2017

The above is the detailed content of Lamp environment configuration: LAMP environment configuration under Alibaba Cloud server under CentOS 6.3. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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