Archive - Originally posted on "The Horse's Mouth" - 2008-08-01 18:17:54 - Graham Ellis
If you're installing LAMP (Linux, Apache, MySQL, PHP), what do you do and in which order? Here's a summary of the procedure we followed on todays Apache httpd deployment course - in this case running (tailored) for a single company audience, and tailored for specfic needs.
(I've documented this and reproduced it here as it brings together in a short reminder form material from many different sources / help files, and shows you the decisions taken in real life as we followed the procedures. In the case of the examples, httpd, mysql and PHP were already installed and had to be stopped and deleted before fresh copies could be installed!)
Illustration - a room on a customer site waiting for the delegates to learn Linux Web Server deployment.
a) Build of httpd (Must do this before we install PHP)
As root
1. Stop the old daemon
2. Take backups of data to be kept
3. cd /usr/local; rm -rf apache2
As admin user
(cd to user's build area)
3. rm -rf httpd-2.2.8
4. tar xzf httpd-2.2.8.tar.gz
5. cd httpd-2.2.8
6. ./configure --enable-proxy --enable-proxy-httpd --enable-proxy-balance --enable-jk --enable-so --enable-rewrite
Note:--enable-so is needed later on for PHP. The other modules were selected because of our requirements later in the day to proxy requests on to another system, to rewrite URLs, and to talk to Apache Tomcat via an AJP 1.3 connector
7. make
Back as root
(cd to user's build area)
8. cd httpd-2.2.8
9. make install
10. cd /usr/local/apache2
11. ./bin/apachectl start
From a browser
12. Test - visit http://yourhostname/
b) Add in MySQL (must do this before PHP as PHP uses its C library)
As root
101. Backup old data
102. Stop the old daemon (./support-files/mysql.server stop)
103. cd /usr/local - remove old version AND symlink!
Note:You should also delete the old /etc/my.cnf file, and the .my.cnf file in root's home directory, if you want to create a fresh build with fresh databases and tables. Otherwise it will inherit the old ones
104. tar xzf ~trainee/mysql-5.1.24-rc-linux-i686-icc-glibc23.tar.gz
105. ln -s mysql-5.1.24-rc-linux-i686-icc-glibc23/ mysql
106. cd mysql; chown -R mysql.mysql .
107 ./scripts/mysql_install_db --user=mysql
108. chown -R root .
109. chown -R mysql data
110. ./support-files/mysql.server start
111. ./bin/mysqladmin -u root password 'abc123'
112. Test - visit via ./bin/mysql -pabc123
c) And now PHP
(Nothing to delete or backup as you've done that already!)
As admin user
201. tar xzf php-5.2.5.tar.gz
202. cd php-5.2.5
203. /configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql
204. make
As root
205. cd /usr/local/apache2
206. ./bin/apachectl stop
207. cd ~trainee/php-5.2.5
208. make install
209. cp php.ini-dist /usr/local/lib/php.ini
210. Edit /usr/local/apache2/conf/httpd.conf to ensure the following are there: LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
211. cd /usr/local/apache2
212. ./bin/apachectl start
213. Add in file /usr/local/apache2/htdocs/phtest.php to contain just
<?php phpinfo(); ?>
214. Test - browse to http://yourservername/phtest.php
d) Make them restart at reboot
301. cd /etc/rc3.d or /etc/rc5.d
302. remove old symbolic links to previous installs
303. cd /etc/init.d
304. remove old apachectl and mysql.server files
310. Test by rebooting!
311. Visit the MySQL client program(repeat step 112) and web server(repeat step 214)
Should you get an error message like:
httpd: Syntax error on line 53 of /usr/local/apache2/conf/httpd.conf: Cannot load /usr/local/apache2/modules/libphp5.so into server: /usr/local/mysql/lib/libmysqlclient.so.16: cannot restore segment prot after reloc: Permission denied
it's likely you're having issues with SELinux. As a quick fix, you may like to
add setenforce 0
near the beginning of the scripts that you have copied into /etc/init.d
------ All basically running at this point --------
e) Further near-mandatory setup!
Move Web Site to appropriate place (e.g. /home or /var or /websites) (and switch web server to use it!)
Set up user and group for web server and switch server to use it! (or use the standard Apache one)
Set up user (same group) for web developer / provider
Set up MySQL account for web server. Set MySQL passwords.
Remove spurious accounts in MySQL!
Set up test page. Reboot (to ensure restarts AOK still!) Test.