没有不值得去解决的问题,也没有不值得去学习的技术!

How to Deploy a LAMP Stack on Alibaba Cloud ECS with CentOS 6.5 64-bit

Change the default website root directory to: /var/www/wwwroot

1. Use PuTTY to connect to the server remotely;

Use PuTTY to connect to the server remotely
Use PuTTY to connect to the server remotely

2. The current operating system is CentOS 6.5 64-bit.

The current operating system is CentOS 6.5 64-bit
The current operating system is CentOS 6.5 64-bit

3. Check disk space usage with the command:
df -h

Check disk space usage
Check disk space usage

4. Check disk space usage, including unmounted data disks, with the command:
fdisk -l
Friendly reminder: If you run the fdisk -l command and do not see /dev/xvdb, it means your cloud server has no data disk, so you do not need to mount it. In this case, this tutorial does not apply to you.

Check disk space usage, including unmounted data disks
Check disk space usage, including unmounted data disks

5. Partition the data disk
Run:
fdisk /dev/xvdb
to partition the data disk;
Following the prompts, enter
n
p
1
press Enter twice
wq
The partitioning will start and finish quickly.

Partition the data disk
Partition the data disk

6. View the new partition
Use the
fdisk -l
command to see that the new partition xvdb1 has been created.

View the new partition
View the new partition

7. You can use the
mkfs.ext4 /dev/xvdb1
command to format the new partition. The formatting time varies depending on the disk size.

Format the new partition
Format the new partition

8. Add partition information
If you want to mount the new partition to the /var/www directory, you can use the following command. Note: If the /var/www directory does not exist, first run the command:
mkdir /var/www
to create the directory.
echo “/dev/xvdb1 /var/www ext4 defaults 0 0” >> /etc/fstab
Run the command to write the new partition information. Then use the
cat /etc/fstab
command to check. If the following information appears, the write was successful.

Add partition information
Add partition information

9. Mount the new partition
Use the
mount -a
command to mount the new partition, then use the
df -h
command to check. If the following information appears, the mount is successful and you can start using the new partition.

Mount the new partition
Mount the new partition

10. Use the
yum install httpd
y
commands to install Apache.

Install Apache
Install Apache

11. Run the command:
service httpd start
to start Apache immediately.
Verify the httpd service status:
service httpd status
Run the command:
chkconfig –levels 235 httpd on
to enable Apache to start automatically.
Check the startup levels of this service:
chkconfig –list httpd
Just make sure it is set to on for runlevels 3 or 5.

Configure the httpd service
Configure the httpd service

12. Open the following in your local browser:

http://Public IP address

If “Apache 2 Test Page powered by CentOS” appears, the httpd service has been installed and started successfully;

httpd service installed and started successfully
httpd service installed and started successfully

13. Set the website’s publish directory and create a virtual host
cd /etc/httpd/conf
ls
Create a backup of the configuration file
cp httpd.conf httpd.bak
ls
vim httpd.conf

Create a backup of the configuration file
Create a backup of the configuration file

?DocumentRoot
Press the n key to view the next match;

Search for DocumentRoot
Search for DocumentRoot

Press the i key to enter edit mode, and change the default website root directory to: /var/www/wwwroot
Press the Esc key to exit edit mode, then press :wq to save and exit;

Change the default website root directory to: /var/www/wwwroot
Change the default website root directory to: /var/www/wwwroot

Create the website root directory with the command:
mkdir -p /var/www/wwwroot
Reload the configuration file
service httpd reload

Create a virtual host
vim /etc/httpd/conf/httpd.conf
Press the i key to enter edit mode, and remove the # sign from NameVirtualHost *:80 to enable virtual host support;
Go to the /etc/httpd/conf.d directory
cd /etc/httpd/conf.d

Create a new virtual host configuration file named vhosts.conf

vim vhosts.conf

Create a virtual host
Create a virtual host

service httpd reload

14. Install and configure PHP
yum install php
y

Install and configure PHP
Install and configure PHP

Install packages like php-mysql to enable PHP support for MySQL. Run the command
yum search php
to find available PHP module packages, select the required packages, and run the command
yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-cli php-common php-devel php-mbstring php-mcrypt php-soap php-bcmath php-mysqli
to install them (you are not limited to the packages in this example)
y

Install packages like php-mysql to enable PHP support for MySQL, etc.
Install packages like php-mysql to enable PHP support for MySQL, etc.

service httpd restart
echo “<?php phpinfo(); ?>” >> /var/www/wwwroot/phpinfo.php

Verify whether PHP was installed successfully

Verify whether PHP was installed successfully
Verify whether PHP was installed successfully

15. Install and configure the FTP server
yum install vsftpd
y
vim /etc/vsftpd/vsftpd.conf
Configure vsftpd:
To disallow anonymous users from logging into the FTP server, use:
anonymous_enable=NO
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list

Configure vsftpd
Configure vsftpd
Configure vsftpd
Configure vsftpd

chkconfig –levels 235 vsftpd on
useradd -d /var/www/wwwroot/phpMyAdmin -s /sbin/nologin phpMyAdmin
passwd phpMyAdmin
ftp%$fg65DFlM43$3
ftp%$fg65DFlM43$3
Add the created user to the configuration file, one user per line
vim /etc/vsftpd/chroot_list
service vsftpd restart
Change the owner of all phpMyAdmin files to phpMyAdmin:
chown -R phpMyAdmin /var/www/wwwroot/phpMyAdmin
chmod -R 755 /var/www/wwwroot/phpMyAdmin

Grant permissions to the apache user for directories that require apache operations, such as the image upload directory
chown -R apache directory

Test whether the connection is successful using FTP client software

Test whether the connection is successful using FTP client software
Test whether the connection is successful using FTP client software

Because the database uses the cloud database RDS, there is no need to configure it on the ECS. The configuration ends here.

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系