Home PHP Framework Laravel 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

Jul 28, 2018 pm 05:18 PM

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
Copy after login

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
Copy after login

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 of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Laravel Introduction Example Laravel Introduction Example Apr 18, 2025 pm 12:45 PM

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

Laravel user login function Laravel user login function Apr 18, 2025 pm 12:48 PM

Laravel provides a comprehensive Auth framework for implementing user login functions, including: Defining user models (Eloquent model), creating login forms (Blade template engine), writing login controllers (inheriting Auth\LoginController), verifying login requests (Auth::attempt) Redirecting after login is successful (redirect) considering security factors: hash passwords, anti-CSRF protection, rate limiting and security headers. In addition, the Auth framework also provides functions such as resetting passwords, registering and verifying emails. For details, please refer to the Laravel documentation: https://laravel.com/doc

Laravel and the Backend: Powering Web Application Logic Laravel and the Backend: Powering Web Application Logic Apr 11, 2025 am 11:29 AM

How does Laravel play a role in backend logic? It simplifies and enhances backend development through routing systems, EloquentORM, authentication and authorization, event and listeners, and performance optimization. 1. The routing system allows the definition of URL structure and request processing logic. 2.EloquentORM simplifies database interaction. 3. The authentication and authorization system is convenient for user management. 4. The event and listener implement loosely coupled code structure. 5. Performance optimization improves application efficiency through caching and queueing.

Laravel framework installation method Laravel framework installation method Apr 18, 2025 pm 12:54 PM

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

What versions of laravel are there? How to choose the version of laravel for beginners What versions of laravel are there? How to choose the version of laravel for beginners Apr 18, 2025 pm 01:03 PM

In the Laravel framework version selection guide for beginners, this article dives into the version differences of Laravel, designed to assist beginners in making informed choices among many versions. We will focus on the key features of each release, compare their pros and cons, and provide useful advice to help beginners choose the most suitable version of Laravel based on their skill level and project requirements. For beginners, choosing a suitable version of Laravel is crucial because it can significantly impact their learning curve and overall development experience.

How to learn Laravel How to learn Laravel for free How to learn Laravel How to learn Laravel for free Apr 18, 2025 pm 12:51 PM

Want to learn the Laravel framework, but suffer from no resources or economic pressure? This article provides you with free learning of Laravel, teaching you how to use resources such as online platforms, documents and community forums to lay a solid foundation for your PHP development journey from getting started to master.

How to view the version number of laravel? How to view the version number of laravel How to view the version number of laravel? How to view the version number of laravel Apr 18, 2025 pm 01:00 PM

The Laravel framework has built-in methods to easily view its version number to meet the different needs of developers. This article will explore these methods, including using the Composer command line tool, accessing .env files, or obtaining version information through PHP code. These methods are essential for maintaining and managing versioning of Laravel applications.

The difference between laravel and thinkphp The difference between laravel and thinkphp Apr 18, 2025 pm 01:09 PM

Laravel and ThinkPHP are both popular PHP frameworks and have their own advantages and disadvantages in development. This article will compare the two in depth, highlighting their architecture, features, and performance differences to help developers make informed choices based on their specific project needs.

See all articles