Full-service Internet Marketing & Web Development
Recent Posts

Sponsors
![]() |
How to automatically install PHP/MySQL on FreeBSDMichel Nadeau, 08-14-2008 |
Today I had to install PHP and MySQL on many, many servers. I could have done everything by hand on each server but the risk of error is big and it's very long. The answer to this task: create an automated script that does everything for you.
NOTE: All my servers were virgin FreeBSD 6.3 machines.
Step 1 - What to accomplish
I wanted to:
- Install MySQL with a custom my.cnf file
- Install PHP with CURL and GD support (so I needed to install libcurl, libpng and zlib)
- Change the timezone to GMT
Step 2 - Before creating the script
The first thing I did was to manually install and configure everything on the first server, taking notes of everything I did. Once I had my complete "guide", containing all the instructions, and that I was sure that my installation was working well, I was ready to write my automated script.
Step 3 - Writing the automated script
I wrote my automated script using BASH. It probably could have been Perl but sometimes it's not installed, so I think that BASH is a better choice.
When you write such a script, you want to make sure of a couple of things:
- Double-check EVERY instruction
- Think about your current directory
- Display debug information
- Create a debug mode that needs you to press a key after some instructions
- TEST the installed applications at the end of your script, with debug information
It took me 4 machines to get a perfect script:
- Machine 1: manual installation/configuration
- Machine 2: automated script, debug mode ON
- Machine 3: automated script (with some modifications), debug mode ON
- Machine 4: automated script (final), debug mode OFF
To avoid needing to transfer a lot of files on each server, I used "wget" to download everything I needed. So the only things I had to send on each server was:
- wget-1.11.4.tar.gz - needed to download the other files
- auto.sh - the automated script
- auto.php - the PHP test script (it tests PHP and MySQL)
- my.cnf - custom my.cnf file to install
NOTE: These files are included in the attached "auto.zip" file.
Step 4 - Running the script
The first thing the script does is to install wget, as it is needed to download the other applications. Then the applications are downloaded, installed and configured. Everything is downloaded, extracted and compiled in a temporary directory. At the end, the script runs some tests to be sure that everything's working correctly. Finally, the temporary directory is removed, as well as the script itself (and the auto.php file) so you don't have to remove anything manually.
Step 5 - Why this post?
This post's purpose is not really to teach you how to specifically install MySQL and PHP automatically. It's more to show you a good example of a successfully deployed automated script; to inspire you and give you some "guidelines" if you ever need to create such a script.
I invite you to take a look at the attached "auto.zip" file, more specifically to the "auto.sh" script.
NOTE: All my servers were virgin FreeBSD 6.3 machines.
Step 1 - What to accomplish
I wanted to:
- Install MySQL with a custom my.cnf file
- Install PHP with CURL and GD support (so I needed to install libcurl, libpng and zlib)
- Change the timezone to GMT
Step 2 - Before creating the script
The first thing I did was to manually install and configure everything on the first server, taking notes of everything I did. Once I had my complete "guide", containing all the instructions, and that I was sure that my installation was working well, I was ready to write my automated script.
Step 3 - Writing the automated script
I wrote my automated script using BASH. It probably could have been Perl but sometimes it's not installed, so I think that BASH is a better choice.
When you write such a script, you want to make sure of a couple of things:
- Double-check EVERY instruction
- Think about your current directory
- Display debug information
- Create a debug mode that needs you to press a key after some instructions
- TEST the installed applications at the end of your script, with debug information
It took me 4 machines to get a perfect script:
- Machine 1: manual installation/configuration
- Machine 2: automated script, debug mode ON
- Machine 3: automated script (with some modifications), debug mode ON
- Machine 4: automated script (final), debug mode OFF
To avoid needing to transfer a lot of files on each server, I used "wget" to download everything I needed. So the only things I had to send on each server was:
- wget-1.11.4.tar.gz - needed to download the other files
- auto.sh - the automated script
- auto.php - the PHP test script (it tests PHP and MySQL)
- my.cnf - custom my.cnf file to install
NOTE: These files are included in the attached "auto.zip" file.
Step 4 - Running the script
The first thing the script does is to install wget, as it is needed to download the other applications. Then the applications are downloaded, installed and configured. Everything is downloaded, extracted and compiled in a temporary directory. At the end, the script runs some tests to be sure that everything's working correctly. Finally, the temporary directory is removed, as well as the script itself (and the auto.php file) so you don't have to remove anything manually.
Step 5 - Why this post?
This post's purpose is not really to teach you how to specifically install MySQL and PHP automatically. It's more to show you a good example of a successfully deployed automated script; to inspire you and give you some "guidelines" if you ever need to create such a script.
I invite you to take a look at the attached "auto.zip" file, more specifically to the "auto.sh" script.
|
|
Subscribe Now to receive new posts via Email as soon as they come out.
Comments
Post your comments

