search
HomePHP FrameworkLaravelLamp environment configuration: LAMP environment configuration under Alibaba Cloud server under CentOS 6.3

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
Task Management Tools: Prioritizing and Tracking Progress in Remote ProjectsTask Management Tools: Prioritizing and Tracking Progress in Remote ProjectsMay 02, 2025 am 12:25 AM

Taskmanagementtoolsareessentialforeffectiveremoteprojectmanagementbyprioritizingtasksandtrackingprogress.1)UsetoolslikeTrelloandAsanatosetprioritieswithlabelsortags.2)EmploytoolslikeJiraandMonday.comforvisualtrackingwithGanttchartsandprogressbars.3)K

How does the latest Laravel version improve performance?How does the latest Laravel version improve performance?May 02, 2025 am 12:24 AM

Laravel10enhancesperformancethroughseveralkeyfeatures.1)Itintroducesquerybuildercachingtoreducedatabaseload.2)ItoptimizesEloquentmodelloadingwithlazyloadingproxies.3)Itimprovesroutingwithanewcachingsystem.4)ItenhancesBladetemplatingwithviewcaching,al

Deployment Strategies for Full-Stack Laravel ApplicationsDeployment Strategies for Full-Stack Laravel ApplicationsMay 02, 2025 am 12:22 AM

The best full-stack Laravel application deployment strategies include: 1. Zero downtime deployment, 2. Blue-green deployment, 3. Continuous deployment, and 4. Canary release. 1. Zero downtime deployment uses Envoy or Deployer to automate the deployment process to ensure that applications remain available when updated. 2. Blue and green deployment enables downtime deployment by maintaining two environments and allows for rapid rollback. 3. Continuous deployment Automate the entire deployment process through GitHubActions or GitLabCI/CD. 4. Canary releases through Nginx configuration, gradually promoting the new version to users to ensure performance optimization and rapid rollback.

Scaling a Full-Stack Laravel Application: Best Practices and TechniquesScaling a Full-Stack Laravel Application: Best Practices and TechniquesMay 02, 2025 am 12:22 AM

ToscaleaLaravelapplicationeffectively,focusondatabasesharding,caching,loadbalancing,andmicroservices.1)Implementdatabaseshardingtodistributedataacrossmultipledatabasesforimprovedperformance.2)UseLaravel'scachingsystemwithRedisorMemcachedtoreducedatab

The Silent Struggle: Overcoming Communication Barriers in Distributed TeamsThe Silent Struggle: Overcoming Communication Barriers in Distributed TeamsMay 02, 2025 am 12:20 AM

Toovercomecommunicationbarriersindistributedteams,use:1)videocallsforface-to-faceinteraction,2)setclearresponsetimeexpectations,3)chooseappropriatecommunicationtools,4)createateamcommunicationguide,and5)establishpersonalboundariestopreventburnout.The

Using Laravel Blade for Frontend Templating in Full-Stack ProjectsUsing Laravel Blade for Frontend Templating in Full-Stack ProjectsMay 01, 2025 am 12:24 AM

LaravelBladeenhancesfrontendtemplatinginfull-stackprojectsbyofferingcleansyntaxandpowerfulfeatures.1)Itallowsforeasyvariabledisplayandcontrolstructures.2)Bladesupportscreatingandreusingcomponents,aidinginmanagingcomplexUIs.3)Itefficientlyhandleslayou

Building a Full-Stack Application with Laravel: A Practical TutorialBuilding a Full-Stack Application with Laravel: A Practical TutorialMay 01, 2025 am 12:23 AM

Laravelisidealforfull-stackapplicationsduetoitselegantsyntax,comprehensiveecosystem,andpowerfulfeatures.1)UseEloquentORMforintuitivebackenddatamanipulation,butavoidN 1queryissues.2)EmployBladetemplatingforcleanfrontendviews,beingcautiousofoverusing@i

What kind of tools did you use for the remote role to stay connected?What kind of tools did you use for the remote role to stay connected?May 01, 2025 am 12:21 AM

Forremotework,IuseZoomforvideocalls,Slackformessaging,Trelloforprojectmanagement,andGitHubforcodecollaboration.1)Zoomisreliableforlargemeetingsbuthastimelimitsonthefreeversion.2)Slackintegrateswellwithothertoolsbutcanleadtonotificationoverload.3)Trel

See all articles

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

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.