VPS Setup Record - LAMP

LAMP = Linux + Apache + MariaDB + PHP

Install Apache

yum -y install httpd

Before doing any modifications, you might want to make a copy of important files like:

mkdir /etc/httpd_bak
cp -R /etc/httpd /etc/httpd_bak

Now setup the first webpage:

vim /etc/httpd/conf.d/happyz.me.conf

And enter:

# My Main Page
<VirtualHost *:80>
ServerAdmin a@happyz.me
ServerName happyz.me
ServerAlias www
DocumentRoot /srv/www/happyz.me/html
<Directory "/srv/www/happyz.me/html/">
	Options FollowSymLinks
	# enables .htaccess
	AllowOverride All
	Require all granted
</Directory>
ErrorLog /srv/www/happyz.me/mylogs/error.log
CustomLog /srv/www/happyz.me/mylogs/acc.log combined
</VirtualHost>
# My Blog
<VirtualHost *:80>
ServerAdmin admin@happyz.me
Servername blog.happyz.me
ServerAlias blog
DocumentRoot /srv/www/happyz.me/blog/  # enables .htaccess
<Directory "/srv/www/happyz.me/blog/">
	Options FollowSymLinks
	# enables .htaccess
	AllowOverride All
	Require all granted
</Directory>
ErrorLog /srv/www/happyz.me/mylogs/error_blog.log
CustomLog /srv/www/happyz.me/mylogs/acc_blog.log combined
</VirtualHost>

Make sure folders /srv/www/happyz.me/mylogs/, /srv/www/happyz.me/blog/, and /srv/www/happyz.me/html/ all exist.

Now enable httpd service during startup by:

systemctl enable httpd
systemctl reload httpd

Suppose firewalld is also on, then we need Firewall to allow http and maybe also https.

firewall-cmd --add-service=http --permanent
firewall-cmd --add-service=https --permanent

The --permanent tag is used such that firewall will not reset it after system reboots.

Then just restart Firewall:

systemctl restart firewalld

We can also use firewall-cmd --list-all to check the current Firewall settings.

Now we should be able to see that the website is up.

Sidenote: To restart apache, we can use

apachectl graceful

Install MariaDB

Just do

yum -y install mariadb-server mariadb
systemctl enable mariadb
systemctl start mariadb
mysql_secure_installation

And follow the instructions in secure installation procedure to secure your database. Some useful commands:

  1. To check if MariaDB is running: systemctl is-active mariadb
  2. To restart MariaDB: systemctl restart mariadb

Create a new database associated with a new MySQL account by first logging into it using the root account:

mysql -u root -p

Then create a database named mywp

create database mywp;

And then create an account "newuser" with password "123"), and grant it to the database mywp:

grant all on mywp.* to 'newuser' identified by '123';
flush privileges;

Then type quit and we are done.

Install PHP

yum -y install php php-mysql

And then it shall support PHP! Yay!

Leave a comment

Your email address will not be published. Required fields are marked *