Error in php program after moving from EC2 instance to GCE instance = Could not access file: /var/www/html/

StackOverflow https://stackoverflow.com/questions/23169356

Question

Moved a php / xml program that submits online forms that sends email of the results to designated recipients as pdf attachment.

System WORKS FINE on Amazon EC2 (and other basic hosting accounts), but breaks on Google's GCE.

Moved to Google Compute Engine GCE and cannot figure out or get past this error.

No email is sent. It makes it to the thank you page with the php error in the page head of:

Could not access file: /var/www/html/temp/98r34prqp98ipjqoipe9898jo.pdf

All paths and config paths are correct and have been looked at a million times.

All users, including apache, root, my user have been assigned to group www who has -R 775 permissions in the /var/www.

/temp has been 777'd.

Also:

sudo su

chown -R root:www /var/www

chmod 2775 /var/www

find /var/www -type d -exec chmod 2775 {} +

find /var/www -type f -exec chmod 0664 {} +

Have also tried the above where I chown'd every user and then tested, root:www, apache:www, myuser:www ... no luck.

Other things done: Installed apache, php, postfix, php-gd, php-pear, mod_ssl (no database is used)

Apache has been restarted a million times.

httpd_can_sendmail --> on

Edits made to php.ini

Using PHPMailer Lite version 5.1

error_log shows no errors except a warning about time zone: [error] [client 0x0x0x0x] PHP Warning: date(): It is not safe to rely on the system's timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. .... blaa, blaaa ....

Possibilities/differences:

  • EC2 has php version 5.3.28 and GCE has php version 5.3.3
  • Different java versions on EC2 vs. GCE?? The system uses a .jar file.
  • There is some httpd.conf virtualhosts configuration that is supposed to be different on GCE?? (I've pasted some of the httpd.conf info below.

  • Some missing module? Here's the modules ... [PHP Modules] bz2 calendar Core ctype curl date dom ereg exif fileinfo filter ftp gd gettext gmp hash iconv json libxml openssl pcntl pcre Phar readline Reflection session shmop SimpleXML sockets SPL standard tokenizer wddx xml xmlreader xmlwriter xsl zip zlib

Here's some of the httpd.conf info: The system has a forced ssl in the htaccess files. Port 443 is enabled in the firewall with 80 also via Google Developer Console

<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>



<VirtualHost *:80>
DocumentRoot /var/www/html/
ServerName www.MYDOMAIN.com
</VirtualHost>


NameVirtualHost *:443
<VirtualHost *:443>
DocumentRoot /var/www/html/
ServerName www.MYDOMAIN.com
ServerAlias MYDOMAIN.com www.MYDOMAIN.com
SSLEngine on
SSLProtocol all -SSLv2
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM
SSLCertificateFile /var/www/SSL/MYDOMAIN.cert
SSLCertificateKeyFile /var/www/SSL/MYDOMAIN.key
SSLCertificateChainFile /var/www/SSL/MYDOMAIN_intermediate.cert
SetEnvIf User-Agent “.*MSIE.*” nokeepalive ssl-unclean-shutdown
</VirtualHost>

VERY FRUSTRATING :(

Was it helpful?

Solution

SOLVED! Evidently, on Google Compute Engine CentOS, by default, Apache is not allowed to run Java.

I had to run:

sudo setsebool httpd_execmem=1
sudo service httpd restart

Bingo!

Other side notes: Be sure you are running the version of java that you want. Find java version via java -version. I had 1.5 running and had to run:

yum search java

to get the list of 1.6 versions to then:

sudo yum install java-1.6.0-openjdk.x86_64

In conclusion, there are three major points:

  1. You have to allow postfix/httpd to send mail: setsebool -P httpd_can_sendmail 1
  2. You have to use sendgrid to send mail from the GCE instance. Google Compute Engine instances are not allowed to send email :( See instructions on how to set this up.
  3. Be sure you have the correct version of Java installed because if you just yum install java, you may end up like I did; installing 1.5 when you need 1.6. PLUS, but default, GCE doesn't allow Apache to use java. So you need to configure java it to be so with setsebool httpd_execmem=1

Hope this helps someone.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top