If you’ve installed CentOS and want to add a full LAMP stack to it, you’re already 25% done–with Linux up and running, all that remains is installing Apache, MySQL, and PHP. With just a few quick commands, your CentOS web server will be ready to rock.

Installing the LAMP stack

Open your terminal window, su to the root user account, and then issue the following command. It will install everything you need for the basic LAMP stack along with any dependencies.

yum install httpd mysql-server php php-mysql

The installation will also set up the http service to start at boot. You can manually start and stop the service with these commands:

  • service httpd start
  • service httpd stop

On the off chance the installation doesn’t set httpd to start at boot, you can set that up with the following commands:

  • systemctl start httpd.service
  • systemctl enable httpd.service

Apache is up and running. Point your browser to the IP address of the server and you should see the HTTP Test page for Apache (Figure A).

Figure A

SEE: Ebook: Administrator’s Guide to Linux in the Enterprise (Tech Pro Research)

Configuring the LAMP stack

  1. First, you need to set up MySQL. Start the service with the command (after su’ing to root) service mysqld start.
  2. You must set a root user password for the database server–do this with the command mysql_secure_installation.
  3. You will be prompted to enter the MySQL password. Since one hasn’t been set, hit Enter, and you will be prompted to set and verify a password for the MySQL root user.
  4. You’ll be dropped back to your bash prompt. Test that the password worked by issuing the command mysql -u root -p.
  5. When prompted, enter the password you just created and you should see mysql>.
  6. Exit the mysql prompt with the command exit.

You are ready to begin working with your CentOS-powered LAMP stack.

Add phpmyadmin

If you’re not excited about working with the MySQL command prompt, you can easily add a web-based GUI tool for database administration with a single command:

yum install phpmyadmin

Once installed, point your browser to http://IP_ADDRESS_OF_SERVER/phpmyadmin and log in with the root user credentials to start managing your MySQL databases.

A winning combination

CentOS is a very powerful server environment. Add the AMP to that L and you have an incredibly flexible and secure combination that will serve you well for a long time. We’ll explore more with this setup in future articles.